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


Java ClusterState.getRoutingNodes方法代码示例

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


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

示例1: stabilize

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState stabilize(ClusterState clusterState, AllocationService service) {
    logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes());

    clusterState = service.deassociateDeadNodes(clusterState, true, "reroute");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    assertRecoveryNodeVersions(routingNodes);

    logger.info("complete rebalancing");
    boolean changed;
    do {
        logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes());
        ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
        changed = newState.equals(clusterState) == false;
        clusterState = newState;
        routingNodes = clusterState.getRoutingNodes();
        assertRecoveryNodeVersions(routingNodes);
    } while (changed);
    return clusterState;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:NodeVersionAllocationDeciderTests.java

示例2: addIndex

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState addIndex(ClusterState clusterState, AllocationService service, int indexOrdinal, int numberOfShards,
                              int numberOfReplicas) {
    MetaData.Builder metaDataBuilder = MetaData.builder(clusterState.getMetaData());
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder(clusterState.routingTable());

    IndexMetaData.Builder index = IndexMetaData.builder("test" + indexOrdinal).settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(
            numberOfReplicas);
    IndexMetaData imd = index.build();
    metaDataBuilder = metaDataBuilder.put(imd, true);
    routingTableBuilder.addAsNew(imd);

    MetaData metaData = metaDataBuilder.build();
    clusterState = ClusterState.builder(clusterState).metaData(metaData).routingTable(routingTableBuilder.build()).build();
    clusterState = service.reroute(clusterState, "reroute");

    logger.info("restart all the primary shards, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("start the replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("complete rebalancing");
    return applyStartedShardsUntilNoChange(clusterState, service);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:AddIncrementallyTests.java

示例3: initCluster

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState initCluster(AllocationService service, int numberOfNodes, int numberOfIndices, int numberOfShards,
                                 int numberOfReplicas) {
    MetaData.Builder metaDataBuilder = MetaData.builder();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();

    for (int i = 0; i < numberOfIndices; i++) {
        IndexMetaData.Builder index = IndexMetaData.builder("test" + i).settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(
                numberOfReplicas);
        metaDataBuilder = metaDataBuilder.put(index);
    }

    MetaData metaData = metaDataBuilder.build();

    for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
        routingTableBuilder.addAsNew(cursor.value);
    }

    RoutingTable initialRoutingTable = routingTableBuilder.build();

    logger.info("start {} nodes", numberOfNodes);
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder();
    for (int i = 0; i < numberOfNodes; i++) {
        nodes.add(newNode("node" + i));
    }
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
    clusterState = service.reroute(clusterState, "reroute");

    logger.info("restart all the primary shards, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("start the replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    routingNodes = clusterState.getRoutingNodes();

    logger.info("complete rebalancing");
    return applyStartedShardsUntilNoChange(clusterState, service);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:AddIncrementallyTests.java

示例4: masterOperation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
protected void masterOperation(final ClusterAllocationExplainRequest request, final ClusterState state,
                               final ActionListener<ClusterAllocationExplainResponse> listener) {
    final RoutingNodes routingNodes = state.getRoutingNodes();
    final ClusterInfo clusterInfo = clusterInfoService.getClusterInfo();
    final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, state,
            clusterInfo, System.nanoTime(), false);

    ShardRouting shardRouting = findShardToExplain(request, allocation);
    logger.debug("explaining the allocation for [{}], found shard [{}]", request, shardRouting);

    ClusterAllocationExplanation cae = explainShard(shardRouting, allocation,
        request.includeDiskInfo() ? clusterInfo : null, request.includeYesDecisions(), gatewayAllocator, shardAllocator);
    listener.onResponse(new ClusterAllocationExplainResponse(cae));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:TransportClusterAllocationExplainAction.java

示例5: initCluster

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState initCluster(AllocationService strategy) {
    MetaData.Builder metaDataBuilder = MetaData.builder();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();

    for (int i = 0; i < numberOfIndices; i++) {
        IndexMetaData.Builder index = IndexMetaData.builder("test" + i).settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas);
        metaDataBuilder = metaDataBuilder.put(index);
    }

    MetaData metaData = metaDataBuilder.build();

    for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
        routingTableBuilder.addAsNew(cursor.value);
    }

    RoutingTable initialRoutingTable = routingTableBuilder.build();


    logger.info("start " + numberOfNodes + " nodes");
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder();
    for (int i = 0; i < numberOfNodes; i++) {
        nodes.add(newNode("node" + i));
    }
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    logger.info("restart all the primary shards, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("start the replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("complete rebalancing");
    return applyStartedShardsUntilNoChange(clusterState, strategy);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:BalanceConfigurationTests.java

示例6: removeNodes

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState removeNodes(ClusterState clusterState, AllocationService strategy) {
    logger.info("Removing half the nodes (" + (numberOfNodes + 1) / 2 + ")");
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());

    boolean removed = false;
    for (int i = (numberOfNodes + 1) / 2; i <= numberOfNodes; i++) {
        nodes.remove("node" + i);
        removed = true;
    }

    clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
    if (removed) {
        clusterState = strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes");
    }

    logger.info("start all the primary shards, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("start the replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));

    logger.info("rebalancing");
    clusterState = strategy.reroute(clusterState, "reroute");

    logger.info("complete rebalancing");
    return applyStartedShardsUntilNoChange(clusterState, strategy);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:BalanceConfigurationTests.java

示例7: createClusterStateWithStartedShards

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState createClusterStateWithStartedShards(String reason) {
    int numberOfNodes = 1 + numberOfReplicas;
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder();
    IntStream.rangeClosed(1, numberOfNodes).mapToObj(node -> newNode("node" + node)).forEach(nodes::add);
    ClusterState stateAfterAddingNode =
        ClusterState.builder(clusterState).nodes(nodes).build();
    RoutingTable afterReroute =
        allocationService.reroute(stateAfterAddingNode, reason).routingTable();
    ClusterState stateAfterReroute = ClusterState.builder(stateAfterAddingNode).routingTable(afterReroute).build();
    RoutingNodes routingNodes = stateAfterReroute.getRoutingNodes();
    return allocationService.applyStartedShards(stateAfterReroute, routingNodes.shardsWithState(ShardRoutingState.INITIALIZING));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:ShardFailedClusterStateTaskExecutorTests.java

示例8: testPrimaryNotRelocatedWhileBeingRecoveredFrom

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

    logger.info("Building initial routing table");

    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(5).numberOfReplicas(1))
            .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 two nodes and performing rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    logger.info("Start the primary shard (on node1)");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));

    assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));

    logger.info("start another node, replica will start recovering form primary");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
    assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));

    logger.info("start another node, make sure the primary is not relocated");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
    assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:PrimaryNotRelocatedWhileBeingRecoveredTests.java

