当前位置: 首页>>代码示例>>Java>>正文


Java AllocationService.applyStartedShards方法代码示例

本文整理汇总了Java中org.elasticsearch.cluster.routing.allocation.AllocationService.applyStartedShards方法的典型用法代码示例。如果您正苦于以下问题:Java AllocationService.applyStartedShards方法的具体用法?Java AllocationService.applyStartedShards怎么用?Java AllocationService.applyStartedShards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.cluster.routing.allocation.AllocationService的用法示例。


在下文中一共展示了AllocationService.applyStartedShards方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNodeLeave

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
/**
 * Tests that during reroute when a node is detected as leaving the cluster, the right unassigned meta is set
 */
public void testNodeLeave() {
    AllocationService allocation = createAllocationService();
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
            .metaData(metaData)
            .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    // starting primaries
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // starting replicas
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
    // remove node2 and reroute
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
    clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
    // verify that NODE_LEAVE is the reason for meta
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo(), notNullValue());
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.NODE_LEFT));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getUnassignedTimeInMillis(), greaterThan(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:UnassignedInfoTests.java

示例2: startRandomInitializingShard

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
protected  static ClusterState startRandomInitializingShard(ClusterState clusterState, AllocationService strategy) {
    List<ShardRouting> initializingShards = clusterState.getRoutingNodes().shardsWithState(INITIALIZING);
    if (initializingShards.isEmpty()) {
        return clusterState;
    }
    return strategy.applyStartedShards(clusterState,
        arrayAsArrayList(initializingShards.get(randomInt(initializingShards.size() - 1))));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:ESAllocationTestCase.java

示例3: applyStartedShardsUntilNoChange

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
protected ClusterState applyStartedShardsUntilNoChange(ClusterState clusterState, AllocationService service) {
    ClusterState lastClusterState;
    do {
        lastClusterState = clusterState;
        logger.debug("ClusterState: {}", clusterState.getRoutingNodes());
        clusterState = service.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    } while (lastClusterState.equals(clusterState) == false);
    return clusterState;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ESAllocationTestCase.java

示例4: testFailedShard

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
/**
 * Verifies that when a shard fails, reason is properly set and details are preserved.
 */
public void testFailedShard() {
    AllocationService allocation = createAllocationService();
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
            .metaData(metaData)
            .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    // starting primaries
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // starting replicas
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
    // fail shard
    ShardRouting shardToFail = clusterState.getRoutingNodes().shardsWithState(STARTED).get(0);
    clusterState = allocation.applyFailedShards(clusterState, Collections.singletonList(new FailedShard(shardToFail, "test fail", null)));
    // verify the reason and details
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo(), notNullValue());
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.ALLOCATION_FAILED));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getMessage(), equalTo("test fail"));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getDetails(), equalTo("test fail"));
    assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).get(0).unassignedInfo().getUnassignedTimeInMillis(), greaterThan(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:UnassignedInfoTests.java

示例5: testIndexEnableNone

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
public void testIndexEnableNone() {
    AllocationService strategy = createAllocationService(Settings.builder()
            .build());

    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("disabled").settings(settings(Version.CURRENT)
                    .put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), Allocation.NONE.name()))
                    .numberOfShards(1).numberOfReplicas(1))
            .put(IndexMetaData.builder("enabled").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable initialRoutingTable = RoutingTable.builder()
            .addAsNew(metaData.index("disabled"))
            .addAsNew(metaData.index("enabled"))
            .build();

    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();

    logger.info("--> adding two nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
    logger.info("--> start the shards (primaries)");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    logger.info("--> start the shards (replicas)");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    logger.info("--> verify only enabled index has been routed");
    assertThat(clusterState.getRoutingNodes().shardsWithState("enabled", STARTED).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().shardsWithState("disabled", STARTED).size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:EnableAllocationTests.java

示例6: testAttributePreferenceRouting

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
public void testAttributePreferenceRouting() {
    AllocationService strategy = createAllocationService(Settings.builder()
            .put("cluster.routing.allocation.node_concurrent_recoveries", 10)
            .put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), "always")
            .put("cluster.routing.allocation.awareness.attributes", "rack_id,zone")
            .build());

    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();

    Map<String, String> node1Attributes = new HashMap<>();
    node1Attributes.put("rack_id", "rack_1");
    node1Attributes.put("zone", "zone1");
    Map<String, String> node2Attributes = new HashMap<>();
    node2Attributes.put("rack_id", "rack_2");
    node2Attributes.put("zone", "zone2");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1", unmodifiableMap(node1Attributes)))
            .add(newNode("node2", unmodifiableMap(node2Attributes)))
            .localNodeId("node1")
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    // after all are started, check routing iteration
    ShardIterator shardIterator = clusterState.routingTable().index("test").shard(0).preferAttributesActiveInitializingShardsIt(new String[]{"rack_id"}, clusterState.nodes());
    ShardRouting shardRouting = shardIterator.nextOrNull();
    assertThat(shardRouting, notNullValue());
    assertThat(shardRouting.currentNodeId(), equalTo("node1"));
    shardRouting = shardIterator.nextOrNull();
    assertThat(shardRouting, notNullValue());
    assertThat(shardRouting.currentNodeId(), equalTo("node2"));

    shardIterator = clusterState.routingTable().index("test").shard(0).preferAttributesActiveInitializingShardsIt(new String[]{"rack_id"}, clusterState.nodes());
    shardRouting = shardIterator.nextOrNull();
    assertThat(shardRouting, notNullValue());
    assertThat(shardRouting.currentNodeId(), equalTo("node1"));
    shardRouting = shardIterator.nextOrNull();
    assertThat(shardRouting, notNullValue());
    assertThat(shardRouting.currentNodeId(), equalTo("node2"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:52,代码来源:RoutingIteratorTests.java

示例7: testNodeSelectorRouting

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
public void testNodeSelectorRouting(){
    AllocationService strategy = createAllocationService(Settings.builder()
            .put("cluster.routing.allocation.node_concurrent_recoveries", 10)
            .put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), "always")
            .build());

    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                    .add(newNode("fred", "node1", singletonMap("disk", "ebs")))
                    .add(newNode("barney", "node2", singletonMap("disk", "ephemeral")))
                    .localNodeId("node1")
    ).build();

    clusterState = strategy.reroute(clusterState, "reroute");

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    ShardsIterator shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("disk:ebs",clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));

    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("dis*:eph*",clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node2"));

    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("fred",clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));

    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("bar*",clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node2"));

    shardsIterator = clusterState.routingTable().index("test").shard(0)
        .onlyNodeSelectorActiveInitializingShardsIt(new String[] {"disk:eph*","disk:ebs"},clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));

    shardsIterator = clusterState.routingTable().index("test").shard(0)
        .onlyNodeSelectorActiveInitializingShardsIt(new String[] {"disk:*", "invalid_name"},clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));

    shardsIterator = clusterState.routingTable().index("test").shard(0)
        .onlyNodeSelectorActiveInitializingShardsIt(new String[] {"disk:*", "disk:*"},clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));

    try {
        shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("welma", clusterState.nodes());
        fail("should have raised illegalArgumentException");
    } catch (IllegalArgumentException illegal) {
        //expected exception
    }

    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("fred",clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(),equalTo("node1"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:72,代码来源:RoutingIteratorTests.java

示例8: testReplicaShardPreferenceIters

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
public void testReplicaShardPreferenceIters() throws Exception {
    AllocationService strategy = createAllocationService(Settings.builder()
            .put("cluster.routing.allocation.node_concurrent_recoveries", 10)
            .build());

    OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY,
        ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));

    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(2))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                    .add(newNode("node1"))
                    .add(newNode("node2"))
                    .add(newNode("node3"))
                    .localNodeId("node1")
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    // When replicas haven't initialized, it comes back with the primary first, then initializing replicas
    GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
    assertThat(shardIterators.size(), equalTo(2)); // two potential shards
    ShardIterator iter = shardIterators.iterator().next();
    assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard
    ShardRouting routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertTrue(routing.primary()); // replicas haven't initialized yet, so primary is first
    assertTrue(routing.started());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    assertTrue(routing.initializing());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    assertTrue(routing.initializing());

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));

    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));


    shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica");
    assertThat(shardIterators.size(), equalTo(2)); // two potential shards
    iter = shardIterators.iterator().next();
    assertThat(iter.size(), equalTo(2)); // two potential replicas for the shard
    routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());

    shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
    assertThat(shardIterators.size(), equalTo(2)); // two potential shards
    iter = shardIterators.iterator().next();
    assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard
    routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    // finally the primary
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertTrue(routing.primary());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:81,代码来源:RoutingIteratorTests.java

