mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3/ordering: compare and update prevRev atomically
Several goroutines may call setPrevRev concurrently with different revisions, all higher than prevRev. Previously all of these goroutines could set prevRev, so prevRev may be replaced by older one. If response's revision equals to prevRev, there's no need to call setPrevRev.
This commit is contained in:
parent
a68a3dc79e
commit
5096b4ed5d
@ -42,11 +42,10 @@ func (kv *kvOrdering) getPrevRev() int64 {
|
||||
}
|
||||
|
||||
func (kv *kvOrdering) setPrevRev(currRev int64) {
|
||||
prevRev := kv.getPrevRev()
|
||||
if currRev > prevRev {
|
||||
kv.revMu.Lock()
|
||||
kv.revMu.Lock()
|
||||
defer kv.revMu.Unlock()
|
||||
if currRev > kv.prevRev {
|
||||
kv.prevRev = currRev
|
||||
kv.revMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +62,9 @@ func (kv *kvOrdering) Get(ctx context.Context, key string, opts ...clientv3.OpOp
|
||||
return nil, err
|
||||
}
|
||||
resp := r.Get()
|
||||
if resp.Header.Revision >= prevRev {
|
||||
if resp.Header.Revision == prevRev {
|
||||
return resp, nil
|
||||
} else if resp.Header.Revision > prevRev {
|
||||
kv.setPrevRev(resp.Header.Revision)
|
||||
return resp, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user