示例9: testAlways

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testAlways() {
        AllocationService strategy = createAllocationService(Settings.builder().put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(),
                ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());

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

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

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

        logger.info("start two nodes");
        clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
        clusterState = strategy.reroute(clusterState, "reroute");

        for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
            assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
            assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
        }

        for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
            assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
            assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
        }

        logger.info("start all the primary shards for test1, replicas will start initializing");
        RoutingNodes routingNodes = clusterState.getRoutingNodes();
        clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));

        for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
//            assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(STARTED));
            assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(INITIALIZING));
        }

        for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
            assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
            assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
        }

        logger.info("start the test1 replica shards");
        routingNodes = clusterState.getRoutingNodes();
        clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
        routingNodes = clusterState.getRoutingNodes();

        for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
            assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(STARTED));
            assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(STARTED));
        }

        for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
            assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
            assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
            assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
        }

        logger.info("now, start 1 more node, check that rebalancing will happen (for test1) because we set it to always");
        clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
                .add(newNode("node3")))
                .build();
        clusterState = strategy.reroute(clusterState, "reroute");
        routingNodes = clusterState.getRoutingNodes();

        assertThat(routingNodes.node("node3").size(), equalTo(1));
        assertThat(routingNodes.node("node3").iterator().next().shardId().getIndex().getName(), equalTo("test1"));
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:76,代码来源:ClusterRebalanceRoutingTests.java

示例10: routingAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private static RoutingAllocation routingAllocation(ClusterState clusterState) {
    return new RoutingAllocation(NOOP_DECIDERS, clusterState.getRoutingNodes(), clusterState, null, System.nanoTime(), randomBoolean());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ClusterAllocationExplainActionTests.java

示例11: testClusterAllActive2

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testClusterAllActive2() {
    AllocationService strategy = createAllocationService(Settings.builder().put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(),
            ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());

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

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

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

    logger.info("start two nodes");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
    clusterState = strategy.reroute(clusterState, "reroute");

    for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
        assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
    }

    for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
        assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
    }

    logger.info("start all the primary shards for test1, replicas will start initializing");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
    routingNodes = clusterState.getRoutingNodes();

    for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(STARTED));
        assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(INITIALIZING));
    }

    for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
        assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
    }

    logger.info("start the test1 replica shards");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
    routingNodes = clusterState.getRoutingNodes();

    for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(STARTED));
        assertThat(clusterState.routingTable().index("test1").shard(i).replicaShards().get(0).state(), equalTo(STARTED));
    }

    for (int i = 0; i < clusterState.routingTable().index("test2").shards().size(); i++) {
        assertThat(clusterState.routingTable().index("test2").shard(i).shards().size(), equalTo(2));
        assertThat(clusterState.routingTable().index("test2").shard(i).primaryShard().state(), equalTo(INITIALIZING));
        assertThat(clusterState.routingTable().index("test2").shard(i).replicaShards().get(0).state(), equalTo(UNASSIGNED));
    }

    logger.info("now, start 1 more node, check that rebalancing will not happen (for test1) because we set it to all_active");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
            .add(newNode("node3")))
            .build();
    clusterState = strategy.reroute(clusterState, "reroute");
    routingNodes = clusterState.getRoutingNodes();

    assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:76,代码来源:ClusterRebalanceRoutingTests.java

