Search in sources :

Example 1 with AllocationDeciders

use of org.opensearch.cluster.routing.allocation.decider.AllocationDeciders in project OpenSearch by opensearch-project.

the class TransportResizeActionTests method testPassNumRoutingShardsAndFail.

public void testPassNumRoutingShardsAndFail() {
    int numShards = randomIntBetween(2, 100);
    ClusterState clusterState = ClusterState.builder(createClusterState("source", numShards, 0, numShards * 4, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(new AllocationDeciders(Collections.singleton(new MaxRetryAllocationDecider())), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = OpenSearchAllocationTestCase.startInitializingShardsAndReroute(service, clusterState, "source").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    ResizeRequest resizeRequest = new ResizeRequest("target", "source");
    resizeRequest.setResizeType(ResizeType.SPLIT);
    resizeRequest.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", numShards * 2).build());
    TransportResizeAction.prepareCreateIndexRequest(resizeRequest, clusterState, null, "source", "target");
    resizeRequest.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", numShards * 2).put("index.number_of_routing_shards", numShards * 2).build());
    ClusterState finalState = clusterState;
    IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> TransportResizeAction.prepareCreateIndexRequest(resizeRequest, finalState, null, "source", "target"));
    assertEquals("cannot provide index.number_of_routing_shards on resize", iae.getMessage());
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) RoutingTable(org.opensearch.cluster.routing.RoutingTable) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService)

Example 2 with AllocationDeciders

use of org.opensearch.cluster.routing.allocation.decider.AllocationDeciders in project OpenSearch by opensearch-project.

the class TransportResizeActionTests method testPassNumRoutingShards.

public void testPassNumRoutingShards() {
    ClusterState clusterState = ClusterState.builder(createClusterState("source", 1, 0, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(new AllocationDeciders(Collections.singleton(new MaxRetryAllocationDecider())), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = OpenSearchAllocationTestCase.startInitializingShardsAndReroute(service, clusterState, "source").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    ResizeRequest resizeRequest = new ResizeRequest("target", "source");
    resizeRequest.setResizeType(ResizeType.SPLIT);
    resizeRequest.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", 2).build());
    TransportResizeAction.prepareCreateIndexRequest(resizeRequest, clusterState, null, "source", "target");
    resizeRequest.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_routing_shards", randomIntBetween(2, 10)).put("index.number_of_shards", 2).build());
    TransportResizeAction.prepareCreateIndexRequest(resizeRequest, clusterState, null, "source", "target");
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) RoutingTable(org.opensearch.cluster.routing.RoutingTable) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService)

Example 3 with AllocationDeciders

use of org.opensearch.cluster.routing.allocation.decider.AllocationDeciders in project OpenSearch by opensearch-project.

the class BalancedSingleShardTests method testRebalanceNotAllowedDuringPendingAsyncFetch.

public void testRebalanceNotAllowedDuringPendingAsyncFetch() {
    BalancedShardsAllocator allocator = new BalancedShardsAllocator(Settings.EMPTY);
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), ShardRoutingState.STARTED);
    ShardRouting shard = clusterState.routingTable().index("idx").shard(0).primaryShard();
    RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(Collections.emptyList()), clusterState);
    routingAllocation.setHasPendingAsyncFetch();
    MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
    assertNotNull(rebalanceDecision.getClusterRebalanceDecision());
    assertEquals(AllocationDecision.AWAITING_INFO, rebalanceDecision.getAllocationDecision());
    assertThat(rebalanceDecision.getExplanation(), startsWith("cannot rebalance as information about existing copies of this shard in the cluster is still being gathered"));
    assertEquals(clusterState.nodes().getSize() - 1, rebalanceDecision.getNodeDecisions().size());
    assertNull(rebalanceDecision.getTargetNode());
    assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Example 4 with AllocationDeciders

use of org.opensearch.cluster.routing.allocation.decider.AllocationDeciders in project OpenSearch by opensearch-project.

the class AllocationServiceTests method testExplainsNonAllocationOfShardWithUnknownAllocator.

public void testExplainsNonAllocationOfShardWithUnknownAllocator() {
    final AllocationService allocationService = new AllocationService(null, null, null, null);
    allocationService.setExistingShardsAllocators(Collections.singletonMap(GatewayAllocator.ALLOCATOR_NAME, new TestGatewayAllocator()));
    final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder();
    nodesBuilder.add(new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT));
    nodesBuilder.add(new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT));
    final Metadata.Builder metadata = Metadata.builder().put(indexMetadata("index", Settings.builder().put(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey(), "unknown")));
    final RoutingTable.Builder routingTableBuilder = RoutingTable.builder().addAsRecovery(metadata.get("index"));
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(nodesBuilder).metadata(metadata).routingTable(routingTableBuilder.build()).build();
    final RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), clusterState.getRoutingNodes(), clusterState, ClusterInfo.EMPTY, null, 0L);
    allocation.setDebugMode(randomBoolean() ? RoutingAllocation.DebugMode.ON : RoutingAllocation.DebugMode.EXCLUDE_YES_DECISIONS);
    final ShardAllocationDecision shardAllocationDecision = allocationService.explainShardAllocation(clusterState.routingTable().index("index").shard(0).primaryShard(), allocation);
    assertTrue(shardAllocationDecision.isDecisionTaken());
    assertThat(shardAllocationDecision.getAllocateDecision().getAllocationStatus(), equalTo(UnassignedInfo.AllocationStatus.NO_VALID_SHARD_COPY));
    assertThat(shardAllocationDecision.getAllocateDecision().getAllocationDecision(), equalTo(AllocationDecision.NO_VALID_SHARD_COPY));
    assertThat(shardAllocationDecision.getAllocateDecision().getExplanation(), equalTo("cannot allocate because a previous copy of " + "the primary shard existed but can no longer be found on the nodes in the cluster"));
    for (NodeAllocationResult nodeAllocationResult : shardAllocationDecision.getAllocateDecision().nodeDecisions) {
        assertThat(nodeAllocationResult.getNodeDecision(), equalTo(AllocationDecision.NO));
        assertThat(nodeAllocationResult.getCanAllocateDecision().type(), equalTo(Decision.Type.NO));
        assertThat(nodeAllocationResult.getCanAllocateDecision().label(), equalTo("allocator_plugin"));
        assertThat(nodeAllocationResult.getCanAllocateDecision().getExplanation(), equalTo("finding the previous copies of this " + "shard requires an allocator called [unknown] but that allocator was not found; perhaps the corresponding plugin is " + "not installed"));
    }
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) RoutingTable(org.opensearch.cluster.routing.RoutingTable) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 5 with AllocationDeciders

