Java Code Examples for org.elasticsearch.cluster.routing.ShardIterator#shardId()

The following examples show how to use org.elasticsearch.cluster.routing.ShardIterator#shardId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocTableInfo.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void fillLocationsFromShardIterators(Map<String, Map<String, List<Integer>>> locations,
                                             GroupShardsIterator shardIterators,
                                             List<ShardId> missingShards) {
    ShardRouting shardRouting;
    for (ShardIterator shardIterator : shardIterators) {
        shardRouting = shardIterator.nextOrNull();
        if (shardRouting != null) {
            if (shardRouting.active()) {
                processShardRouting(locations, shardRouting);
            } else {
                missingShards.add(shardIterator.shardId());
            }
        } else {
            if (isPartitioned) {
                // if the table is partitioned maybe a index/shard just got newly created ...
                missingShards.add(shardIterator.shardId());
            } else {
                throw new UnavailableShardsException(shardIterator.shardId());
            }
        }
    }
}
 
Example 2
Source File: InsertFromValues.java    From crate with Apache License 2.0 6 votes vote down vote up
private static ShardLocation getShardLocation(String indexName,
                                              String id,
                                              @Nullable String routing,
                                              ClusterService clusterService) {
    ShardIterator shardIterator = clusterService.operationRouting().indexShards(
        clusterService.state(),
        indexName,
        id,
        routing);

    final String nodeId;
    ShardRouting shardRouting = shardIterator.nextOrNull();
    if (shardRouting == null) {
        nodeId = null;
    } else if (shardRouting.active() == false) {
        nodeId = shardRouting.relocatingNodeId();
    } else {
        nodeId = shardRouting.currentNodeId();
    }
    return new ShardLocation(shardIterator.shardId(), nodeId);
}
 
Example 3
Source File: AbstractSearchAsyncAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private String executionFailureMsg(@Nullable ShardRouting shard, final ShardIterator shardIt, SearchRequest request, boolean lastShard) {
    if (shard != null) {
        return shard.shortSummary() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
    } else {
        return shardIt.shardId() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
    }
}
 
Example 4
Source File: TransportBroadcastAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
void setFailure(ShardIterator shardIt, int shardIndex, Throwable t) {
    // we don't aggregate shard failures on non active shards (but do keep the header counts right)
    if (TransportActions.isShardNotAvailableException(t)) {
        return;
    }

    if (!(t instanceof BroadcastShardOperationFailedException)) {
        t = new BroadcastShardOperationFailedException(shardIt.shardId(), t);
    }

    Object response = shardsResponses.get(shardIndex);
    if (response == null) {
        // just override it and return
        shardsResponses.set(shardIndex, t);
    }

    if (!(response instanceof Throwable)) {
        // we should never really get here...
        return;
    }

    // the failure is already present, try and not override it with an exception that is less meaningless
    // for example, getting illegal shard state
    if (TransportActions.isReadOverrideException(t)) {
        shardsResponses.set(shardIndex, t);
    }
}
 
Example 5
Source File: GroupRowsByShard.java    From crate with Apache License 2.0 5 votes vote down vote up
@Nullable
private ShardLocation getShardLocation(String indexName, String id, @Nullable String routing) {
    try {
        ShardIterator shardIterator = clusterService.operationRouting().indexShards(
            clusterService.state(),
            indexName,
            id,
            routing
        );

        final String nodeId;
        ShardRouting shardRouting = shardIterator.nextOrNull();
        if (shardRouting == null) {
            nodeId = null;
        } else if (shardRouting.active() == false) {
            nodeId = shardRouting.relocatingNodeId();
        } else {
            nodeId = shardRouting.currentNodeId();
        }
        if (nodeId == null && LOGGER.isDebugEnabled()) {
            LOGGER.debug("Unable to get the node id for index {} and shard {}", indexName, id);
        }
        return new ShardLocation(shardIterator.shardId(), nodeId);
    } catch (IndexNotFoundException e) {
        if (!autoCreateIndices) {
            throw e;
        }
        return null;
    }
}
 
Example 6
Source File: RoutingProvider.java    From crate with Apache License 2.0 5 votes vote down vote up
private static void fillLocationsFromShardIterator(boolean ignoreMissingShards,
                                                   Map<String, Map<String, IntIndexedContainer>> locations,
                                                   ShardIterator shardIterator) {
    ShardRouting shardRouting = shardIterator.nextOrNull();
    if (shardRouting == null) {
        if (ignoreMissingShards) {
            return;
        }
        throw new UnavailableShardsException(shardIterator.shardId());
    }
    processShardRouting(locations, shardRouting);
}
 
Example 7
Source File: BlobIndex.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public ShardId shardId(String digest) {
    ShardIterator si = operationRouting.getShards(clusterService.state(), index.getName(), null, null, digest, "_only_local");
    // TODO: check null and raise
    return si.shardId();
}
 
Example 8
Source File: BlobIndicesService.java    From crate with Apache License 2.0 4 votes vote down vote up
private ShardId localShardId(String index, String digest) {
    ShardIterator si = clusterService.operationRouting().getShards(
        clusterService.state(), index, null, digest, "_only_local");
    return si.shardId();
}