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

Optimize complicated if-else in routing table. #56870

Merged
merged 3 commits into from
May 18, 2020

Conversation

howardhuanghua
Copy link
Contributor

Optimize the complicated if-else logic in RoutingTable.

@howardhuanghua howardhuanghua changed the title optimize complicated if-else in routing table Optimize complicated if-else in routing table. May 17, 2020
@original-brownbear original-brownbear added :Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) >non-issue labels May 17, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Allocation)

@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label May 17, 2020
Copy link
Member

@original-brownbear original-brownbear left a 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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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).

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. I removed abs method. Thank you @DaveCTurner .

@original-brownbear
Copy link
Member

Jenkins test this

@original-brownbear
Copy link
Member

Jenkins run elasticsearch-ci/bwc (unrelated)

@original-brownbear
Copy link
Member

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

user doesn't have permission to update head repository

@original-brownbear
Copy link
Member

@howardhuanghua could you please merge latest master into your branch, the BwC tests are broken because it's outdated I think.
Thanks!

@howardhuanghua
Copy link
Contributor Author

@original-brownbear , I have merged the lastest master and updated this branch. Please help to re-trigger the test again. Thank you.

@original-brownbear
Copy link
Member

Jenkins test this

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

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

LGTM

@original-brownbear original-brownbear merged commit e686d30 into elastic:master May 18, 2020
original-brownbear pushed a commit to original-brownbear/elasticsearch that referenced this pull request May 18, 2020
original-brownbear added a commit that referenced this pull request May 18, 2020
`delta` is always positive here.

Co-authored-by: Howard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) >non-issue Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants