Reset source shards to `started` if canceling relocation.
Currently we miss to reset the source shards status to ACTIVE if we cancel a relocation. If the shard is RELOCATING we need to reset to state ACTIVE. Closes #4457
This commit is contained in:
parent
30c6f2fa23
commit
8d321530de
|
@ -176,9 +176,7 @@ public class CancelAllocationCommand implements AllocationCommand {
|
||||||
RoutingNode relocatingFromNode = allocation.routingNodes().node(shardRouting.relocatingNodeId());
|
RoutingNode relocatingFromNode = allocation.routingNodes().node(shardRouting.relocatingNodeId());
|
||||||
if (relocatingFromNode != null) {
|
if (relocatingFromNode != null) {
|
||||||
for (MutableShardRouting fromShardRouting : relocatingFromNode) {
|
for (MutableShardRouting fromShardRouting : relocatingFromNode) {
|
||||||
assert shardRouting.state() != RELOCATING;
|
if (fromShardRouting.shardId().equals(shardRouting.shardId()) && fromShardRouting.state() == RELOCATING) {
|
||||||
if (fromShardRouting.shardId().equals(shardRouting.shardId()) && shardRouting.state() == RELOCATING) {
|
|
||||||
// NOCOMMIT @Shay the check on the shardRouting.state() == RELOCATING can never be true right this should be fromShardRouting?
|
|
||||||
allocation.routingNodes().cancelRelocation(fromShardRouting);
|
allocation.routingNodes().cancelRelocation(fromShardRouting);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||||
|
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||||
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
|
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
|
@ -301,6 +302,25 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
|
||||||
assertThat(clusterState.routingNodes().node("node2").size(), equalTo(1));
|
assertThat(clusterState.routingNodes().node("node2").size(), equalTo(1));
|
||||||
assertThat(clusterState.routingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
assertThat(clusterState.routingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
||||||
|
|
||||||
|
logger.info("--> move the replica shard");
|
||||||
|
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand(new ShardId("test", 0), "node2", "node3")));
|
||||||
|
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
||||||
|
assertThat(clusterState.routingNodes().node("node1").size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node2").size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node2").shardsWithState(RELOCATING).size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node3").size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||||
|
|
||||||
|
logger.info("--> cancel the move of the replica shard");
|
||||||
|
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand(new ShardId("test", 0), "node3", false)));
|
||||||
|
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
||||||
|
assertThat(clusterState.routingNodes().node("node1").size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node2").size(), equalTo(1));
|
||||||
|
assertThat(clusterState.routingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
||||||
|
|
||||||
|
|
||||||
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
|
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
|
||||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand(new ShardId("test", 0), "node1", true)));
|
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand(new ShardId("test", 0), "node1", true)));
|
||||||
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
||||||
|
|
Loading…
Reference in New Issue