Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 27, 2016

Conversation

mitake
Copy link
Contributor

@mitake mitake commented Jul 11, 2016

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

/cc @xiang90

@mitake
Copy link
Contributor Author

mitake commented Jul 19, 2016

kindly ping? @xiang90

@@ -49,12 +49,12 @@ type applyResult struct {

// applierV3 is the interface for processing V3 raft messages
type applierV3 interface {
Apply(r *pb.InternalRaftRequest) *applyResult
Apply(r *pb.InternalRaftRequest, hasWaiter bool) *applyResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasWaiter -> canSkip? From applier perspective, haswaiter does not make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canSkip seems to be better. I'll rename the parameter, thanks.

@xiang90
Copy link
Contributor

xiang90 commented Jul 21, 2016

lgtm. need to rebase. sorry for the review delay.

@mitake
Copy link
Contributor Author

mitake commented Jul 22, 2016

@xiang90 updated for the renaming and rebasing , PTAL.

ar = s.applyV3.Apply(&raftReq)
canSkip := !s.w.IsRegistered(id)
if !canSkip || !noSideEffect(&raftReq) {
ar = s.applyV3.Apply(&raftReq, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s.applyV3.Apply(&raftReq, canSkip)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for pointing, I'll fix it.

@mitake
Copy link
Contributor Author

mitake commented Jul 22, 2016

@xiang90 updated for your comment, PTAL.

@heyitsanthony
Copy link
Contributor

@mitake This interface change seems somewhat excessive for what it does. I think it would be cleaner to strip out the range requests from the txn request before passing it to Apply instead of having a special flag for this edge case. What do you think?

@mitake
Copy link
Contributor Author

mitake commented Jul 25, 2016

@heyitsanthony yes, your idea seems to be far better than the current implementation. I'll fix this PR later.

@mitake
Copy link
Contributor Author

mitake commented Jul 26, 2016

@heyitsanthony @xiang90 updated for simplifying, PTAL.

for i := 0; i < len(ops); {
switch ops[i].Request.(type) {
case *pb.RequestOp_RequestRange:
ops = append(ops[:i], ops[i+1:]...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably just nil it out instead of appending? then we can avoid some allocations...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@mitake
Copy link
Contributor Author

mitake commented Jul 26, 2016

@xiang90 updated for your comment, PTAL.

@xiang90
Copy link
Contributor

xiang90 commented Jul 26, 2016

lgtm defer to @heyitsanthony

@heyitsanthony
Copy link
Contributor

lgtm


func removeNeedlessRangeReqs(txn *pb.TxnRequest) {
f := func(ops []*pb.RequestOp) {
for i := 0; i < len(ops); i++ {
Copy link
Contributor

@heyitsanthony heyitsanthony Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to avoid all the nil checks + keep the alloc-free stuff,

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it seems to be better. I'll follow this style and remove the nil checks in the apply phase.

@mitake
Copy link
Contributor Author

mitake commented Jul 27, 2016

@heyitsanthony @xiang90 updated for the better removal of range reqs, PTAL

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
etcd-io#5689
@heyitsanthony
Copy link
Contributor

lgtm, thanks!

@xiang90 xiang90 merged commit 3c3b33b into etcd-io:master Jul 27, 2016
@mitake mitake deleted the skip-apply-txn branch July 27, 2016 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants