Search in sources :

Example 1 with ShardLocation

use of io.crate.execution.engine.indexing.ShardLocation in project crate by crate.

the class InsertFromValues method resolveAndGroupShardRequests.

private static <TReq extends ShardRequest<TReq, TItem>, TItem extends ShardRequest.Item> Map<ShardLocation, TReq> resolveAndGroupShardRequests(ShardedRequests<TReq, TItem> shardedRequests, ClusterService clusterService) {
    var itemsByMissingIndex = shardedRequests.itemsByMissingIndex().entrySet().iterator();
    while (itemsByMissingIndex.hasNext()) {
        var entry = itemsByMissingIndex.next();
        var index = entry.getKey();
        var requestItems = entry.getValue();
        var requestItemsIterator = requestItems.iterator();
        while (requestItemsIterator.hasNext()) {
            var itemAndRoutingAndSourceInfo = requestItemsIterator.next();
            ShardLocation shardLocation;
            try {
                shardLocation = getShardLocation(index, itemAndRoutingAndSourceInfo.item().id(), itemAndRoutingAndSourceInfo.routing(), clusterService);
            } catch (IndexNotFoundException e) {
                if (IndexParts.isPartitioned(index)) {
                    requestItemsIterator.remove();
                    continue;
                } else {
                    throw e;
                }
            }
            shardedRequests.add(itemAndRoutingAndSourceInfo.item(), 0, shardLocation, null);
            requestItemsIterator.remove();
        }
        if (requestItems.isEmpty()) {
            itemsByMissingIndex.remove();
        }
    }
    return shardedRequests.itemsByShard();
}
Also used : ShardLocation(io.crate.execution.engine.indexing.ShardLocation) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 2 with ShardLocation

use of io.crate.execution.engine.indexing.ShardLocation in project crate by crate.

the class InsertFromValues method getShardLocation.

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);
}
Also used : ShardLocation(io.crate.execution.engine.indexing.ShardLocation) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

ShardLocation (io.crate.execution.engine.indexing.ShardLocation)2 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1