use of io.crate.operation.collect.collectors.RemoteCollector in project crate by crate.
the class RemoteCollectorFactory method createCollector.
/**
* create a RemoteCollector
* The RemoteCollector will collect data from another node using a wormhole as if it was collecting on this node.
* <p>
* This should only be used if a shard is not available on the current node due to a relocation
*/
public CrateCollector.Builder createCollector(String index, Integer shardId, RoutedCollectPhase collectPhase, final RamAccountingContext ramAccountingContext) {
// new job because subContexts can't be merged into an existing job
final UUID childJobId = UUID.randomUUID();
IndexShardRoutingTable shardRoutings = clusterService.state().routingTable().shardRoutingTable(index, shardId);
// for update operations primaryShards must be used
// (for others that wouldn't be the case, but at this point it is not easily visible which is the case)
ShardRouting shardRouting = shardRoutings.primaryShard();
final String remoteNodeId = shardRouting.currentNodeId();
assert remoteNodeId != null : "primaryShard not assigned :(";
final String localNodeId = clusterService.localNode().getId();
final RoutedCollectPhase newCollectPhase = createNewCollectPhase(childJobId, collectPhase, index, shardId, remoteNodeId);
return consumer -> new RemoteCollector(childJobId, localNodeId, remoteNodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), jobContextService, ramAccountingContext, consumer, newCollectPhase);
}
Aggregations