Skip to content

Commit 30feced

Browse files
authored
Include both index and shard ID in allocation messages (#115895)
The shardId in AllocationCommand is the 0-based ID for the shard. It needs to be combined with the index name to make sense in both error and explanation messages. This PR ensures that is the case for both CancelAllocationCommand and MoveAllocationCommand. Other commands are already doing the same thing.
1 parent 32b1fc2 commit 30feced

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/CancelAllocationCommand.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
136136
allocation.decision(
137137
Decision.NO,
138138
"cancel_allocation_command",
139-
"can't cancel " + shardId + ", failed to find it on node " + discoNode
139+
"can't cancel [" + index + "][" + shardId + "], failed to find it on node " + discoNode
140140
)
141141
);
142142
}
143-
throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + ", failed to find it on node " + discoNode);
143+
throw new IllegalArgumentException(
144+
"[cancel_allocation] can't cancel [" + index + "][" + shardId + "], failed to find it on node " + discoNode
145+
);
144146
}
145147
if (shardRouting.primary() && allowPrimary == false) {
146148
if ((shardRouting.initializing() && shardRouting.relocatingNodeId() != null) == false) {
@@ -151,19 +153,23 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
151153
allocation.decision(
152154
Decision.NO,
153155
"cancel_allocation_command",
154-
"can't cancel "
156+
"can't cancel ["
157+
+ index
158+
+ "]["
155159
+ shardId
156-
+ " on node "
160+
+ "] on node "
157161
+ discoNode
158162
+ ", shard is primary and "
159163
+ shardRouting.state().name().toLowerCase(Locale.ROOT)
160164
)
161165
);
162166
}
163167
throw new IllegalArgumentException(
164-
"[cancel_allocation] can't cancel "
168+
"[cancel_allocation] can't cancel ["
169+
+ index
170+
+ "]["
165171
+ shardId
166-
+ " on node "
172+
+ "] on node "
167173
+ discoNode
168174
+ ", shard is primary and "
169175
+ shardRouting.state().name().toLowerCase(Locale.ROOT)
@@ -178,7 +184,7 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
178184
allocation.decision(
179185
Decision.YES,
180186
"cancel_allocation_command",
181-
"shard " + shardId + " on node " + discoNode + " can be cancelled"
187+
"shard [" + index + "][" + shardId + "] on node " + discoNode + " can be cancelled"
182188
)
183189
);
184190
}

server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
141141
if (explain) {
142142
return new RerouteExplanation(
143143
this,
144-
allocation.decision(Decision.NO, "move_allocation_command", "shard " + shardId + " has not been started")
144+
allocation.decision(
145+
Decision.NO,
146+
"move_allocation_command",
147+
"shard [" + index + "][" + shardId + "] has not been started"
148+
)
145149
);
146150
}
147151
throw new IllegalArgumentException(
148-
"[move_allocation] can't move " + shardId + ", shard is not started (state = " + shardRouting.state() + "]"
152+
"[move_allocation] can't move ["
153+
+ index
154+
+ "]["
155+
+ shardId
156+
+ "], shard is not started (state = "
157+
+ shardRouting.state()
158+
+ "]"
149159
);
150160
}
151161

@@ -155,9 +165,11 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
155165
return new RerouteExplanation(this, decision);
156166
}
157167
throw new IllegalArgumentException(
158-
"[move_allocation] can't move "
168+
"[move_allocation] can't move ["
169+
+ index
170+
+ "]["
159171
+ shardId
160-
+ ", from "
172+
+ "], from "
161173
+ fromDiscoNode
162174
+ ", to "
163175
+ toDiscoNode
@@ -182,10 +194,12 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain)
182194
if (explain) {
183195
return new RerouteExplanation(
184196
this,
185-
allocation.decision(Decision.NO, "move_allocation_command", "shard " + shardId + " not found")
197+
allocation.decision(Decision.NO, "move_allocation_command", "shard [" + index + "][" + shardId + "] not found")
186198
);
187199
}
188-
throw new IllegalArgumentException("[move_allocation] can't move " + shardId + ", failed to find it on node " + fromDiscoNode);
200+
throw new IllegalArgumentException(
201+
"[move_allocation] can't move [" + index + "][" + shardId + "], failed to find it on node " + fromDiscoNode
202+
);
189203
}
190204
return new RerouteExplanation(this, decision);
191205
}

0 commit comments

Comments
 (0)