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

Make shard balancing deterministic if weights are identical #4866

Merged
merged 1 commit into from Jan 23, 2014

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented Jan 23, 2014

It happens to be the case that the iteration order of a HashMaps
keyset might be different across runs. This can cause undeterministic
results in shard balancing if weights are identical and multiple shards
of the same index are eligable for relocation. This commit adds
a tie-breaker based on the shard ID to prioritise the lowest shard
ID. This also makes AddIncrementallyTests#testAddNodesAndIndices
reproducible.

@@ -804,7 +804,8 @@ private boolean tryRelocateShard(Operation operation, ModelNode minNode, ModelNo
if ((srcDecision = maxNode.removeShard(shard)) != null) {
minNode.addShard(shard, srcDecision);
final float delta = weight.weight(operation, this, minNode, idx) - weight.weight(operation, this, maxNode, idx);
if (delta < minCost) {
if (delta < minCost ||
(candidate != null && delta == minCost && candidate.id() > shard.id())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. Maybe there could just be a comment that this tie-breaker is necessary to make shard balancing deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already added it :) updateing in a sec and referencing the corresponding issue.

@jpountz
Copy link
Contributor

jpountz commented Jan 23, 2014

+1

It happens to be the case that the iteration order of a HashMaps
keyset might be different across runs. This can cause undeterministic
results in shard balancing if weights are identical and multiple shards
of the same index are eligable for relocation. This commit adds
a tie-breaker based on the shard ID to prioritise the lowest shard
ID. This also makes `AddIncrementallyTests#testAddNodesAndIndices`
reproducible.

Closes elastic#4867
@s1monw s1monw merged commit 592a411 into elastic:master Jan 23, 2014
@s1monw s1monw deleted the deterministic_balancing branch January 23, 2014 15:16
@lcawl lcawl added :Distributed/Distributed A catch all label for anything in the Distributed Area. If you aren't sure, use this one. and removed :Allocation labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Distributed A catch all label for anything in the Distributed Area. If you aren't sure, use this one. >enhancement v0.90.11 v1.0.0.RC2 v1.1.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants