Search in sources :

Example 1 with MaxRetryAllocationDecider

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

the class ClusterModule method createAllocationDeciders.

// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/**
 * Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins.
 */
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
    // collect deciders by class so that we can detect duplicates
    Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
    addAllocationDecider(deciders, new MaxRetryAllocationDecider());
    addAllocationDecider(deciders, new ResizeAllocationDecider());
    addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider());
    addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider());
    addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ConcurrentRecoveriesAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new NodeVersionAllocationDecider());
    addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider());
    addAllocationDecider(deciders, new RestoreInProgressAllocationDecider());
    addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new NodeLoadAwareAllocationDecider(settings, clusterSettings));
    clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
    return deciders.values();
}
Also used : IndexGraveyard(org.opensearch.cluster.metadata.IndexGraveyard) NamedWriteable(org.opensearch.common.io.stream.NamedWriteable) Metadata(org.opensearch.cluster.metadata.Metadata) EnableAllocationDecider(org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider) MetadataDeleteIndexService(org.opensearch.cluster.metadata.MetadataDeleteIndexService) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) ClusterRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) SnapshotInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) ThrottlingAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ComponentTemplateMetadata(org.opensearch.cluster.metadata.ComponentTemplateMetadata) DelayedAllocationService(org.opensearch.cluster.routing.DelayedAllocationService) AllocationDecider(org.opensearch.cluster.routing.allocation.decider.AllocationDecider) ComposableIndexTemplateMetadata(org.opensearch.cluster.metadata.ComposableIndexTemplateMetadata) Property(org.opensearch.common.settings.Setting.Property) Map(java.util.Map) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) ShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.ShardsAllocator) TaskResultsService(org.opensearch.tasks.TaskResultsService) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) DiskThresholdDecider(org.opensearch.cluster.routing.allocation.decider.DiskThresholdDecider) ResizeAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider) SameShardAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ClusterPlugin(org.opensearch.plugins.ClusterPlugin) AwarenessAllocationDecider(org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) Collection(java.util.Collection) PersistentTasksCustomMetadata(org.opensearch.persistent.PersistentTasksCustomMetadata) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) PersistentTasksNodeService(org.opensearch.persistent.PersistentTasksNodeService) Objects(java.util.Objects) List(java.util.List) DataStreamMetadata(org.opensearch.cluster.metadata.DataStreamMetadata) ExistingShardsAllocator(org.opensearch.cluster.routing.allocation.ExistingShardsAllocator) GatewayAllocator(org.opensearch.gateway.GatewayAllocator) Reader(org.opensearch.common.io.stream.Writeable.Reader) ScriptMetadata(org.opensearch.script.ScriptMetadata) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) SnapshotsInfoService(org.opensearch.snapshots.SnapshotsInfoService) RestoreInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDecider) ConcurrentRecoveriesAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRecoveriesAllocationDecider) MetadataIndexAliasesService(org.opensearch.cluster.metadata.MetadataIndexAliasesService) MetadataUpdateSettingsService(org.opensearch.cluster.metadata.MetadataUpdateSettingsService) HashMap(java.util.HashMap) ParseField(org.opensearch.common.ParseField) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) MappingUpdatedAction(org.opensearch.cluster.action.index.MappingUpdatedAction) NodeVersionAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) LinkedHashMap(java.util.LinkedHashMap) ShardsLimitAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) MetadataMappingService(org.opensearch.cluster.metadata.MetadataMappingService) AbstractModule(org.opensearch.common.inject.AbstractModule) NodeMappingRefreshAction(org.opensearch.cluster.action.index.NodeMappingRefreshAction) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ReplicaAfterPrimaryActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) MetadataIndexStateService(org.opensearch.cluster.metadata.MetadataIndexStateService) RebalanceOnlyWhenActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) IngestMetadata(org.opensearch.ingest.IngestMetadata) FilterAllocationDecider(org.opensearch.cluster.routing.allocation.decider.FilterAllocationDecider) MetadataIndexTemplateService(org.opensearch.cluster.metadata.MetadataIndexTemplateService) Setting(org.opensearch.common.settings.Setting) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) Sets(org.opensearch.common.util.set.Sets) ConcurrentRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) NodeLoadAwareAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeLoadAwareAllocationDecider) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterService(org.opensearch.cluster.service.ClusterService) Collections(java.util.Collections) ResizeAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider) SnapshotInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) EnableAllocationDecider(org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider) NodeLoadAwareAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeLoadAwareAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) ThrottlingAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) ConcurrentRecoveriesAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRecoveriesAllocationDecider) LinkedHashMap(java.util.LinkedHashMap) ClusterRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) SameShardAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SameShardAllocationDecider) RestoreInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDecider) FilterAllocationDecider(org.opensearch.cluster.routing.allocation.decider.FilterAllocationDecider) DiskThresholdDecider(org.opensearch.cluster.routing.allocation.decider.DiskThresholdDecider) ShardsLimitAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) AwarenessAllocationDecider(org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) NodeVersionAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) EnableAllocationDecider(org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider) ClusterRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) SnapshotInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) ThrottlingAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) AllocationDecider(org.opensearch.cluster.routing.allocation.decider.AllocationDecider) ResizeAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider) SameShardAllocationDecider(org.opensearch.cluster.routing.allocation.decider.SameShardAllocationDecider) AwarenessAllocationDecider(org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) RestoreInProgressAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDecider) ConcurrentRecoveriesAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRecoveriesAllocationDecider) NodeVersionAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) ShardsLimitAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.opensearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) FilterAllocationDecider(org.opensearch.cluster.routing.allocation.decider.FilterAllocationDecider) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ConcurrentRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) NodeLoadAwareAllocationDecider(org.opensearch.cluster.routing.allocation.decider.NodeLoadAwareAllocationDecider) ConcurrentRebalanceAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider)

