From f0143916de648a6cc6fb5c6bd3b41e7121092d57 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sun, 16 Apr 2017 20:30:49 -0700 Subject: [PATCH 1/2] clientv3/integration: test fetching entire keyspace --- clientv3/integration/kv_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/clientv3/integration/kv_test.go b/clientv3/integration/kv_test.go index f9f87fe20a8..49f107f76df 100644 --- a/clientv3/integration/kv_test.go +++ b/clientv3/integration/kv_test.go @@ -381,6 +381,36 @@ func TestKVRange(t *testing.T) { {Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, }, }, + // fetch entire keyspace using WithFromKey + { + "\x00", "", + 0, + []clientv3.OpOption{clientv3.WithFromKey(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)}, + + []*mvccpb.KeyValue{ + {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, + {Key: []byte("b"), Value: nil, CreateRevision: 3, ModRevision: 3, Version: 1}, + {Key: []byte("c"), Value: nil, CreateRevision: 4, ModRevision: 6, Version: 3}, + {Key: []byte("foo"), Value: nil, CreateRevision: 7, ModRevision: 7, Version: 1}, + {Key: []byte("foo/abc"), Value: nil, CreateRevision: 8, ModRevision: 8, Version: 1}, + {Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, + }, + }, + // fetch entire keyspace using WithPrefix + { + "", "", + 0, + []clientv3.OpOption{clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)}, + + []*mvccpb.KeyValue{ + {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, + {Key: []byte("b"), Value: nil, CreateRevision: 3, ModRevision: 3, Version: 1}, + {Key: []byte("c"), Value: nil, CreateRevision: 4, ModRevision: 6, Version: 3}, + {Key: []byte("foo"), Value: nil, CreateRevision: 7, ModRevision: 7, Version: 1}, + {Key: []byte("foo/abc"), Value: nil, CreateRevision: 8, ModRevision: 8, Version: 1}, + {Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, + }, + }, } for i, tt := range tests { From f92c11e1f2e5b97d150c5a8c3ecc5bcb706622f7 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sun, 16 Apr 2017 20:46:33 -0700 Subject: [PATCH 2/2] clientv3: translate WithPrefix() into WithFromKey() for empty key --- clientv3/op.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clientv3/op.go b/clientv3/op.go index e8218924ba3..63b99501e82 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -282,6 +282,10 @@ func getPrefix(key []byte) []byte { // can return 'foo1', 'foo2', and so on. func WithPrefix() OpOption { return func(op *Op) { + if len(op.key) == 0 { + op.key, op.end = []byte{0}, []byte{0} + return + } op.end = getPrefix(op.key) } }