示例12: testCanAllocateUsesMaxAvailableSpace

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testCanAllocateUsesMaxAvailableSpace() {
    ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    DiskThresholdDecider decider = new DiskThresholdDecider(Settings.EMPTY, nss);

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

    final Index index = metaData.index("test").getIndex();

    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
            new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
    DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
            new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);

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

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

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                    .add(node_0)
                    .add(node_1)
    ).build();

    // actual test -- after all that bloat :)
    ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsages = ImmutableOpenMap.builder();
    leastAvailableUsages.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, 0)); // all full
    leastAvailableUsages.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, 0)); // all full

    ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsage = ImmutableOpenMap.builder();
    mostAvailableUsage.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, randomIntBetween(20, 100))); // 20 - 99 percent since after allocation there must be at least 10% left and shard is 10byte
    mostAvailableUsage.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, randomIntBetween(0, 10))); // this is weird and smells like a bug! it should be up to 20%?

    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    shardSizes.put("[test][0][p]", 10L); // 10 bytes
    final ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(), shardSizes.build(), ImmutableOpenMap.of());
    RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Settings.EMPTY, Collections.singleton(decider)), clusterState.getRoutingNodes(), clusterState, clusterInfo, System.nanoTime(), false);
    allocation.debugDecision(true);
    Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.YES, decision.type());
    assertThat(((Decision.Single) decision).getExplanation(), containsString("enough disk for shard on node"));
    decision = decider.canAllocate(test_0, new RoutingNode("node_1", node_1), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.NO, decision.type());
    assertThat(((Decision.Single) decision).getExplanation(), containsString(
        "the node is above the high watermark cluster setting [cluster.routing.allocation.disk.watermark.high=90%], using more " +
        "disk space than the maximum allowed [90.0%]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:51,代码来源:DiskThresholdDeciderUnitTests.java

示例13: testMinimalRelocations

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testMinimalRelocations() {
    Settings.Builder settings = Settings.builder();
    settings.put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
            .put("cluster.routing.allocation.node_concurrent_recoveries", 2);
    AllocationService service = createAllocationService(settings.build());

    ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
    int nodeOffset = 1;
    clusterState = addNodes(clusterState, service, 1, nodeOffset++);
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
    assertNumIndexShardsPerNode(clusterState, equalTo(3));

    logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
    nodes.add(newNode("node2"));
    clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();

    clusterState = service.reroute(clusterState, "reroute");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();

    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState  = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, equalTo(clusterState));
    assertNumIndexShardsPerNode(clusterState, equalTo(2));
    logger.debug("ClusterState: {}", clusterState.getRoutingNodes());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:61,代码来源:AddIncrementallyTests.java

示例14: testMinimalRelocationsNoLimit

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testMinimalRelocationsNoLimit() {
    Settings.Builder settings = Settings.builder();
    settings.put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
            .put("cluster.routing.allocation.node_concurrent_recoveries", 100)
            .put("cluster.routing.allocation.node_initial_primaries_recoveries", 100);
    AllocationService service = createAllocationService(settings.build());

    ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
    int nodeOffset = 1;
    clusterState = addNodes(clusterState, service, 1, nodeOffset++);
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
    assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
    assertNumIndexShardsPerNode(clusterState, equalTo(3));

    logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
    nodes.add(newNode("node2"));
    clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();

    clusterState = service.reroute(clusterState, "reroute");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();

    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    routingNodes = clusterState.getRoutingNodes();
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));

    newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
    assertThat(newState, equalTo(clusterState));
    assertNumIndexShardsPerNode(clusterState, equalTo(2));
    logger.debug("ClusterState: {}", clusterState.getRoutingNodes());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:AddIncrementallyTests.java

示例15: testBackupElectionToPrimaryWhenPrimaryCanBeAllocatedToAnotherNode

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

    logger.info("Building initial routing table");

    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(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();

    logger.info("Adding two nodes and performing rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    clusterState = strategy.reroute(clusterState, "reroute");

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

    logger.info("Start the primary shard (on node1)");
    RoutingNodes routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));

    logger.info("Start the backup shard (on node2)");
    routingNodes = clusterState.getRoutingNodes();
    clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));

    logger.info("Adding third node and reroute and kill first node");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3")).remove("node1")).build();
    RoutingTable prevRoutingTable = clusterState.routingTable();
    clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
    routingNodes = clusterState.getRoutingNodes();
    routingTable = clusterState.routingTable();

    assertThat(prevRoutingTable != routingTable, equalTo(true));
    assertThat(routingTable.index("test").shards().size(), equalTo(1));
    assertThat(routingNodes.node("node1"), nullValue());
    assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(1));
    assertThat(routingNodes.node("node3").numberOfShardsWithState(INITIALIZING), equalTo(1));
    // verify where the primary is
    assertThat(routingTable.index("test").shard(0).primaryShard().currentNodeId(), equalTo("node2"));
    assertThat(clusterState.metaData().index("test").primaryTerm(0), equalTo(2L));
    assertThat(routingTable.index("test").shard(0).replicaShards().get(0).currentNodeId(), equalTo("node3"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:PrimaryElectionRoutingTests.java


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