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