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();
}
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);
}
Aggregations