Search in sources :

Example 1 with RELOCATING

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));
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) INITIALIZING(org.opensearch.cluster.routing.ShardRoutingState.INITIALIZING) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) SnapshotRecoverySource(org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource) Version(org.opensearch.Version) ThrottlingAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MoveAllocationCommand(org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand) CLUSTER_NAME_SETTING(org.opensearch.cluster.ClusterName.CLUSTER_NAME_SETTING) ArrayList(java.util.ArrayList) RecoverySource(org.opensearch.cluster.routing.RecoverySource) HashSet(java.util.HashSet) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexId(org.opensearch.repositories.IndexId) STARTED(org.opensearch.cluster.routing.ShardRoutingState.STARTED) OpenSearchAllocationTestCase(org.opensearch.cluster.OpenSearchAllocationTestCase) SnapshotShardSizeInfo(org.opensearch.snapshots.SnapshotShardSizeInfo) UUIDs(org.opensearch.common.UUIDs) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) Decision(org.opensearch.cluster.routing.allocation.decider.Decision) TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) AllocationCommands(org.opensearch.cluster.routing.allocation.command.AllocationCommands) Index(org.opensearch.index.Index) SnapshotId(org.opensearch.snapshots.SnapshotId) IntHashSet(com.carrotsearch.hppc.IntHashSet) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) Collectors(java.util.stream.Collectors) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) InternalSnapshotsInfoService(org.opensearch.snapshots.InternalSnapshotsInfoService) RELOCATING(org.opensearch.cluster.routing.ShardRoutingState.RELOCATING) Logger(org.apache.logging.log4j.Logger) Snapshot(org.opensearch.snapshots.Snapshot) UNASSIGNED(org.opensearch.cluster.routing.ShardRoutingState.UNASSIGNED) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RestoreInProgress(org.opensearch.cluster.RestoreInProgress) RoutingTable(org.opensearch.cluster.routing.RoutingTable) ShardRoutingHelper(org.opensearch.cluster.routing.ShardRoutingHelper) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) SnapshotsInfoService(org.opensearch.snapshots.SnapshotsInfoService) ClusterState(org.opensearch.cluster.ClusterState) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Settings(org.opensearch.common.settings.Settings)

Aggregations

IntHashSet (com.carrotsearch.hppc.IntHashSet)1 ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Version (org.opensearch.Version)1 CLUSTER_NAME_SETTING (org.opensearch.cluster.ClusterName.CLUSTER_NAME_SETTING)1 ClusterState (org.opensearch.cluster.ClusterState)1 OpenSearchAllocationTestCase (org.opensearch.cluster.OpenSearchAllocationTestCase)1 RestoreInProgress (org.opensearch.cluster.RestoreInProgress)1 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)1 Metadata (org.opensearch.cluster.metadata.Metadata)1 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)1 IndexRoutingTable (org.opensearch.cluster.routing.IndexRoutingTable)1