Search in sources :

Example 6 with PageBucketReceiver

use of io.crate.execution.jobs.PageBucketReceiver in project crate by crate.

the class JobLauncher method setupTasks.

private void setupTasks(TransactionContext txnCtx, Map<String, Collection<NodeOperation>> operationByServer, List<ExecutionPhase> handlerPhases, List<RowConsumer> handlerConsumers) throws Throwable {
    assert handlerPhases.size() == handlerConsumers.size() : "handlerPhases size must match handlerConsumers size";
    String localNodeId = clusterService.localNode().getId();
    Collection<NodeOperation> localNodeOperations = operationByServer.remove(localNodeId);
    if (localNodeOperations == null) {
        localNodeOperations = Collections.emptyList();
    }
    // + 1 for localTask which is always created
    InitializationTracker initializationTracker = new InitializationTracker(operationByServer.size() + 1);
    List<Tuple<ExecutionPhase, RowConsumer>> handlerPhaseAndReceiver = createHandlerPhaseAndReceivers(handlerPhases, handlerConsumers, initializationTracker);
    RootTask.Builder builder = tasksService.newBuilder(jobId, txnCtx.sessionSettings().userName(), localNodeId, operationByServer.keySet());
    SharedShardContexts sharedShardContexts = maybeInstrumentProfiler(builder);
    List<CompletableFuture<StreamBucket>> directResponseFutures = jobSetup.prepareOnHandler(txnCtx.sessionSettings(), localNodeOperations, builder, handlerPhaseAndReceiver, sharedShardContexts);
    RootTask localTask = tasksService.createTask(builder);
    List<PageBucketReceiver> pageBucketReceivers = getHandlerBucketReceivers(localTask, handlerPhaseAndReceiver);
    int bucketIdx = 0;
    /*
         * If you touch anything here make sure the following tests pass with > 1k iterations:
         *
         * Seed: 112E1807417E925A - testInvalidPatternSyntax
         * Seed: Any              - testRegularSelectWithFewAvailableThreadsShouldNeverGetStuck
         * Seed: CC456FF5004F35D3 - testFailureOfJoinDownstream
         */
    if (!localNodeOperations.isEmpty() && !directResponseFutures.isEmpty()) {
        assert directResponseFutures.size() == pageBucketReceivers.size() : "directResponses size must match pageBucketReceivers";
        CompletableFutures.allAsList(directResponseFutures).whenComplete(BucketForwarder.asConsumer(pageBucketReceivers, bucketIdx, initializationTracker));
        bucketIdx++;
        try {
            // initializationTracker for localNodeOperations is triggered via SetBucketCallback
            localTask.start();
        } catch (Throwable t) {
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    } else {
        try {
            localTask.start();
            initializationTracker.jobInitialized();
        } catch (Throwable t) {
            initializationTracker.jobInitializationFailed(t);
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    }
    sendJobRequests(txnCtx, localNodeId, operationByServer, pageBucketReceivers, handlerPhaseAndReceiver, bucketIdx, initializationTracker);
}
Also used : NodeOperation(io.crate.execution.dsl.phases.NodeOperation) RootTask(io.crate.execution.jobs.RootTask) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) Tuple(io.crate.common.collections.Tuple)

Aggregations

PageBucketReceiver (io.crate.execution.jobs.PageBucketReceiver)6 RootTask (io.crate.execution.jobs.RootTask)4 CumulativePageBucketReceiver (io.crate.execution.jobs.CumulativePageBucketReceiver)2 DownstreamRXTask (io.crate.execution.jobs.DownstreamRXTask)2 Tuple (io.crate.common.collections.Tuple)1 Bucket (io.crate.data.Bucket)1 Row (io.crate.data.Row)1 ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)1 NodeOperation (io.crate.execution.dsl.phases.NodeOperation)1 DistResultRXTask (io.crate.execution.jobs.DistResultRXTask)1 SharedShardContexts (io.crate.execution.jobs.SharedShardContexts)1 Task (io.crate.execution.jobs.Task)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ActionListener (org.elasticsearch.action.ActionListener)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1