use of org.opensearch.cluster.routing.ShardRoutingState.RELOCATING in project OpenSearch by opensearch-project.
the class ThrottlingAllocationTests method testRecoveryCounts.
public void testRecoveryCounts() {
TestGatewayAllocator gatewayAllocator = new TestGatewayAllocator();
Settings settings = Settings.builder().put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey(), 1).put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING.getKey(), 20).put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(), 2).build();
AllocationService strategy = createAllocationService(settings, gatewayAllocator);
Metadata metadata = Metadata.builder().persistentSettings(settings).build();
ClusterState clusterState = ClusterState.builder(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
logger.info("create a new index and start all primaries");
clusterState = createNewIndexAndStartAllPrimaries(2, 2, strategy, clusterState);
logger.info("Add a new node for all replica assignment. 4 replicas move to INIT after reroute.");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().index("new_index").shardsWithState(UNASSIGNED).size(), equalTo(0));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).size(), equalTo(4));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node1"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node2"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node3"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node1"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node2"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node3"), equalTo(0));
logger.info("Exclude node1 and add node4. After this, primary shard on node1 moves to RELOCATING state and only " + "non initial replica recoveries are impacted");
settings = Settings.builder().put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING.getKey(), 1).put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING.getKey(), 20).put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_REPLICAS_RECOVERIES_SETTING.getKey(), 2).put("cluster.routing.allocation.exclude._id", "node1").build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node4"))).build();
strategy = createAllocationService(settings, gatewayAllocator);
clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().index("new_index").shardsWithState(UNASSIGNED).size(), equalTo(0));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).size(), equalTo(5));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node4"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node1"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node2"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node3"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node4"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node4"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node1"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node2"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node4"), equalTo(0));
logger.info("Start primary on node4. Now all replicas for that primary start getting accounted for from node4.");
clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).stream().filter(routing -> routing.primary() && routing.isRelocationTarget()).collect(Collectors.toList()));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(UNASSIGNED).size(), equalTo(0));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).size(), equalTo(4));
assertThat(clusterState.routingTable().index("new_index").shardsWithState(RELOCATING).size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getIncomingRecoveries("node4"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node1"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node2"), equalTo(1));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node3"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialIncomingRecoveries("node4"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node2"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getOutgoingRecoveries("node4"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node1"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node2"), equalTo(2));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node3"), equalTo(0));
assertThat(clusterState.getRoutingNodes().getInitialOutgoingRecoveries("node4"), equalTo(2));
}
Aggregations