mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: Fix inconsistent naming convention in v3 client.
In order to have a consistent naming for variable/function names pertaining to ModifiedRevision, all occurrences have been renamed to ModRevision.
This commit is contained in:
parent
e73ac5bdd7
commit
606889a002
@ -76,7 +76,7 @@ func CreatedRevision(key string) Cmp {
|
|||||||
return Cmp{Key: []byte(key), Target: pb.Compare_CREATE}
|
return Cmp{Key: []byte(key), Target: pb.Compare_CREATE}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ModifiedRevision(key string) Cmp {
|
func ModRevision(key string) Cmp {
|
||||||
return Cmp{Key: []byte(key), Target: pb.Compare_MOD}
|
return Cmp{Key: []byte(key), Target: pb.Compare_MOD}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func NewUniqueKV(ctx context.Context, kv v3.KV, pfx, val string, opts ...v3.OpOp
|
|||||||
for {
|
for {
|
||||||
newKey := fmt.Sprintf("%s/%v", pfx, time.Now().UnixNano())
|
newKey := fmt.Sprintf("%s/%v", pfx, time.Now().UnixNano())
|
||||||
put := v3.OpPut(newKey, val, opts...)
|
put := v3.OpPut(newKey, val, opts...)
|
||||||
cmp := v3.Compare(v3.ModifiedRevision(newKey), "=", 0)
|
cmp := v3.Compare(v3.ModRevision(newKey), "=", 0)
|
||||||
resp, err := kv.Txn(ctx).If(cmp).Then(put).Commit()
|
resp, err := kv.Txn(ctx).If(cmp).Then(put).Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
|
@ -235,7 +235,7 @@ func isKeyCurrent(k string, r *v3.GetResponse) v3.Cmp {
|
|||||||
if len(r.Kvs) != 0 {
|
if len(r.Kvs) != 0 {
|
||||||
rev = r.Kvs[0].ModRevision + 1
|
rev = r.Kvs[0].ModRevision + 1
|
||||||
}
|
}
|
||||||
return v3.Compare(v3.ModifiedRevision(k), "<", rev)
|
return v3.Compare(v3.ModRevision(k), "<", rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func respToValue(resp *v3.GetResponse) string {
|
func respToValue(resp *v3.GetResponse) string {
|
||||||
|
@ -163,11 +163,11 @@ func TestKVRange(t *testing.T) {
|
|||||||
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// range all with SortByModifiedRev, SortDescend
|
// range all with SortByModRevision, SortDescend
|
||||||
{
|
{
|
||||||
"a", "x",
|
"a", "x",
|
||||||
0,
|
0,
|
||||||
[]clientv3.OpOption{clientv3.WithSort(clientv3.SortByModifiedRev, clientv3.SortDescend)},
|
[]clientv3.OpOption{clientv3.WithSort(clientv3.SortByModRevision, clientv3.SortDescend)},
|
||||||
|
|
||||||
[]*storagepb.KeyValue{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
||||||
|
@ -221,10 +221,10 @@ func WithFirstKey() []OpOption { return withTop(SortByKey, SortAscend) }
|
|||||||
func WithLastKey() []OpOption { return withTop(SortByKey, SortDescend) }
|
func WithLastKey() []OpOption { return withTop(SortByKey, SortDescend) }
|
||||||
|
|
||||||
// WithFirstRev gets the key with the oldest modification revision in the request range.
|
// WithFirstRev gets the key with the oldest modification revision in the request range.
|
||||||
func WithFirstRev() []OpOption { return withTop(SortByModifiedRev, SortAscend) }
|
func WithFirstRev() []OpOption { return withTop(SortByModRevision, SortAscend) }
|
||||||
|
|
||||||
// WithLastRev gets the key with the latest modification revision in the request range.
|
// WithLastRev gets the key with the latest modification revision in the request range.
|
||||||
func WithLastRev() []OpOption { return withTop(SortByModifiedRev, SortDescend) }
|
func WithLastRev() []OpOption { return withTop(SortByModRevision, SortDescend) }
|
||||||
|
|
||||||
// withTop gets the first key over the get's prefix given a sort order
|
// withTop gets the first key over the get's prefix given a sort order
|
||||||
func withTop(target SortTarget, order SortOrder) []OpOption {
|
func withTop(target SortTarget, order SortOrder) []OpOption {
|
||||||
|
@ -27,7 +27,7 @@ const (
|
|||||||
SortByKey SortTarget = iota
|
SortByKey SortTarget = iota
|
||||||
SortByVersion
|
SortByVersion
|
||||||
SortByCreatedRev
|
SortByCreatedRev
|
||||||
SortByModifiedRev
|
SortByModRevision
|
||||||
SortByValue
|
SortByValue
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ var (
|
|||||||
|
|
||||||
// deleteRevKey deletes a key by revision, returning false if key is missing
|
// deleteRevKey deletes a key by revision, returning false if key is missing
|
||||||
func deleteRevKey(kv v3.KV, key string, rev int64) (bool, error) {
|
func deleteRevKey(kv v3.KV, key string, rev int64) (bool, error) {
|
||||||
cmp := v3.Compare(v3.ModifiedRevision(key), "=", rev)
|
cmp := v3.Compare(v3.ModRevision(key), "=", rev)
|
||||||
req := v3.OpDelete(key)
|
req := v3.OpDelete(key)
|
||||||
txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit()
|
txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,7 +123,7 @@ func newSequentialKV(kv v3.KV, prefix, val string, leaseID v3.LeaseID) (*RemoteK
|
|||||||
baseKey := "__" + prefix
|
baseKey := "__" + prefix
|
||||||
|
|
||||||
// current revision might contain modification so +1
|
// current revision might contain modification so +1
|
||||||
cmp := v3.Compare(v3.ModifiedRevision(baseKey), "<", resp.Header.Revision+1)
|
cmp := v3.Compare(v3.ModRevision(baseKey), "<", resp.Header.Revision+1)
|
||||||
reqPrefix := v3.OpPut(baseKey, "", v3.WithLease(leaseID))
|
reqPrefix := v3.OpPut(baseKey, "", v3.WithLease(leaseID))
|
||||||
reqNewKey := v3.OpPut(newKey, val, v3.WithLease(leaseID))
|
reqNewKey := v3.OpPut(newKey, val, v3.WithLease(leaseID))
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
|
|||||||
case sortTarget == "KEY":
|
case sortTarget == "KEY":
|
||||||
sortByTarget = clientv3.SortByKey
|
sortByTarget = clientv3.SortByKey
|
||||||
case sortTarget == "MODIFY":
|
case sortTarget == "MODIFY":
|
||||||
sortByTarget = clientv3.SortByModifiedRev
|
sortByTarget = clientv3.SortByModRevision
|
||||||
case sortTarget == "VALUE":
|
case sortTarget == "VALUE":
|
||||||
sortByTarget = clientv3.SortByValue
|
sortByTarget = clientv3.SortByValue
|
||||||
case sortTarget == "VERSION":
|
case sortTarget == "VERSION":
|
||||||
|
@ -187,7 +187,7 @@ func parseCompare(line string) (*clientv3.Cmp, error) {
|
|||||||
}
|
}
|
||||||
case "m", "mod":
|
case "m", "mod":
|
||||||
if v, err = strconv.ParseInt(val, 10, 64); err == nil {
|
if v, err = strconv.ParseInt(val, 10, 64); err == nil {
|
||||||
cmp = clientv3.Compare(clientv3.ModifiedRevision(key), op, v)
|
cmp = clientv3.Compare(clientv3.ModRevision(key), op, v)
|
||||||
}
|
}
|
||||||
case "val", "value":
|
case "val", "value":
|
||||||
cmp = clientv3.Compare(clientv3.Value(key), op, val)
|
cmp = clientv3.Compare(clientv3.Value(key), op, val)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user