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

Fix optimization in BalancedShardsAllocator #87843

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ public void writeTo(StreamOutput out) throws IOException {
* be forced to move to another node.
*/
public static MoveDecision stay(Decision canRemainDecision) {
if (canRemainDecision != null) {
assert canRemainDecision.type() != Type.NO;
return new MoveDecision(canRemainDecision, null, AllocationDecision.NO_ATTEMPT, null, null, 0);
} else {
if (canRemainDecision == Decision.YES) {
return CACHED_STAY_DECISION;
}
assert canRemainDecision.type() != Type.NO;
return new MoveDecision(canRemainDecision, null, AllocationDecision.NO_ATTEMPT, null, null, 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public class MoveDecisionTests extends ESTestCase {

public void testCachedDecisions() {
// cached stay decision
MoveDecision stay1 = MoveDecision.stay(null);
MoveDecision stay2 = MoveDecision.stay(null);
MoveDecision stay1 = MoveDecision.stay(Decision.YES);
MoveDecision stay2 = MoveDecision.stay(Decision.YES);
assertSame(stay1, stay2); // not in explain mode, so should use cached decision
stay1 = MoveDecision.stay(Decision.YES);
stay2 = MoveDecision.stay(Decision.YES);

stay1 = MoveDecision.stay(new Decision.Single(Type.YES, null, null, (Object[]) null));
stay2 = MoveDecision.stay(new Decision.Single(Type.YES, null, null, (Object[]) null));
assertNotSame(stay1, stay2);

// cached cannot move decision
Expand Down