Skip to content

Commit 47c70f9

Browse files
authored
Format message only when debug is enabled (#96437)
This change uses `allocation.decision` instead of `Decision.single` so that we are checking debug flag before formatting explanation message.
1 parent 83bfcc6 commit 47c70f9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
3434
if (replacementOngoing(allocation) == false) {
3535
return YES__NO_REPLACEMENTS;
3636
} else if (replacementFromSourceToTarget(allocation, shardRouting.currentNodeId(), node.node().getName())) {
37-
return Decision.single(
38-
Decision.Type.YES,
37+
return allocation.decision(
38+
Decision.YES,
3939
NAME,
4040
"node [%s] is replacing node [%s], and may receive shards from it",
4141
shardRouting.currentNodeId(),
@@ -48,16 +48,16 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
4848
return YES__RECONCILING;
4949
}
5050

51-
return Decision.single(
52-
Decision.Type.NO,
51+
return allocation.decision(
52+
Decision.NO,
5353
NAME,
5454
"node [%s] is being replaced, and its shards may only be allocated to the replacement target [%s]",
5555
shardRouting.currentNodeId(),
5656
getReplacementName(allocation, shardRouting.currentNodeId())
5757
);
5858
} else if (isReplacementSource(allocation, node.nodeId())) {
59-
return Decision.single(
60-
Decision.Type.NO,
59+
return allocation.decision(
60+
Decision.NO,
6161
NAME,
6262
"node [%s] is being replaced by [%s], so no data may be allocated to it",
6363
node.nodeId(),
@@ -73,8 +73,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
7373
}
7474

7575
final SingleNodeShutdownMetadata shutdown = allocation.replacementTargetShutdowns().get(node.node().getName());
76-
return Decision.single(
77-
Decision.Type.NO,
76+
return allocation.decision(
77+
Decision.NO,
7878
NAME,
7979
"node [%s] is replacing the vacating node [%s], only data currently allocated to the source node "
8080
+ "may be allocated to it until the replacement is complete",
@@ -92,8 +92,8 @@ public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting
9292
if (replacementOngoing(allocation) == false) {
9393
return YES__NO_REPLACEMENTS;
9494
} else if (isReplacementSource(allocation, node.nodeId())) {
95-
return Decision.single(
96-
Decision.Type.NO,
95+
return allocation.decision(
96+
Decision.NO,
9797
NAME,
9898
"node [%s] is being replaced by node [%s], so no data may remain on it",
9999
node.nodeId(),
@@ -110,17 +110,17 @@ public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNod
110110
return YES__NO_REPLACEMENTS;
111111
} else if (isReplacementTargetName(allocation, node.getName())) {
112112
final SingleNodeShutdownMetadata shutdown = allocation.replacementTargetShutdowns().get(node.getName());
113-
return Decision.single(
114-
Decision.Type.NO,
113+
return allocation.decision(
114+
Decision.NO,
115115
NAME,
116116
"node [%s] is a node replacement target for node [%s], "
117117
+ "shards cannot auto expand to be on it until the replacement is complete",
118118
node.getId(),
119119
shutdown == null ? null : shutdown.getNodeId()
120120
);
121121
} else if (isReplacementSource(allocation, node.getId())) {
122-
return Decision.single(
123-
Decision.Type.NO,
122+
return allocation.decision(
123+
Decision.NO,
124124
NAME,
125125
"node [%s] is being replaced by [%s], shards cannot auto expand to be on it",
126126
node.getId(),
@@ -134,16 +134,16 @@ public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNod
134134
@Override
135135
public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
136136
if (replacementFromSourceToTarget(allocation, shardRouting.currentNodeId(), node.node().getName())) {
137-
return Decision.single(
138-
Decision.Type.YES,
137+
return allocation.decision(
138+
Decision.YES,
139139
NAME,
140140
"node [%s] is being replaced by node [%s], and can be force vacated to the target",
141141
shardRouting.currentNodeId(),
142142
node.nodeId()
143143
);
144144
} else {
145-
return Decision.single(
146-
Decision.Type.NO,
145+
return allocation.decision(
146+
Decision.NO,
147147
NAME,
148148
"shard is not on the source of a node replacement relocated to the replacement target"
149149
);
@@ -153,8 +153,8 @@ public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, Routing
153153
@Override
154154
public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
155155
if (isReplacementTargetName(allocation, node.node().getName())) {
156-
return Decision.single(
157-
Decision.Type.YES,
156+
return allocation.decision(
157+
Decision.YES,
158158
NAME,
159159
"node [%s] is a node replacement target and can have a previously allocated replica re-allocated to it",
160160
node.nodeId()

0 commit comments

Comments
 (0)