Merge pull request #4407 from heyitsanthony/txn-no-retry

clientv3: don't retry txns that may modify the store
release-2.3
Anthony Romano 2016-02-03 15:37:49 -08:00
commit c07fc3e08e
3 changed files with 13 additions and 1 deletions

View File

@ -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
}

View File

@ -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,

View File

@ -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
}