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 55d4404
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) {
resps := make([]*pb.ResponseOp, len(reqs))
changedKV := false
for i := range reqs {
if reqs[i] == nil {
// removed by removeNeedlessRangeReqs()
continue
}

if reqs[i].GetRequestRange() == nil {
changedKV = true
}
Expand Down Expand Up @@ -732,6 +737,11 @@ func (s *kvSortByValue) Less(i, j int) bool {

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

tv, ok := requ.Request.(*pb.RequestOp_RequestPut)
if !ok {
continue
Expand All @@ -749,6 +759,11 @@ func (a *applierV3backend) checkRequestLeases(reqs []*pb.RequestOp) error {

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

tv, ok := requ.Request.(*pb.RequestOp_RequestRange)
if !ok {
continue
Expand Down Expand Up @@ -788,3 +803,17 @@ 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); i++ {
switch ops[i].Request.(type) {
case *pb.RequestOp_RequestRange:
ops[i] = nil
}
}
}

f(txn.Success)
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 55d4404

Please sign in to comment.