-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Optimize complicated if-else in routing table. #56870
Optimize complicated if-else in routing table. #56870
Conversation
Pinging @elastic/es-distributed (:Distributed/Allocation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make this slighy simpler by dropping some dead code but I'm not sure about the approach taken here. Using the same loop for adding and removing replicas seems really confusing to be honest.
} | ||
} else if (currentNumberOfReplicas > numberOfReplicas) { | ||
int delta = currentNumberOfReplicas - numberOfReplicas; | ||
if (delta <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just remove this condition as it's obviously always false
and keep the rest the same (maybe also inline delta
like we have in the "add" case). Seems to me that makes the logic easiest to digest if we want to change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@original-brownbear Thanks for checking, I think we could pre-compute the delta and seperate the add and remove operation. Please help to review the update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with @original-brownbear here, using Math.abs(expr)
and then branching on the sign of expr
looks weird to me. Let's avoid the use of Math#abs
(and therefore the super-broad @SuppressForbidden
annotation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I removed abs
method. Thank you @DaveCTurner .
Jenkins test this |
Jenkins run elasticsearch-ci/bwc (unrelated) |
@elasticmachine update branch |
user doesn't have permission to update head repository |
@howardhuanghua could you please merge latest |
46f44bd
to
6389d4b
Compare
6389d4b
to
2bb15b2
Compare
@original-brownbear , I have merged the lastest master and updated this branch. Please help to re-trigger the test again. Thank you. |
Jenkins test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
`delta` is always positive here.
`delta` is always positive here. Co-authored-by: Howard <[email protected]>
Optimize the complicated if-else logic in RoutingTable.