Example 2 with MaxRetryAllocationDecider

use of org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider 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 3 with MaxRetryAllocationDecider

use of org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider 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 4 with MaxRetryAllocationDecider

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

the class MaxRetryAllocationDeciderTests method testFailedAllocation.

public void testFailedAllocation() {
    ClusterState clusterState = createInitialClusterState();
    RoutingTable routingTable = clusterState.routingTable();
    final int retries = MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY.get(Settings.EMPTY);
    // now fail it N-1 times
    for (int i = 0; i < retries - 1; i++) {
        List<FailedShard> failedShards = Collections.singletonList(new FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i, new UnsupportedOperationException(), randomBoolean()));
        ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
        assertThat(newState, not(equalTo(clusterState)));
        clusterState = newState;
        routingTable = newState.routingTable();
        assertEquals(routingTable.index("idx").shards().size(), 1);
        ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
        assertEquals(unassignedPrimary.state(), INITIALIZING);
        assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), i + 1);
        assertThat(unassignedPrimary.unassignedInfo().getMessage(), containsString("boom" + i));
        // MaxRetryAllocationDecider#canForceAllocatePrimary should return YES decisions because canAllocate returns YES here
        assertEquals(Decision.YES, new MaxRetryAllocationDecider().canForceAllocatePrimary(unassignedPrimary, null, new RoutingAllocation(null, null, clusterState, null, null, 0)));
    }
    // now we go and check that we are actually stick to unassigned on the next failure
    {
        List<FailedShard> failedShards = Collections.singletonList(new FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom", new UnsupportedOperationException(), randomBoolean()));
        ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
        assertThat(newState, not(equalTo(clusterState)));
        clusterState = newState;
        routingTable = newState.routingTable();
        assertEquals(routingTable.index("idx").shards().size(), 1);
        ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
        assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), retries);
        assertEquals(unassignedPrimary.state(), UNASSIGNED);
        assertThat(unassignedPrimary.unassignedInfo().getMessage(), containsString("boom"));
        // MaxRetryAllocationDecider#canForceAllocatePrimary should return a NO decision because canAllocate returns NO here
        assertEquals(Decision.NO, new MaxRetryAllocationDecider().canForceAllocatePrimary(unassignedPrimary, null, new RoutingAllocation(null, null, clusterState, null, null, 0)));
    }
    // change the settings and ensure we can do another round of allocation for that index.
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(Metadata.builder(clusterState.metadata()).put(IndexMetadata.builder(clusterState.metadata().index("idx")).settings(Settings.builder().put(clusterState.metadata().index("idx").getSettings()).put("index.allocation.max_retries", retries + 1).build()).build(), true).build()).build();
    ClusterState newState = strategy.reroute(clusterState, "settings changed");
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingTable = newState.routingTable();
    // good we are initializing and we are maintaining failure information
    assertEquals(routingTable.index("idx").shards().size(), 1);
    ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
    assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), retries);
    assertEquals(unassignedPrimary.state(), INITIALIZING);
    assertThat(unassignedPrimary.unassignedInfo().getMessage(), containsString("boom"));
    // bumped up the max retry count, so canForceAllocatePrimary should return a YES decision
    assertEquals(Decision.YES, new MaxRetryAllocationDecider().canForceAllocatePrimary(routingTable.index("idx").shard(0).shards().get(0), null, new RoutingAllocation(null, null, clusterState, null, null, 0)));
    // now we start the shard
    clusterState = startShardsAndReroute(strategy, clusterState, routingTable.index("idx").shard(0).shards().get(0));
    routingTable = clusterState.routingTable();
    // all counters have been reset to 0 ie. no unassigned info
    assertEquals(routingTable.index("idx").shards().size(), 1);
    assertNull(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo());
    assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), STARTED);
    // now fail again and see if it has a new counter
    List<FailedShard> failedShards = Collections.singletonList(new FailedShard(routingTable.index("idx").shard(0).shards().get(0), "ZOOOMG", new UnsupportedOperationException(), randomBoolean()));
    newState = strategy.applyFailedShards(clusterState, failedShards);
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingTable = newState.routingTable();
    assertEquals(routingTable.index("idx").shards().size(), 1);
    unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
    assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), 1);
    assertEquals(unassignedPrimary.state(), UNASSIGNED);
    assertThat(unassignedPrimary.unassignedInfo().getMessage(), containsString("ZOOOMG"));
    // Counter reset, so MaxRetryAllocationDecider#canForceAllocatePrimary should return a YES decision
    assertEquals(Decision.YES, new MaxRetryAllocationDecider().canForceAllocatePrimary(unassignedPrimary, null, new RoutingAllocation(null, null, clusterState, null, null, 0)));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) RoutingTable(org.opensearch.cluster.routing.RoutingTable) List(java.util.List) ShardRouting(org.opensearch.cluster.routing.ShardRouting) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider)

Example 5 with MaxRetryAllocationDecider

use of org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider 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

MaxRetryAllocationDecider (org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider)10 ClusterState (org.opensearch.cluster.ClusterState)9 RoutingTable (org.opensearch.cluster.routing.RoutingTable)9 AllocationService (org.opensearch.cluster.routing.allocation.AllocationService)9 BalancedShardsAllocator (org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)9 AllocationDeciders (org.opensearch.cluster.routing.allocation.decider.AllocationDeciders)9 TestGatewayAllocator (org.opensearch.test.gateway.TestGatewayAllocator)8 Settings (org.opensearch.common.settings.Settings)5 MetadataCreateIndexService.aggregateIndexSettings (org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings)3 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)3 IndexSettings (org.opensearch.index.IndexSettings)3 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 CreateIndexClusterStateUpdateRequest (org.opensearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest)2 ActiveShardCount (org.opensearch.action.support.ActiveShardCount)2 Metadata (org.opensearch.cluster.metadata.Metadata)2 Setting (org.opensearch.common.settings.Setting)2 DocsStats (org.opensearch.index.shard.DocsStats)2 IOException (java.io.IOException)1