From 60431d18902941db207f4dd3f3c572fe8880081d Mon Sep 17 00:00:00 2001 From: eaudetcobello <155978570+eaudetcobello@users.noreply.github.com> Date: Fri, 23 Feb 2024 15:57:08 +0000 Subject: [PATCH 1/3] Kv should be mkv --- pkg/kine/drivers/generic/generic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kine/drivers/generic/generic.go b/pkg/kine/drivers/generic/generic.go index 7d157e7f..3f1daebe 100644 --- a/pkg/kine/drivers/generic/generic.go +++ b/pkg/kine/drivers/generic/generic.go @@ -218,7 +218,7 @@ func Open(ctx context.Context, driverName, dataSourceName string, paramCharacter SELECT (%s), COUNT(c.theid) FROM ( %s - ) c`, revSQL, fmt.Sprintf(listSQL, "AND kv.id <= ?")), paramCharacter, numbered), + ) c`, revSQL, fmt.Sprintf(listSQL, "AND mkv.id <= ?")), paramCharacter, numbered), AfterSQLPrefix: q(fmt.Sprintf(` SELECT %s From 3b0d410139921fd77f0598f78b7b1008be186021 Mon Sep 17 00:00:00 2001 From: Angelos Kolaitis Date: Sat, 24 Feb 2024 14:32:10 +0200 Subject: [PATCH 2/3] add unit test for ListRevision --- test/list_test.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/list_test.go b/test/list_test.go index b9dcc845..0de24a74 100644 --- a/test/list_test.go +++ b/test/list_test.go @@ -93,6 +93,70 @@ func TestList(t *testing.T) { g.Expect(resp.Header.Revision).ToNot(BeZero()) g.Expect(resp.Kvs[0].Key).To(Equal([]byte("/key/1"))) }) + + t.Run("ListRevision", func(t *testing.T) { + t.Run("Create", func(t *testing.T) { + // Create some keys + keys := []string{"/revkey/1"} + for _, key := range keys { + resp, err := client.Txn(ctx). + If(clientv3.Compare(clientv3.ModRevision(key), "=", 0)). + Then(clientv3.OpPut(key, "value")). + Commit() + + g.Expect(err).To(BeNil()) + g.Expect(resp.Succeeded).To(BeTrue()) + g.Expect(resp.Header.Revision).ToNot(BeZero()) + } + }) + + t.Run("Update", func(t *testing.T) { + g := NewWithT(t) + var rev int64 + for rev < 30 { + get, err := client.Get(ctx, "/revkey/1", clientv3.WithRange("")) + g.Expect(err).To(BeNil()) + g.Expect(get.Kvs).To(HaveLen(1)) + rev = get.Kvs[0].ModRevision + + update, err := client.Txn(ctx). + If(clientv3.Compare(clientv3.ModRevision("/revkey/1"), "=", rev)). + Then(clientv3.OpPut("/revkey/1", fmt.Sprintf("val-%d", rev))). + Else(clientv3.OpGet("/revkey/1", clientv3.WithRange(""))). + Commit() + + g.Expect(err).To(BeNil()) + g.Expect(update.Succeeded).To(BeTrue()) + } + }) + + t.Run("List", func(t *testing.T) { + t.Run("NoRevision", func(t *testing.T) { + g := NewWithT(t) + resp, err := client.Get(ctx, "/revkey/", clientv3.WithPrefix()) + g.Expect(err).To(BeNil()) + g.Expect(resp.Kvs).To(HaveLen(1)) + g.Expect(resp.Kvs[0].ModRevision).To(Equal(int64(31))) + g.Expect(resp.Count).To(Equal(int64(1))) + }) + t.Run("OldRevision", func(t *testing.T) { + g := NewWithT(t) + resp, err := client.Get(ctx, "/revkey/", clientv3.WithPrefix(), clientv3.WithRev(10)) + g.Expect(err).To(BeNil()) + g.Expect(resp.Kvs).To(HaveLen(1)) + g.Expect(resp.Kvs[0].ModRevision).To(Equal(int64(10))) + g.Expect(resp.Count).To(Equal(int64(1))) + }) + t.Run("LaterRevision", func(t *testing.T) { + g := NewWithT(t) + resp, err := client.Get(ctx, "/revkey/", clientv3.WithPrefix(), clientv3.WithRev(100)) + g.Expect(err).To(BeNil()) + g.Expect(resp.Kvs).To(HaveLen(1)) + g.Expect(resp.Kvs[0].ModRevision).To(Equal(int64(31))) + g.Expect(resp.Count).To(Equal(int64(1))) + }) + }) + }) }) } From 3fe5aff450b37ba66c299000cd441cd7db1a8f5c Mon Sep 17 00:00:00 2001 From: Angelos Kolaitis Date: Sat, 24 Feb 2024 14:32:27 +0200 Subject: [PATCH 3/3] revert unused prefix manipulation in count --- pkg/kine/logstructured/sqllog/sql.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/kine/logstructured/sqllog/sql.go b/pkg/kine/logstructured/sqllog/sql.go index 6a915587..7afbb622 100644 --- a/pkg/kine/logstructured/sqllog/sql.go +++ b/pkg/kine/logstructured/sqllog/sql.go @@ -472,10 +472,6 @@ func canSkipRevision(rev, skip int64, skipTime time.Time) bool { } func (s *SQLLog) Count(ctx context.Context, prefix string, revision int64) (int64, int64, error) { - if strings.HasSuffix(prefix, "/") { - prefix += "%" - } - if revision == 0 { return s.d.CountCurrent(ctx, prefix) }