Search in sources :

Example 6 with NodeOperation

use of io.crate.execution.dsl.phases.NodeOperation in project crate by crate.

the class ExplainPlan method extractPhasesTimingsFrom.

private static Map<String, Object> extractPhasesTimingsFrom(Map<String, Map<String, Object>> timingsByNodeId, NodeOperationTree operationTree) {
    Map<String, Object> allPhases = new TreeMap<>();
    for (NodeOperation operation : operationTree.nodeOperations()) {
        ExecutionPhase phase = operation.executionPhase();
        getPhaseTimingsAndAddThemToPhasesMap(phase, timingsByNodeId, allPhases);
    }
    ExecutionPhase leafExecutionPhase = operationTree.leaf();
    getPhaseTimingsAndAddThemToPhasesMap(leafExecutionPhase, timingsByNodeId, allPhases);
    return allPhases;
}
Also used : NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) TreeMap(java.util.TreeMap)

Example 7 with NodeOperation

use of io.crate.execution.dsl.phases.NodeOperation in project crate by crate.

the class DocLevelCollectTest method collect.

private Bucket collect(RoutedCollectPhase collectNode) throws Throwable {
    JobSetup jobSetup = internalCluster().getDataNodeInstance(JobSetup.class);
    TasksService tasksService = internalCluster().getDataNodeInstance(TasksService.class);
    SharedShardContexts sharedShardContexts = new SharedShardContexts(internalCluster().getDataNodeInstance(IndicesService.class), UnaryOperator.identity());
    RootTask.Builder builder = tasksService.newBuilder(collectNode.jobId());
    NodeOperation nodeOperation = NodeOperation.withDirectResponse(collectNode, mock(ExecutionPhase.class), (byte) 0, "remoteNode");
    List<CompletableFuture<StreamBucket>> results = jobSetup.prepareOnRemote(DUMMY_SESSION_INFO, List.of(nodeOperation), builder, sharedShardContexts);
    RootTask rootTask = tasksService.createTask(builder);
    rootTask.start();
    return results.get(0).get(2, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) JobSetup(io.crate.execution.jobs.JobSetup) IndicesService(org.elasticsearch.indices.IndicesService) TasksService(io.crate.execution.jobs.TasksService) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) RootTask(io.crate.execution.jobs.RootTask)

Example 8 with NodeOperation

use of io.crate.execution.dsl.phases.NodeOperation in project crate by crate.

the class DistributingConsumerFactoryTest method createDownstream.

private RowConsumer createDownstream(Set<String> downstreamExecutionNodes) {
    UUID jobId = UUID.randomUUID();
    Routing routing = new Routing(Map.of("n1", Map.of("i1", IntArrayList.from(1, 2))));
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_MODULO);
    MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, 1, downstreamExecutionNodes, List.of(LongType.INSTANCE), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0);
    return rowDownstreamFactory.create(nodeOperation, RamAccounting.NO_ACCOUNTING, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Routing(io.crate.metadata.Routing) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 9 with NodeOperation

use of io.crate.execution.dsl.phases.NodeOperation 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

NodeOperation (io.crate.execution.dsl.phases.NodeOperation)9 ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)5 UUID (java.util.UUID)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Tuple (io.crate.common.collections.Tuple)3 MergePhase (io.crate.execution.dsl.phases.MergePhase)3 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)3 Routing (io.crate.metadata.Routing)3 Collection (java.util.Collection)3 IndicesService (org.elasticsearch.indices.IndicesService)3 IntContainer (com.carrotsearch.hppc.IntContainer)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)2 RowConsumer (io.crate.data.RowConsumer)2 ExecutionPhases (io.crate.execution.dsl.phases.ExecutionPhases)2 StreamBucket (io.crate.execution.engine.distribution.StreamBucket)2 RootTask (io.crate.execution.jobs.RootTask)2 SharedShardContexts (io.crate.execution.jobs.SharedShardContexts)2 TransactionContext (io.crate.metadata.TransactionContext)2 ArrayList (java.util.ArrayList)2