Skip to content
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 @@ -153,7 +153,7 @@ public boolean isDecisionTaken() {
*/
public boolean cannotRemainAndCanMove() {
checkDecisionState();
return canRemain() == false && canMoveDecision == AllocationDecision.YES;
return cannotRemain() && canMoveDecision == AllocationDecision.YES;
}

/**
Expand All @@ -163,7 +163,7 @@ public boolean cannotRemainAndCanMove() {
*/
public boolean cannotRemainAndCannotMove() {
checkDecisionState();
return canRemain() == false && canMoveDecision != AllocationDecision.YES;
return cannotRemain() && canMoveDecision != AllocationDecision.YES;
}

/**
Expand All @@ -175,6 +175,14 @@ public boolean canRemain() {
return canRemainDecision.type() == Type.YES;
}

/**
* Returns {@code true} if the shard cannot remain on its current node, returns {@code false} if the shard can remain.
* If {@link #isDecisionTaken()} returns {@code false}, then invoking this method will throw an {@code IllegalStateException}.
*/
public boolean cannotRemain() {
return canRemain() == false;
}

/**
* Returns the decision for the shard being allowed to remain on its current node. If {@link #isDecisionTaken()}
* returns {@code false}, then invoking this method will throw an {@code IllegalStateException}.
Expand Down Expand Up @@ -257,7 +265,7 @@ public String getExplanation() {
};
} else {
// it was a decision to force move the shard
assert canRemain() == false;
assert cannotRemain();
return switch (canMoveDecision) {
case YES -> Explanations.Move.YES;
case THROTTLED -> Explanations.Move.THROTTLED;
Expand All @@ -280,7 +288,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
builder.endObject();
}
builder.field("can_remain_on_current_node", canRemain() ? "yes" : "no");
if (canRemain() == false && canRemainDecision.getDecisions().isEmpty() == false) {
if (cannotRemain() && canRemainDecision.getDecisions().isEmpty() == false) {
builder.startArray("can_remain_decisions");
canRemainDecision.toXContent(builder, params);
builder.endArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public ShardAllocationDecision explainShardAllocation(final ShardRouting shard,
} else {
moveDecision = balancer.decideMove(index, shard);
if (moveDecision.isDecisionTaken() && moveDecision.canRemain()) {
moveDecision = balancer.decideRebalance(index, shard, moveDecision.getCanRemainDecision());
moveDecision = balancer.explainRebalanceDecision(index, shard, moveDecision.getCanRemainDecision());
}
}
return new ShardAllocationDecision(allocateUnassignedDecision, moveDecision);
Expand Down Expand Up @@ -465,7 +465,7 @@ private boolean balance() {
* optimally balanced cluster. This method is invoked from the cluster allocation
* explain API only.
*/
private MoveDecision decideRebalance(final ProjectIndex index, final ShardRouting shard, Decision canRemain) {
private MoveDecision explainRebalanceDecision(final ProjectIndex index, final ShardRouting shard, Decision canRemain) {
final NodeSorter sorter = nodeSorters.sorterForShard(shard);
index.assertMatch(shard);
if (shard.started() == false) {
Expand Down Expand Up @@ -852,7 +852,7 @@ public boolean moveShards() {
}
shardMoved = true;
}
} else if (moveDecision.isDecisionTaken() && moveDecision.canRemain() == false) {
} else if (moveDecision.isDecisionTaken() && moveDecision.cannotRemain()) {
logger.trace("[{}][{}] can't move", shardRouting.index(), shardRouting.id());
}
}
Expand Down Expand Up @@ -945,13 +945,13 @@ private MoveDecision decideMove(ProjectIndex index, ShardRouting shardRouting, P
final ModelNode sourceNode = nodes.get(shardRouting.currentNodeId());
assert sourceNode != null && sourceNode.containsShard(index, shardRouting);
RoutingNode routingNode = sourceNode.getRoutingNode();
Decision canRemain = allocation.deciders().canRemain(shardRouting, routingNode, allocation);
if (canRemain.type() != Decision.Type.NO && canRemain.type() != Decision.Type.NOT_PREFERRED) {
return MoveDecision.createRemainYesDecision(canRemain);
Decision canRemainDecision = allocation.deciders().canRemain(shardRouting, routingNode, allocation);
if (canRemainDecision.type() != Decision.Type.NO && canRemainDecision.type() != Decision.Type.NOT_PREFERRED) {
return MoveDecision.createRemainYesDecision(canRemainDecision);
}

// Check predicate to decide whether to assess movement options
if (canRemain.type() == Type.NOT_PREFERRED && nonPreferredPredicate.test(shardRouting) == false) {
if (canRemainDecision.type() == Type.NOT_PREFERRED && nonPreferredPredicate.test(shardRouting) == false) {
return MoveDecision.NOT_TAKEN;
}

Expand All @@ -962,11 +962,11 @@ private MoveDecision decideMove(ProjectIndex index, ShardRouting shardRouting, P
* This is not guaranteed to be balanced after this operation we still try best effort to
* allocate on the minimal eligible node.
*/
final MoveDecision moveDecision = decideMove(sorter, shardRouting, sourceNode, canRemain, this::decideCanAllocate);
final MoveDecision moveDecision = decideMove(sorter, shardRouting, sourceNode, canRemainDecision, this::decideCanAllocate);
if (moveDecision.cannotRemainAndCannotMove()) {
final boolean shardsOnReplacedNode = allocation.metadata().nodeShutdowns().contains(shardRouting.currentNodeId(), REPLACE);
if (shardsOnReplacedNode) {
return decideMove(sorter, shardRouting, sourceNode, canRemain, this::decideCanForceAllocateForVacate);
return decideMove(sorter, shardRouting, sourceNode, canRemainDecision, this::decideCanForceAllocateForVacate);
}
}
return moveDecision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ static ShutdownShardMigrationStatus shardMigrationStatus(
.map(shardRouting -> new Tuple<>(shardRouting, allocationService.explainShardAllocation(shardRouting, allocation)))
// Given that we're checking the status of a node that's shutting down, no shards should be allowed to remain
.filter(pair -> {
assert pair.v2().getMoveDecision().canRemain() == false
assert pair.v2().getMoveDecision().cannotRemain()
: "shard [" + pair + "] can remain on node [" + nodeId + "], but that node is shutting down";
return pair.v2().getMoveDecision().canRemain() == false;
return pair.v2().getMoveDecision().cannotRemain();
})
// These shards will move as soon as possible
.filter(pair -> pair.v2().getMoveDecision().getAllocationDecision().equals(AllocationDecision.YES) == false)
Expand Down