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 27, 2016
1 parent 0d6c028 commit 157a7da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions etcdserver/apply_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (aa *authApplierV3) DeleteRange(txnID int64, r *pb.DeleteRangeRequest) (*pb

func (aa *authApplierV3) checkTxnReqsPermission(reqs []*pb.RequestOp) error {
for _, requ := range reqs {
if requ == nil {
// removed by removeNeedlessRangeReqs()
continue
}

switch tv := requ.Request.(type) {
case *pb.RequestOp_RequestRange:
if tv.RequestRange == nil {
Expand Down
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 157a7da

Please sign in to comment.