From 154b25ac954bfa2714848f5608a46751c04b3805 Mon Sep 17 00:00:00 2001 From: Yang Wang Date: Wed, 30 Oct 2024 12:43:50 +1100 Subject: [PATCH] Include both index and shard ID in allocation messages 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. --- .../command/CancelAllocationCommand.java | 20 +++++++++----- .../command/MoveAllocationCommand.java | 26 ++++++++++++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/CancelAllocationCommand.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/CancelAllocationCommand.java index 79daceaf11851..f946402d1fa09 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/CancelAllocationCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/CancelAllocationCommand.java @@ -136,11 +136,13 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) allocation.decision( Decision.NO, "cancel_allocation_command", - "can't cancel " + shardId + ", failed to find it on node " + discoNode + "can't cancel [" + index + "][" + shardId + "], failed to find it on node " + discoNode ) ); } - throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + ", failed to find it on node " + discoNode); + throw new IllegalArgumentException( + "[cancel_allocation] can't cancel [" + index + "][" + shardId + "], failed to find it on node " + discoNode + ); } if (shardRouting.primary() && allowPrimary == false) { if ((shardRouting.initializing() && shardRouting.relocatingNodeId() != null) == false) { @@ -151,9 +153,11 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) allocation.decision( Decision.NO, "cancel_allocation_command", - "can't cancel " + "can't cancel [" + + index + + "][" + shardId - + " on node " + + "] on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT) @@ -161,9 +165,11 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) ); } throw new IllegalArgumentException( - "[cancel_allocation] can't cancel " + "[cancel_allocation] can't cancel [" + + index + + "][" + shardId - + " on node " + + "] on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT) @@ -178,7 +184,7 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) allocation.decision( Decision.YES, "cancel_allocation_command", - "shard " + shardId + " on node " + discoNode + " can be cancelled" + "shard [" + index + "][" + shardId + "] on node " + discoNode + " can be cancelled" ) ); } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java index 4295a6178168a..b937ebdc33091 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java @@ -141,11 +141,21 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) if (explain) { return new RerouteExplanation( this, - allocation.decision(Decision.NO, "move_allocation_command", "shard " + shardId + " has not been started") + allocation.decision( + Decision.NO, + "move_allocation_command", + "shard [" + index + "][" + shardId + "] has not been started" + ) ); } throw new IllegalArgumentException( - "[move_allocation] can't move " + shardId + ", shard is not started (state = " + shardRouting.state() + "]" + "[move_allocation] can't move [" + + index + + "][" + + shardId + + "], shard is not started (state = " + + shardRouting.state() + + "]" ); } @@ -155,9 +165,11 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) return new RerouteExplanation(this, decision); } throw new IllegalArgumentException( - "[move_allocation] can't move " + "[move_allocation] can't move [" + + index + + "][" + shardId - + ", from " + + "], from " + fromDiscoNode + ", to " + toDiscoNode @@ -182,10 +194,12 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) if (explain) { return new RerouteExplanation( this, - allocation.decision(Decision.NO, "move_allocation_command", "shard " + shardId + " not found") + allocation.decision(Decision.NO, "move_allocation_command", "shard [" + index + "][" + shardId + "] not found") ); } - throw new IllegalArgumentException("[move_allocation] can't move " + shardId + ", failed to find it on node " + fromDiscoNode); + throw new IllegalArgumentException( + "[move_allocation] can't move [" + index + "][" + shardId + "], failed to find it on node " + fromDiscoNode + ); } return new RerouteExplanation(this, decision); }