etcdserver: skip range requests in txn if the result is needless

If a server isn't serving txn requests from a client, the server
doesn't need the result of range requests in the txn.

This is a succeeding commit of
https://github.com/coreos/etcd/pull/5689
release-3.1
Hitoshi Mitake 2016-07-08 15:29:37 +09:00 committed by Hitoshi Mitake
parent 0d6c028aa2
commit 0090573749
2 changed files with 23 additions and 1 deletions

View File

@ -788,3 +788,21 @@ func isGteRange(rangeEnd []byte) bool {
func noSideEffect(r *pb.InternalRaftRequest) bool {
return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil
}
func removeNeedlessRangeReqs(txn *pb.TxnRequest) {
f := func(ops []*pb.RequestOp) []*pb.RequestOp {
j := 0
for i := 0; i < len(ops); i++ {
if _, ok := ops[i].Request.(*pb.RequestOp_RequestRange); ok {
continue
}
ops[j] = ops[i]
j++
}
return ops[:j]
}
txn.Success = f(txn.Success)
txn.Failure = f(txn.Failure)
}

View File

@ -1080,7 +1080,11 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) {
}
var ar *applyResult
if s.w.IsRegistered(id) || !noSideEffect(&raftReq) {
needResult := s.w.IsRegistered(id)
if needResult || !noSideEffect(&raftReq) {
if !needResult && raftReq.Txn != nil {
removeNeedlessRangeReqs(raftReq.Txn)
}
ar = s.applyV3.Apply(&raftReq)
}