Skip to content

Commit

Permalink
etcdserver: skip range requests in txn if the result is needless
Browse files Browse the repository at this point in the history
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
#5689
  • Loading branch information
mitake committed Jul 26, 2016
1 parent 0d6c028 commit faaac03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,19 @@ 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) {
for i := 0; i < len(ops); {
switch ops[i].Request.(type) {
case *pb.RequestOp_RequestRange:
ops = append(ops[:i], ops[i+1:]...)
default:
i++
}
}
}

f(txn.Success)
f(txn.Failure)
}
6 changes: 5 additions & 1 deletion etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit faaac03

Please sign in to comment.