Skip to content

Commit

Permalink
Include both index and shard ID in allocation messages (#115895)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ywangd authored and jozala committed Nov 13, 2024
1 parent a703a1c commit 63ea717
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -151,19 +153,23 @@ 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)
)
);
}
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)
Expand All @@ -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"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
+ "]"
);
}

Expand All @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 63ea717

Please sign in to comment.