Search in sources :

Example 1 with RemoteCollector

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);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) java.util(java.util) Projections(io.crate.planner.projection.Projections) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) TreeMapBuilder(io.crate.core.collections.TreeMapBuilder) Routing(io.crate.metadata.Routing) Singleton(org.elasticsearch.common.inject.Singleton) ClusterService(org.elasticsearch.cluster.ClusterService) JobContextService(io.crate.jobs.JobContextService) TransportActionProvider(io.crate.executor.transport.TransportActionProvider) DistributionInfo(io.crate.planner.distribution.DistributionInfo) RamAccountingContext(io.crate.breaker.RamAccountingContext) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Aggregations

RamAccountingContext (io.crate.breaker.RamAccountingContext)1 TreeMapBuilder (io.crate.core.collections.TreeMapBuilder)1 TransportActionProvider (io.crate.executor.transport.TransportActionProvider)1 JobContextService (io.crate.jobs.JobContextService)1 Routing (io.crate.metadata.Routing)1 RemoteCollector (io.crate.operation.collect.collectors.RemoteCollector)1 DistributionInfo (io.crate.planner.distribution.DistributionInfo)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 Projections (io.crate.planner.projection.Projections)1 java.util (java.util)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 Inject (org.elasticsearch.common.inject.Inject)1 Singleton (org.elasticsearch.common.inject.Singleton)1