Search in sources :

Example 11 with AllocationDeciders

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders in project elasticsearch by elastic.

the class ClusterModule method configure.

@Override
protected void configure() {
    bind(GatewayAllocator.class).asEagerSingleton();
    bind(AllocationService.class).asEagerSingleton();
    bind(ClusterService.class).toInstance(clusterService);
    bind(NodeConnectionsService.class).asEagerSingleton();
    bind(MetaDataCreateIndexService.class).asEagerSingleton();
    bind(MetaDataDeleteIndexService.class).asEagerSingleton();
    bind(MetaDataIndexStateService.class).asEagerSingleton();
    bind(MetaDataMappingService.class).asEagerSingleton();
    bind(MetaDataIndexAliasesService.class).asEagerSingleton();
    bind(MetaDataUpdateSettingsService.class).asEagerSingleton();
    bind(MetaDataIndexTemplateService.class).asEagerSingleton();
    bind(IndexNameExpressionResolver.class).toInstance(indexNameExpressionResolver);
    bind(RoutingService.class).asEagerSingleton();
    bind(DelayedAllocationService.class).asEagerSingleton();
    bind(ShardStateAction.class).asEagerSingleton();
    bind(NodeMappingRefreshAction.class).asEagerSingleton();
    bind(MappingUpdatedAction.class).asEagerSingleton();
    bind(TaskResultsService.class).asEagerSingleton();
    bind(AllocationDeciders.class).toInstance(new AllocationDeciders(settings, allocationDeciders));
    bind(ShardsAllocator.class).toInstance(shardsAllocator);
}
Also used : GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) MetaDataUpdateSettingsService(org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService) RoutingService(org.elasticsearch.cluster.routing.RoutingService) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) MetaDataCreateIndexService(org.elasticsearch.cluster.metadata.MetaDataCreateIndexService) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) NodeMappingRefreshAction(org.elasticsearch.cluster.action.index.NodeMappingRefreshAction) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) ShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator) MetaDataIndexAliasesService(org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ClusterService(org.elasticsearch.cluster.service.ClusterService) MetaDataMappingService(org.elasticsearch.cluster.metadata.MetaDataMappingService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) MetaDataDeleteIndexService(org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) MetaDataIndexStateService(org.elasticsearch.cluster.metadata.MetaDataIndexStateService) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService)

Example 12 with AllocationDeciders

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders in project elasticsearch by elastic.

the class TransportShrinkActionTests method testErrorCondition.

public void testErrorCondition() {
    ClusterState state = createClusterState("source", randomIntBetween(2, 42), randomIntBetween(0, 10), Settings.builder().put("index.blocks.write", true).build());
    assertTrue(expectThrows(IllegalStateException.class, () -> TransportShrinkAction.prepareCreateIndexRequest(new ShrinkRequest("target", "source"), state, (i) -> new DocsStats(Integer.MAX_VALUE, randomIntBetween(1, 1000)), new IndexNameExpressionResolver(Settings.EMPTY))).getMessage().startsWith("Can't merge index with more than [2147483519] docs - too many documents in shards "));
    assertTrue(expectThrows(IllegalStateException.class, () -> {
        ShrinkRequest req = new ShrinkRequest("target", "source");
        req.getShrinkIndexRequest().settings(Settings.builder().put("index.number_of_shards", 4));
        ClusterState clusterState = createClusterState("source", 8, 1, Settings.builder().put("index.blocks.write", true).build());
        TransportShrinkAction.prepareCreateIndexRequest(req, clusterState, (i) -> i == 2 || i == 3 ? new DocsStats(Integer.MAX_VALUE / 2, randomIntBetween(1, 1000)) : null, new IndexNameExpressionResolver(Settings.EMPTY));
    }).getMessage().startsWith("Can't merge index with more than [2147483519] docs - too many documents in shards "));
    // create one that won't fail
    ClusterState clusterState = ClusterState.builder(createClusterState("source", randomIntBetween(2, 10), 0, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY, Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = service.applyStartedShards(clusterState, routingTable.index("source").shardsWithState(ShardRoutingState.INITIALIZING)).routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    TransportShrinkAction.prepareCreateIndexRequest(new ShrinkRequest("target", "source"), clusterState, (i) -> new DocsStats(randomIntBetween(1, 1000), randomIntBetween(1, 1000)), new IndexNameExpressionResolver(Settings.EMPTY));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) Arrays(java.util.Arrays) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) EmptyClusterInfoService(org.elasticsearch.cluster.EmptyClusterInfoService) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) CreateIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) IndexWriter(org.apache.lucene.index.IndexWriter) Version(org.elasticsearch.Version) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Collections(java.util.Collections) TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 13 with AllocationDeciders

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders in project elasticsearch by elastic.