use of org.opensearch.cluster.routing.allocation.decider.AllocationDeciders in project OpenSearch by opensearch-project.

the class MetadataCreateIndexServiceTests method runPrepareResizeIndexSettingsTest.

private void runPrepareResizeIndexSettingsTest(final Settings sourceSettings, final Settings requestSettings, final Collection<Setting<?>> additionalIndexScopedSettings, final boolean copySettings, final Consumer<Settings> consumer) {
    final String indexName = randomAlphaOfLength(10);
    final Settings indexSettings = Settings.builder().put("index.blocks.write", true).put("index.routing.allocation.require._name", "node1").put(sourceSettings).build();
    final ClusterState initialClusterState = ClusterState.builder(createClusterState(indexName, randomIntBetween(2, 10), 0, indexSettings)).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    final AllocationService service = new AllocationService(new AllocationDeciders(singleton(new MaxRetryAllocationDecider())), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE);
    final RoutingTable initialRoutingTable = service.reroute(initialClusterState, "reroute").routingTable();
    final ClusterState routingTableClusterState = ClusterState.builder(initialClusterState).routingTable(initialRoutingTable).build();
    // now we start the shard
    final RoutingTable routingTable = OpenSearchAllocationTestCase.startInitializingShardsAndReroute(service, routingTableClusterState, indexName).routingTable();
    final ClusterState clusterState = ClusterState.builder(routingTableClusterState).routingTable(routingTable).build();
    final Settings.Builder indexSettingsBuilder = Settings.builder().put("index.number_of_shards", 1).put(requestSettings);
    final Set<Setting<?>> settingsSet = Stream.concat(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS.stream(), additionalIndexScopedSettings.stream()).collect(Collectors.toSet());
    MetadataCreateIndexService.prepareResizeIndexSettings(clusterState, indexSettingsBuilder, clusterState.metadata().index(indexName).getIndex(), "target", ResizeType.SHRINK, copySettings, new IndexScopedSettings(Settings.EMPTY, settingsSet));
    consumer.accept(indexSettingsBuilder.build());
}
Also used : TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) ClusterState(org.opensearch.cluster.ClusterState) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) Setting(org.opensearch.common.settings.Setting) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) RoutingTable(org.opensearch.cluster.routing.RoutingTable) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) MetadataCreateIndexService.aggregateIndexSettings(org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings) IndexSettings(org.opensearch.index.IndexSettings) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService)

Aggregations

AllocationDeciders (org.opensearch.cluster.routing.allocation.decider.AllocationDeciders)28 ClusterState (org.opensearch.cluster.ClusterState)22 BalancedShardsAllocator (org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)18 TestGatewayAllocator (org.opensearch.test.gateway.TestGatewayAllocator)15 RoutingTable (org.opensearch.cluster.routing.RoutingTable)14 ShardRouting (org.opensearch.cluster.routing.ShardRouting)13 AllocationService (org.opensearch.cluster.routing.allocation.AllocationService)10 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)8 Metadata (org.opensearch.cluster.metadata.Metadata)8 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)8 MaxRetryAllocationDecider (org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider)8 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)6 Settings (org.opensearch.common.settings.Settings)6 RoutingNode (org.opensearch.cluster.routing.RoutingNode)5 AllocationDecider (org.opensearch.cluster.routing.allocation.decider.AllocationDecider)5 SameShardAllocationDecider (org.opensearch.cluster.routing.allocation.decider.SameShardAllocationDecider)5 ClusterSettings (org.opensearch.common.settings.ClusterSettings)5 HashSet (java.util.HashSet)4 RoutingAllocation (org.opensearch.cluster.routing.allocation.RoutingAllocation)4 Index (org.opensearch.index.Index)4