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


Java ClusterState.routingTable方法代码示例

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


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

示例1: findNextDelayedAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Finds the next (closest) delay expiration of an delayed shard in nanoseconds based on current time.
 * Returns 0 if delay is negative.
 * Returns -1 if no delayed shard is found.
 */
public static long findNextDelayedAllocation(long currentNanoTime, ClusterState state) {
    MetaData metaData = state.metaData();
    RoutingTable routingTable = state.routingTable();
    long nextDelayNanos = Long.MAX_VALUE;
    for (ShardRouting shard : routingTable.shardsWithState(ShardRoutingState.UNASSIGNED)) {
        UnassignedInfo unassignedInfo = shard.unassignedInfo();
        if (unassignedInfo.isDelayed()) {
            Settings indexSettings = metaData.index(shard.index()).getSettings();
            // calculate next time to schedule
            final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(currentNanoTime, indexSettings);
            if (newComputedLeftDelayNanos < nextDelayNanos) {
                nextDelayNanos = newComputedLeftDelayNanos;
            }
        }
    }
    return nextDelayNanos == Long.MAX_VALUE ? -1L : nextDelayNanos;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:UnassignedInfo.java

示例2: applyRerouteResult

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private void applyRerouteResult(ClusterState newClusterState) {
    ClusterState previousClusterState = this.clusterState;
    ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
    if (previousClusterState.routingTable() != newClusterState.routingTable()) {
        builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1)
                .build());
    }
    if (previousClusterState.metaData() != newClusterState.metaData()) {
        builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
    }
    this.clusterState = builder.build();
    final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
    logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]",
            clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(),
            clusterHealth.getInitializingShards(), clusterHealth.getRelocatingShards());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PrimaryTermsTests.java