the class TransportShrinkActionTests method testShrinkIndexSettings.

public void testShrinkIndexSettings() {
    String indexName = randomAsciiOfLength(10);
    // create one that won't fail
    ClusterState clusterState = ClusterState.builder(createClusterState(indexName, randomIntBetween(2, 10), 0, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY, Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = service.applyStartedShards(clusterState, routingTable.index(indexName).shardsWithState(ShardRoutingState.INITIALIZING)).routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    int numSourceShards = clusterState.metaData().index(indexName).getNumberOfShards();
    DocsStats stats = new DocsStats(randomIntBetween(0, (IndexWriter.MAX_DOCS) / numSourceShards), randomIntBetween(1, 1000));
    ShrinkRequest target = new ShrinkRequest("target", indexName);
    final ActiveShardCount activeShardCount = randomBoolean() ? ActiveShardCount.ALL : ActiveShardCount.ONE;
    target.setWaitForActiveShards(activeShardCount);
    CreateIndexClusterStateUpdateRequest request = TransportShrinkAction.prepareCreateIndexRequest(target, clusterState, (i) -> stats, new IndexNameExpressionResolver(Settings.EMPTY));
    assertNotNull(request.shrinkFrom());
    assertEquals(indexName, request.shrinkFrom().getName());
    assertEquals("1", request.settings().get("index.number_of_shards"));
    assertEquals("shrink_index", request.cause());
    assertEquals(request.waitForActiveShards(), activeShardCount);
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) CreateIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 14 with AllocationDeciders

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders in project elasticsearch by elastic.

the class BalancedSingleShardTests method setupStateAndRebalance.

private Tuple<ClusterState, MoveDecision> setupStateAndRebalance(AllocationDecider allocationDecider, Settings balancerSettings, boolean rebalanceExpected) {
    AllocationDecider rebalanceDecider = new AllocationDecider(Settings.EMPTY) {

        @Override
        public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
            return Decision.YES;
        }
    };
    List<AllocationDecider> allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider);
    final int numShards = randomIntBetween(8, 13);
    BalancedShardsAllocator allocator = new BalancedShardsAllocator(balancerSettings);
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", 2, numShards);
    // add a new node so shards can be rebalanced there
    DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(clusterState.nodes());
    nodesBuilder.add(newNode(randomAsciiOfLength(7)));
    clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
    ShardRouting shard = clusterState.routingTable().index("idx").shard(0).primaryShard();
    RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(Settings.EMPTY, allocationDeciders), clusterState);
    MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
    if (rebalanceExpected == false) {
        assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);
    }
    return Tuple.tuple(clusterState, rebalanceDecision);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 15 with AllocationDeciders

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders in project elasticsearch by elastic.

the class BalancedSingleShardTests method testRebalancingNotAllowedDueToCanRebalance.

public void testRebalancingNotAllowedDueToCanRebalance() {
    final Decision canRebalanceDecision = randomFrom(Decision.NO, Decision.THROTTLE);
    AllocationDecider noRebalanceDecider = new AllocationDecider(Settings.EMPTY) {

        @Override
        public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
            return allocation.decision(canRebalanceDecision, "TEST", "foobar");
        }
    };
    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(Settings.EMPTY, Collections.singleton(noRebalanceDecider)), clusterState);
    MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
    assertEquals(canRebalanceDecision.type(), rebalanceDecision.getClusterRebalanceDecision().type());
    assertEquals(AllocationDecision.fromDecisionType(canRebalanceDecision.type()), rebalanceDecision.getAllocationDecision());
    assertThat(rebalanceDecision.getExplanation(), containsString(canRebalanceDecision.type() == Type.THROTTLE ? "rebalancing is throttled" : "rebalancing is not allowed"));
    assertNotNull(rebalanceDecision.getNodeDecisions());
    assertNull(rebalanceDecision.getTargetNode());
    assertEquals(1, rebalanceDecision.getClusterRebalanceDecision().getDecisions().size());
    for (Decision subDecision : rebalanceDecision.getClusterRebalanceDecision().getDecisions()) {
        assertEquals("foobar", ((Decision.Single) subDecision).getExplanation());
    }
    assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)

Aggregations

AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)23 ClusterState (org.elasticsearch.cluster.ClusterState)17 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)16 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)13 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)10 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)8 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)6 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)6 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)5 AllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)5 MaxRetryAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 MetaData (org.elasticsearch.cluster.metadata.MetaData)4 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)4 Decision (org.elasticsearch.cluster.routing.allocation.decider.Decision)4 SameShardAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider)4 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 HashSet (java.util.HashSet)3 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)3