Search in sources :

Example 6 with OperationRouting

use of org.elasticsearch.cluster.routing.OperationRouting in project elasticsearch by elastic.

the class InternalTestCluster method routingKeyForShard.

synchronized String routingKeyForShard(Index index, int shard, Random random) {
    assertThat(shard, greaterThanOrEqualTo(0));
    assertThat(shard, greaterThanOrEqualTo(0));
    for (NodeAndClient n : nodes.values()) {
        Node node = n.node;
        IndicesService indicesService = getInstanceFromNode(IndicesService.class, node);
        ClusterService clusterService = getInstanceFromNode(ClusterService.class, node);
        IndexService indexService = indicesService.indexService(index);
        if (indexService != null) {
            assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard));
            OperationRouting operationRouting = clusterService.operationRouting();
            while (true) {
                String routing = RandomStrings.randomAsciiOfLength(random, 10);
                final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), null, routing).shardId().getId();
                if (shard == targetShard) {
                    return routing;
                }
            }
        }
    }
    fail("Could not find a node that holds " + index);
    return null;
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexService(org.elasticsearch.index.IndexService) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) IndicesService(org.elasticsearch.indices.IndicesService)

Aggregations

OperationRouting (org.elasticsearch.cluster.routing.OperationRouting)6 ClusterState (org.elasticsearch.cluster.ClusterState)4 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)4 ShardResponse (io.crate.executor.transport.ShardResponse)2 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)2 Reference (io.crate.metadata.Reference)2 ReferenceIdent (io.crate.metadata.ReferenceIdent)2 RowGranularity (io.crate.metadata.RowGranularity)2 TableIdent (io.crate.metadata.TableIdent)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 DataTypes (io.crate.types.DataTypes)2 UUID (java.util.UUID)2 java.util.concurrent (java.util.concurrent)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ActionListener (org.elasticsearch.action.ActionListener)2 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)2 ClusterService (org.elasticsearch.cluster.ClusterService)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)2