mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4407 from heyitsanthony/txn-no-retry
clientv3: don't retry txns that may modify the store
This commit is contained in:
commit
c07fc3e08e
@ -185,7 +185,7 @@ func (kv *kv) do(op Op) (*pb.ResponseUnion, error) {
|
||||
}
|
||||
|
||||
// do not retry on modifications
|
||||
if op.t != tRange {
|
||||
if op.isWrite() {
|
||||
go kv.switchRemote(err)
|
||||
return nil, err
|
||||
}
|
||||
|
@ -64,6 +64,10 @@ func (op Op) toRequestUnion() *pb.RequestUnion {
|
||||
}
|
||||
}
|
||||
|
||||
func (op Op) isWrite() bool {
|
||||
return op.t != tRange
|
||||
}
|
||||
|
||||
func OpRange(key, end string, limit, rev int64, sort *SortOption) Op {
|
||||
return Op{
|
||||
t: tRange,
|
||||
|
@ -58,6 +58,8 @@ type txn struct {
|
||||
cthen bool
|
||||
celse bool
|
||||
|
||||
isWrite bool
|
||||
|
||||
cmps []*pb.Compare
|
||||
|
||||
sus []*pb.RequestUnion
|
||||
@ -101,6 +103,7 @@ func (txn *txn) Then(ops ...Op) Txn {
|
||||
txn.cthen = true
|
||||
|
||||
for _, op := range ops {
|
||||
txn.isWrite = txn.isWrite || op.isWrite()
|
||||
txn.sus = append(txn.sus, op.toRequestUnion())
|
||||
}
|
||||
|
||||
@ -118,6 +121,7 @@ func (txn *txn) Else(ops ...Op) Txn {
|
||||
txn.celse = true
|
||||
|
||||
for _, op := range ops {
|
||||
txn.isWrite = txn.isWrite || op.isWrite()
|
||||
txn.fas = append(txn.fas, op.toRequestUnion())
|
||||
}
|
||||
|
||||
@ -137,6 +141,10 @@ func (txn *txn) Commit() (*TxnResponse, error) {
|
||||
return (*TxnResponse)(resp), nil
|
||||
}
|
||||
|
||||
if txn.isWrite {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isRPCError(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user