Skip to content

Commit

Permalink
Format message only when debug is enabled (#96437)
Browse files Browse the repository at this point in the history
This change uses `allocation.decision` instead of `Decision.single` so that we
are checking debug flag before formatting explanation message.
  • Loading branch information
idegtiarenko authored May 31, 2023
1 parent 83bfcc6 commit 47c70f9
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
if (replacementOngoing(allocation) == false) {
return YES__NO_REPLACEMENTS;
} else if (replacementFromSourceToTarget(allocation, shardRouting.currentNodeId(), node.node().getName())) {
return Decision.single(
Decision.Type.YES,
return allocation.decision(
Decision.YES,
NAME,
"node [%s] is replacing node [%s], and may receive shards from it",
shardRouting.currentNodeId(),
Expand All @@ -48,16 +48,16 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
return YES__RECONCILING;
}

return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is being replaced, and its shards may only be allocated to the replacement target [%s]",
shardRouting.currentNodeId(),
getReplacementName(allocation, shardRouting.currentNodeId())
);
} else if (isReplacementSource(allocation, node.nodeId())) {
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is being replaced by [%s], so no data may be allocated to it",
node.nodeId(),
Expand All @@ -73,8 +73,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
}

final SingleNodeShutdownMetadata shutdown = allocation.replacementTargetShutdowns().get(node.node().getName());
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is replacing the vacating node [%s], only data currently allocated to the source node "
+ "may be allocated to it until the replacement is complete",
Expand All @@ -92,8 +92,8 @@ public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting
if (replacementOngoing(allocation) == false) {
return YES__NO_REPLACEMENTS;
} else if (isReplacementSource(allocation, node.nodeId())) {
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is being replaced by node [%s], so no data may remain on it",
node.nodeId(),
Expand All @@ -110,17 +110,17 @@ public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNod
return YES__NO_REPLACEMENTS;
} else if (isReplacementTargetName(allocation, node.getName())) {
final SingleNodeShutdownMetadata shutdown = allocation.replacementTargetShutdowns().get(node.getName());
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is a node replacement target for node [%s], "
+ "shards cannot auto expand to be on it until the replacement is complete",
node.getId(),
shutdown == null ? null : shutdown.getNodeId()
);
} else if (isReplacementSource(allocation, node.getId())) {
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"node [%s] is being replaced by [%s], shards cannot auto expand to be on it",
node.getId(),
Expand All @@ -134,16 +134,16 @@ public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNod
@Override
public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
if (replacementFromSourceToTarget(allocation, shardRouting.currentNodeId(), node.node().getName())) {
return Decision.single(
Decision.Type.YES,
return allocation.decision(
Decision.YES,
NAME,
"node [%s] is being replaced by node [%s], and can be force vacated to the target",
shardRouting.currentNodeId(),
node.nodeId()
);
} else {
return Decision.single(
Decision.Type.NO,
return allocation.decision(
Decision.NO,
NAME,
"shard is not on the source of a node replacement relocated to the replacement target"
);
Expand All @@ -153,8 +153,8 @@ public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, Routing
@Override
public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
if (isReplacementTargetName(allocation, node.node().getName())) {
return Decision.single(
Decision.Type.YES,
return allocation.decision(
Decision.YES,
NAME,
"node [%s] is a node replacement target and can have a previously allocated replica re-allocated to it",
node.nodeId()
Expand Down

0 comments on commit 47c70f9

Please sign in to comment.