Search in sources :

Example 6 with RootTask

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

the class TransportDistributedResultAction method nodeOperation.

private CompletableFuture<DistributedResultResponse> nodeOperation(final DistributedResultRequest request, @Nullable Iterator<TimeValue> retryDelay) {
    RootTask rootTask = tasksService.getTaskOrNull(request.jobId());
    if (rootTask == null) {
        if (tasksService.recentlyFailed(request.jobId())) {
            return CompletableFuture.failedFuture(JobKilledException.of("Received result for job=" + request.jobId() + " but there is no context for this job due to a failure during the setup."));
        } else {
            return retryOrFailureResponse(request, retryDelay);
        }
    }
    DownstreamRXTask rxTask;
    try {
        rxTask = rootTask.getTask(request.executionPhaseId());
    } catch (ClassCastException e) {
        return CompletableFuture.failedFuture(new IllegalStateException(String.format(Locale.ENGLISH, "Found execution rootTask for %d but it's not a downstream rootTask", request.executionPhaseId()), e));
    } catch (Throwable t) {
        return CompletableFuture.failedFuture(t);
    }
    PageBucketReceiver pageBucketReceiver = rxTask.getBucketReceiver(request.executionPhaseInputId());
    if (pageBucketReceiver == null) {
        return CompletableFuture.failedFuture(new IllegalStateException(String.format(Locale.ENGLISH, "Couldn't find BucketReceiver for input %d", request.executionPhaseInputId())));
    }
    Throwable throwable = request.throwable();
    if (throwable == null) {
        SendResponsePageResultListener pageResultListener = new SendResponsePageResultListener();
        pageBucketReceiver.setBucket(request.bucketIdx(), request.readRows(pageBucketReceiver.streamers()), request.isLast(), pageResultListener);
        return pageResultListener.future;
    } else {
        pageBucketReceiver.kill(throwable);
        return CompletableFuture.completedFuture(new DistributedResultResponse(false));
    }
}
Also used : PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) DownstreamRXTask(io.crate.execution.jobs.DownstreamRXTask) RootTask(io.crate.execution.jobs.RootTask)

Example 7 with RootTask

use of io.crate.execution.jobs.RootTask 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)

Example 8 with RootTask

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

the class TransportJobAction method nodeOperation.

@Override
public CompletableFuture<JobResponse> nodeOperation(final JobRequest request) {
    RootTask.Builder contextBuilder = tasksService.newBuilder(request.jobId(), request.sessionSettings().userName(), request.coordinatorNodeId(), Collections.emptySet());
    SharedShardContexts sharedShardContexts = maybeInstrumentProfiler(request.enableProfiling(), contextBuilder);
    List<CompletableFuture<StreamBucket>> directResponseFutures = jobSetup.prepareOnRemote(request.sessionSettings(), request.nodeOperations(), contextBuilder, sharedShardContexts);
    try {
        RootTask context = tasksService.createTask(contextBuilder);
        context.start();
    } catch (Throwable t) {
        return CompletableFuture.failedFuture(t);
    }
    if (directResponseFutures.size() == 0) {
        return CompletableFuture.completedFuture(new JobResponse(List.of()));
    } else {
        return CompletableFutures.allAsList(directResponseFutures).thenApply(JobResponse::new);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) RootTask(io.crate.execution.jobs.RootTask)

Example 9 with RootTask

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

the class NodeDisconnectJobMonitorServiceTest method testOnNodeDisconnectedKillsJobOriginatingFromThatNode.

@Test
public void testOnNodeDisconnectedKillsJobOriginatingFromThatNode() throws Exception {
    TasksService tasksService = tasksInstance();
    RootTask.Builder builder = tasksService.newBuilder(UUID.randomUUID());
    builder.addTask(new DummyTask());
    RootTask context = tasksService.createTask(builder);
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(tasksService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), mock(TransportService.class), mock(TransportKillJobsNodeAction.class));
    monitorService.onNodeDisconnected(new DiscoveryNode(NODE_ID, buildNewFakeTransportAddress(), Version.CURRENT), mock(Transport.Connection.class));
    expectedException.expect(TaskMissing.class);
    tasksService.getTask(context.jobId());
    monitorService.close();
}
Also used : TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) DummyTask(io.crate.execution.jobs.DummyTask) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportService(org.elasticsearch.transport.TransportService) NodeLimits(io.crate.execution.jobs.NodeLimits) TasksService(io.crate.execution.jobs.TasksService) RootTask(io.crate.execution.jobs.RootTask) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

RootTask (io.crate.execution.jobs.RootTask)9 TasksService (io.crate.execution.jobs.TasksService)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 PageBucketReceiver (io.crate.execution.jobs.PageBucketReceiver)3 SharedShardContexts (io.crate.execution.jobs.SharedShardContexts)3 UUID (java.util.UUID)3 ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)2 NodeOperation (io.crate.execution.dsl.phases.NodeOperation)2 DownstreamRXTask (io.crate.execution.jobs.DownstreamRXTask)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Test (org.junit.Test)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 IntObjectCursor (com.carrotsearch.hppc.cursors.IntObjectCursor)1 Streamer (io.crate.Streamer)1 BlockBasedRamAccounting (io.crate.breaker.BlockBasedRamAccounting)1 ConcurrentRamAccounting (io.crate.breaker.ConcurrentRamAccounting)1