|
@@ -440,7 +440,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|
|
|
|
|
logger.info("Adding two nodes and performing rerouting");
|
|
logger.info("Adding two nodes and performing rerouting");
|
|
clusterState = ClusterState.builder(clusterState)
|
|
clusterState = ClusterState.builder(clusterState)
|
|
- .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")))
|
|
|
|
|
|
+ .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).localNodeId("node1").masterNodeId("node1"))
|
|
.build();
|
|
.build();
|
|
clusterState = strategy.reroute(clusterState, "reroute");
|
|
clusterState = strategy.reroute(clusterState, "reroute");
|
|
|
|
|
|
@@ -535,7 +535,15 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|
|
|
|
|
// add 4 nodes
|
|
// add 4 nodes
|
|
clusterState = ClusterState.builder(clusterState)
|
|
clusterState = ClusterState.builder(clusterState)
|
|
- .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4")))
|
|
|
|
|
|
+ .nodes(
|
|
|
|
+ DiscoveryNodes.builder()
|
|
|
|
+ .add(newNode("node1"))
|
|
|
|
+ .add(newNode("node2"))
|
|
|
|
+ .add(newNode("node3"))
|
|
|
|
+ .add(newNode("node4"))
|
|
|
|
+ .localNodeId("node1")
|
|
|
|
+ .masterNodeId("node1")
|
|
|
|
+ )
|
|
.build();
|
|
.build();
|
|
clusterState = ClusterState.builder(clusterState).routingTable(allocation.reroute(clusterState, "reroute").routingTable()).build();
|
|
clusterState = ClusterState.builder(clusterState).routingTable(allocation.reroute(clusterState, "reroute").routingTable()).build();
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(1));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(1));
|
|
@@ -560,13 +568,19 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|
ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
|
|
ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
|
|
assertThat(newState, not(equalTo(clusterState)));
|
|
assertThat(newState, not(equalTo(clusterState)));
|
|
clusterState = newState;
|
|
clusterState = newState;
|
|
- // the primary gets allocated on another node, replicas are initializing
|
|
|
|
|
|
+
|
|
|
|
+ // The started replica gets promoted to primary and the initializing replica is reset. The other replica will be assigned.
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
|
|
|
|
ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
|
|
ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
|
|
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
|
|
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
|
|
assertThat(newPrimaryShard.allocationId(), equalTo(startedReplica.allocationId()));
|
|
assertThat(newPrimaryShard.allocationId(), equalTo(startedReplica.allocationId()));
|
|
|
|
+
|
|
|
|
+ // Another reroute changes nothing
|
|
|
|
+ clusterState = allocation.reroute(clusterState, "test");
|
|
|
|
+ assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
|
|
+ assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
}
|
|
}
|
|
|
|
|
|
public void testFailAllReplicasInitializingOnPrimaryFailWhileHavingAReplicaToElect() {
|
|
public void testFailAllReplicasInitializingOnPrimaryFailWhileHavingAReplicaToElect() {
|
|
@@ -609,11 +623,18 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|
ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
|
|
ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
|
|
assertThat(newState, not(equalTo(clusterState)));
|
|
assertThat(newState, not(equalTo(clusterState)));
|
|
clusterState = newState;
|
|
clusterState = newState;
|
|
|
|
+
|
|
|
|
+ // The started replica gets promoted to primary and the initializing replica is reset. The other replica will be assigned.
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
|
|
|
|
ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
|
|
ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
|
|
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
|
|
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
|
|
|
|
+
|
|
|
|
+ // Another reroute changes nothing
|
|
|
|
+ clusterState = allocation.reroute(clusterState, "test");
|
|
|
|
+ assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
|
|
|
|
+ assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
|
|
}
|
|
}
|
|
|
|
|
|
public void testReplicaOnNewestVersionIsPromoted() {
|
|
public void testReplicaOnNewestVersionIsPromoted() {
|