示例3: testPrimaryShardYesDecisionOnIndexCreation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testPrimaryShardYesDecisionOnIndexCreation() throws IOException {
    final String indexName = "test-idx";
    Settings settings = Settings.builder()
                            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
                            .build();
    AllocationDecider decider = new TestAllocateDecision(Decision.YES) {
        @Override
        public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
            if (node.getByShardId(shardRouting.shardId()) == null) {
                return Decision.YES;
            } else {
                return Decision.NO;
            }
        }
    };
    // if deciders say YES to allocating primary shards, stay in YELLOW state
    ClusterState clusterState = runAllocationTest(
        settings, indexName, Collections.singleton(decider), ClusterHealthStatus.YELLOW
    );
    // make sure primaries are initialized
    RoutingTable routingTable = clusterState.routingTable();
    for (IndexShardRoutingTable indexShardRoutingTable : routingTable.index(indexName)) {
        assertTrue(indexShardRoutingTable.primaryShard().initializing());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:DecisionsImpactOnClusterHealthTests.java

示例4: startPrimaries

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState startPrimaries(final ClusterState clusterState, final String indexName) {
    RoutingTable routingTable = clusterState.routingTable();
    IndexRoutingTable indexRoutingTable = routingTable.index(indexName);
    IndexRoutingTable.Builder newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
    for (final ObjectCursor<IndexShardRoutingTable> shardEntry : indexRoutingTable.getShards().values()) {
        final IndexShardRoutingTable shardRoutingTable = shardEntry.value;
        for (ShardRouting shardRouting : shardRoutingTable.getShards()) {
            if (shardRouting.primary()) {
                shardRouting = shardRouting.initialize(randomAsciiOfLength(8), null, shardRouting.getExpectedShardSize())
                                   .moveToStarted();
            }
            newIndexRoutingTable.addShard(shardRouting);
        }
    }
    routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build();
    return ClusterState.builder(clusterState).routingTable(routingTable).build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ActiveShardCountTests.java

示例5: startAllShards

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private ClusterState startAllShards(final ClusterState clusterState, final String indexName) {
    RoutingTable routingTable = clusterState.routingTable();
    IndexRoutingTable indexRoutingTable = routingTable.index(indexName);
    IndexRoutingTable.Builder newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
    for (final ObjectCursor<IndexShardRoutingTable> shardEntry : indexRoutingTable.getShards().values()) {
        final IndexShardRoutingTable shardRoutingTable = shardEntry.value;
        for (ShardRouting shardRouting : shardRoutingTable.getShards()) {
            if (shardRouting.primary()) {
                assertTrue(shardRouting.active());
            } else {
                if (shardRouting.active() == false) {
                    shardRouting = shardRouting.initialize(randomAsciiOfLength(8), null, shardRouting.getExpectedShardSize())
                                       .moveToStarted();
                }
            }
            newIndexRoutingTable.addShard(shardRouting);
        }
    }
    routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build();
    return ClusterState.builder(clusterState).routingTable(routingTable).build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ActiveShardCountTests.java

示例6: assertAllShardsOnNodes

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Asserts that all shards are allocated on nodes matching the given node pattern.
 */
public Set<String> assertAllShardsOnNodes(String index, String... pattern) {
    Set<String> nodes = new HashSet<>();
    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                if (shardRouting.currentNodeId() != null && index.equals(shardRouting.getIndexName())) {
                    String name = clusterState.nodes().get(shardRouting.currentNodeId()).getName();
                    nodes.add(name);
                    assertThat("Allocated on new node: " + name, Regex.simpleMatch(pattern, name), is(true));
                }
            }
        }
    }
    return nodes;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ESIntegTestCase.java

示例7: RoutingAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Creates a new {@link RoutingAllocation}
 *  @param deciders {@link AllocationDeciders} to used to make decisions for routing allocations
 * @param routingNodes Routing nodes in the current cluster
 * @param clusterState cluster state before rerouting
 * @param currentNanoTime the nano time to use for all delay allocation calculation (typically {@link System#nanoTime()})
 */
public RoutingAllocation(AllocationDeciders deciders, RoutingNodes routingNodes, ClusterState clusterState, ClusterInfo clusterInfo,
                         long currentNanoTime, boolean retryFailed) {
    this.deciders = deciders;
    this.routingNodes = routingNodes;
    this.metaData = clusterState.metaData();
    this.routingTable = clusterState.routingTable();
    this.nodes = clusterState.nodes();
    this.customs = clusterState.customs();
    this.clusterInfo = clusterInfo;
    this.currentNanoTime = currentNanoTime;
    this.retryFailed = retryFailed;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RoutingAllocation.java

示例8: indicesWithMissingPrimaries

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Finds all indices that have not all primaries available
 */
private Set<String> indicesWithMissingPrimaries(ClusterState clusterState, String[] concreteIndices) {
    Set<String> indices = new HashSet<>();
    RoutingTable routingTable = clusterState.routingTable();
    for (String index : concreteIndices) {
        IndexRoutingTable indexRoutingTable = routingTable.index(index);
        if (indexRoutingTable.allPrimaryShardsActive() == false) {
            indices.add(index);
        }
    }
    return indices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TransportUpgradeAction.java

示例9: masterOperation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
protected void masterOperation(IndicesShardStoresRequest request, ClusterState state, ActionListener<IndicesShardStoresResponse> listener) {
    final RoutingTable routingTables = state.routingTable();
    final RoutingNodes routingNodes = state.getRoutingNodes();
    final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
    final Set<ShardId> shardIdsToFetch = new HashSet<>();

    logger.trace("using cluster state version [{}] to determine shards", state.version());
    // collect relevant shard ids of the requested indices for fetching store infos
    for (String index : concreteIndices) {
        IndexRoutingTable indexShardRoutingTables = routingTables.index(index);
        if (indexShardRoutingTables == null) {
            continue;
        }
        for (IndexShardRoutingTable routing : indexShardRoutingTables) {
            final int shardId = routing.shardId().id();
            ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, routing);
            if (request.shardStatuses().contains(shardHealth.getStatus())) {
                shardIdsToFetch.add(routing.shardId());
            }
        }
    }

    // async fetch store infos from all the nodes
    // NOTE: instead of fetching shard store info one by one from every node (nShards * nNodes requests)
    // we could fetch all shard store info from every node once (nNodes requests)
    // we have to implement a TransportNodesAction instead of using TransportNodesListGatewayStartedShards
    // for fetching shard stores info, that operates on a list of shards instead of a single shard
    new AsyncShardStoresInfoFetches(state.nodes(), routingNodes, shardIdsToFetch, listener).start();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:TransportIndicesShardStoresAction.java

示例10: testDecommissionNodeNoReplicas

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testDecommissionNodeNoReplicas() throws Exception {
    logger.info("--> starting 2 nodes");
    List<String> nodesIds = internalCluster().startNodes(2);
    final String node_0 = nodesIds.get(0);
    final String node_1 = nodesIds.get(1);
    assertThat(cluster().size(), equalTo(2));

    logger.info("--> creating an index with no replicas");
    client().admin().indices().prepareCreate("test")
            .setSettings(Settings.builder().put("index.number_of_replicas", 0))
            .execute().actionGet();
    ensureGreen();
    logger.info("--> index some data");
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
    }
    client().admin().indices().prepareRefresh().execute().actionGet();
    assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(100L));

    logger.info("--> decommission the second node");
    client().admin().cluster().prepareUpdateSettings()
            .setTransientSettings(Settings.builder().put("cluster.routing.allocation.exclude._name", node_1))
            .execute().actionGet();
    waitForRelocation();

    logger.info("--> verify all are allocated on node1 now");
    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                assertThat(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), equalTo(node_0));
            }
        }
    }

    client().admin().indices().prepareRefresh().execute().actionGet();
    assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(100L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:FilteringAllocationIT.java

示例11: indicesWithMissingPrimaries

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Finds all indices that have not all primaries available
 */
private Set<String> indicesWithMissingPrimaries(ClusterState clusterState, String[] concreteIndices) {
    Set<String> indices = newHashSet();
    RoutingTable routingTable = clusterState.routingTable();
    for (String index : concreteIndices) {
        IndexRoutingTable indexRoutingTable = routingTable.index(index);
        if (indexRoutingTable.allPrimaryShardsActive() == false) {
            indices.add(index);
        }
    }
    return indices;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:TransportUpgradeAction.java

示例12: masterOperation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
protected void masterOperation(IndicesShardStoresRequest request, ClusterState state, ActionListener<IndicesShardStoresResponse> listener) {
    final RoutingTable routingTables = state.routingTable();
    final RoutingNodes routingNodes = state.getRoutingNodes();
    final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    final Set<ShardId> shardIdsToFetch = new HashSet<>();

    logger.trace("using cluster state version [{}] to determine shards", state.version());
    // collect relevant shard ids of the requested indices for fetching store infos
    for (String index : concreteIndices) {
        IndexRoutingTable indexShardRoutingTables = routingTables.index(index);
        if (indexShardRoutingTables == null) {
            continue;
        }
        for (IndexShardRoutingTable routing : indexShardRoutingTables) {
            ClusterShardHealth shardHealth = new ClusterShardHealth(routing.shardId().id(), routing);
            if (request.shardStatuses().contains(shardHealth.getStatus())) {
                shardIdsToFetch.add(routing.shardId());
            }
        }
    }

    // async fetch store infos from all the nodes
    // NOTE: instead of fetching shard store info one by one from every node (nShards * nNodes requests)
    // we could fetch all shard store info from every node once (nNodes requests)
    // we have to implement a TransportNodesAction instead of using TransportNodesListGatewayStartedShards
    // for fetching shard stores info, that operates on a list of shards instead of a single shard
    new AsyncShardStoresInfoFetches(state.nodes(), routingNodes, state.metaData(), shardIdsToFetch, listener).start();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:TransportIndicesShardStoresAction.java

示例13: 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

示例14: testAwarenessZones

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testAwarenessZones() throws Exception {
    Settings commonSettings = Settings.builder()
            .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a,b")
            .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "zone")
            .put(ZenDiscovery.JOIN_TIMEOUT_SETTING.getKey(), "10s")
            .build();

    logger.info("--> starting 4 nodes on different zones");
    List<String> nodes = internalCluster().startNodes(
            Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(),
            Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
            Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(),
            Settings.builder().put(commonSettings).put("node.attr.zone", "a").build()
    );
    String A_0 = nodes.get(0);
    String B_0 = nodes.get(1);
    String B_1 = nodes.get(2);
    String A_1 = nodes.get(3);

    logger.info("--> waiting for nodes to form a cluster");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("4").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));

    client().admin().indices().prepareCreate("test")
    .setSettings(Settings.builder().put("index.number_of_shards", 5)
            .put("index.number_of_replicas", 1)).execute().actionGet();

    logger.info("--> waiting for shards to be allocated");
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));

    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();

    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
            }
        }
    }
    assertThat(counts.get(A_1), anyOf(equalTo(2),equalTo(3)));
    assertThat(counts.get(B_1), anyOf(equalTo(2),equalTo(3)));
    assertThat(counts.get(A_0), anyOf(equalTo(2),equalTo(3)));
    assertThat(counts.get(B_0), anyOf(equalTo(2),equalTo(3)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:AwarenessAllocationIT.java


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