Search in sources :

Example 1 with ShardIterator

use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.

the class BlobService method getRedirectAddress.

/**
     * @param index  the name of blob-enabled index
     * @param digest sha-1 hash value of the file
     * @return null if no redirect is required, Otherwise the address to which should be redirected.
     */
public String getRedirectAddress(String index, String digest) throws MissingHTTPEndpointException {
    ShardIterator shards = clusterService.operationRouting().getShards(clusterService.state(), index, null, null, digest, "_local");
    String localNodeId = clusterService.state().nodes().getLocalNodeId();
    DiscoveryNodes nodes = clusterService.state().getNodes();
    ShardRouting shard;
    while ((shard = shards.nextOrNull()) != null) {
        if (!shard.active()) {
            continue;
        }
        if (shard.currentNodeId().equals(localNodeId)) {
            // no redirect required if the shard is on this node
            return null;
        }
        DiscoveryNode node = nodes.get(shard.currentNodeId());
        String httpAddress = node.getAttributes().get("http_address");
        if (httpAddress != null) {
            return httpAddress + "/_blobs/" + BlobIndex.stripPrefix(index) + "/" + digest;
        }
    }
    throw new MissingHTTPEndpointException("Can't find a suitable http server to serve the blob");
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) MissingHTTPEndpointException(io.crate.blob.exceptions.MissingHTTPEndpointException) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 2 with ShardIterator

use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.

the class TransportStartBlobAction method resolveRequest.

@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, StartBlobRequest request) {
    ShardIterator shardIterator = clusterService.operationRouting().indexShards(clusterService.state(), concreteIndex, null, request.id(), null);
    request.setShardId(shardIterator.shardId());
}
Also used : ShardIterator(org.elasticsearch.cluster.routing.ShardIterator)

Example 3 with ShardIterator

use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.

the class TransportDeleteBlobAction method resolveRequest.

@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, DeleteBlobRequest request) {
    ShardIterator shardIterator = clusterService.operationRouting().indexShards(clusterService.state(), concreteIndex, null, request.id(), null);
    request.setShardId(shardIterator.shardId());
}
Also used : ShardIterator(org.elasticsearch.cluster.routing.ShardIterator)

Example 4 with ShardIterator

use of org.elasticsearch.cluster.routing.ShardIterator in project crate by crate.

the class BlobTableInfo method getRouting.

@Override
public Routing getRouting(WhereClause whereClause, @Nullable String preference) {
    Map<String, Map<String, List<Integer>>> locations = new TreeMap<>();
    GroupShardsIterator shardIterators = clusterService.operationRouting().searchShards(clusterService.state(), new String[] { index }, null, preference);
    ShardRouting shardRouting;
    for (ShardIterator shardIterator : shardIterators) {
        shardRouting = shardIterator.nextOrNull();
        processShardRouting(locations, shardRouting, shardIterator.shardId());
    }
    return new Routing(locations);
}
Also used : GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 5 with ShardIterator

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

the class SearchStatsIT method nodeIdsWithIndex.

private Set<String> nodeIdsWithIndex(String... indices) {
    ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
    GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true);
    Set<String> nodes = new HashSet<>();
    for (ShardIterator shardIterator : allAssignedShardsGrouped) {
        for (ShardRouting routing : shardIterator.asUnordered()) {
            if (routing.active()) {
                nodes.add(routing.currentNodeId());
            }
        }
    }
    return nodes;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) HashSet(java.util.HashSet)

Aggregations

ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)30 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)22 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)16 ClusterState (org.elasticsearch.cluster.ClusterState)14 PlainShardIterator (org.elasticsearch.cluster.routing.PlainShardIterator)11 HashMap (java.util.HashMap)7 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 Index (org.elasticsearch.index.Index)7 ArrayList (java.util.ArrayList)6 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 MetaData (org.elasticsearch.cluster.metadata.MetaData)6 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)6 ShardId (org.elasticsearch.index.shard.ShardId)6 AliasFilter (org.elasticsearch.search.internal.AliasFilter)6 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 ActionListener (org.elasticsearch.action.ActionListener)4 Transport (org.elasticsearch.transport.Transport)4 Path (java.nio.file.Path)3