示例9: testEnableClusterBalanceNoReplicas

import org.elasticsearch.cluster.routing.allocation.AllocationService; //导入方法依赖的package包/类
public void testEnableClusterBalanceNoReplicas() {
    final boolean useClusterSetting = randomBoolean();
    Settings build = Settings.builder()
            .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), useClusterSetting ? Rebalance.NONE: RandomPicks.randomFrom(random(), Rebalance.values())) // index settings override cluster settings
            .put(ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING.getKey(), 3)
            .build();
    ClusterSettings clusterSettings = new ClusterSettings(build, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AllocationService strategy = createAllocationService(build, clusterSettings, random());
    Settings indexSettings = useClusterSetting ? Settings.EMPTY : Settings.builder().put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), Rebalance.NONE).build();

    logger.info("Building initial routing table");
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT).put(indexSettings)).numberOfShards(6).numberOfReplicas(0))
            .build();

    RoutingTable initialRoutingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(6));
    logger.info("--> start the shards (primaries)");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
            .add(newNode("node3"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(0));
    metaData = clusterState.metaData();
    if (useClusterSetting) {
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).transientSettings(Settings.builder()
                .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL)
                .build())).build();
    } else {
        IndexMetaData meta = clusterState.getMetaData().index("test");
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).removeAllIndices()
                .put(IndexMetaData.builder(meta).settings(Settings.builder().put(meta.getSettings()).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL).build()))).build();
    }
    clusterSettings.applySettings(clusterState.metaData().settings());
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat("expected 4 primaries to be started and 2 to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
    assertThat("expected 2 primaries to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(2));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:EnableAllocationTests.java


注:本文中的org.elasticsearch.cluster.routing.allocation.AllocationService.applyStartedShards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。