From ea7d8be913a86353cc4ecd79a25f1f70e246e361 Mon Sep 17 00:00:00 2001 From: jaime Date: Fri, 10 Dec 2021 16:50:52 +0800 Subject: [PATCH] [skip ci] Refine error message (#11728) Signed-off-by: yun.zhang Co-authored-by: yun.zhang --- internal/kv/etcd/etcd_kv.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/kv/etcd/etcd_kv.go b/internal/kv/etcd/etcd_kv.go index d07bb0af9a..412ae8c609 100644 --- a/internal/kv/etcd/etcd_kv.go +++ b/internal/kv/etcd/etcd_kv.go @@ -397,7 +397,7 @@ func (kv *EtcdKV) CompareValueAndSwap(key, value, target string, opts ...clientv // CompareVersionAndSwap compares the existing key-value's version with version, and if // they are equal, the target is stored in etcd. -func (kv *EtcdKV) CompareVersionAndSwap(key string, version int64, target string, opts ...clientv3.OpOption) error { +func (kv *EtcdKV) CompareVersionAndSwap(key string, source int64, target string, opts ...clientv3.OpOption) error { start := time.Now() ctx, cancel := context.WithTimeout(context.TODO(), RequestTimeout) defer cancel() @@ -405,13 +405,14 @@ func (kv *EtcdKV) CompareVersionAndSwap(key string, version int64, target string clientv3.Compare( clientv3.Version(path.Join(kv.rootPath, key)), "=", - version)). + source)). Then(clientv3.OpPut(path.Join(kv.rootPath, key), target, opts...)).Commit() if err != nil { return err } if !resp.Succeeded { - return fmt.Errorf("function CompareAndSwap error for compare is false for key: %s", key) + return fmt.Errorf("function CompareAndSwap error for compare is false for key: %s," + + " source version: %d, target version: %s", key, source, target) } CheckElapseAndWarn(start, "Slow etcd operation compare version and swap") return nil