Search in sources :

Example 1 with ExecutionPhase

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

the class JobLauncher method executeBulk.

public List<CompletableFuture<Long>> executeBulk(TransactionContext txnCtx) {
    Iterable<NodeOperation> nodeOperations = nodeOperationTrees.stream().flatMap(opTree -> opTree.nodeOperations().stream())::iterator;
    Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperations);
    List<ExecutionPhase> handlerPhases = new ArrayList<>(nodeOperationTrees.size());
    List<RowConsumer> handlerConsumers = new ArrayList<>(nodeOperationTrees.size());
    List<CompletableFuture<Long>> results = new ArrayList<>(nodeOperationTrees.size());
    for (NodeOperationTree nodeOperationTree : nodeOperationTrees) {
        CollectingRowConsumer<?, Long> consumer = new CollectingRowConsumer<>(Collectors.collectingAndThen(Collectors.summingLong(r -> ((long) r.get(0))), sum -> sum));
        handlerConsumers.add(consumer);
        results.add(consumer.completionFuture());
        handlerPhases.add(nodeOperationTree.leaf());
    }
    try {
        setupTasks(txnCtx, operationByServer, handlerPhases, handlerConsumers);
    } catch (Throwable throwable) {
        return Collections.singletonList(CompletableFuture.failedFuture(throwable));
    }
    return results;
}
Also used : TransactionContext(io.crate.metadata.TransactionContext) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) Tuple(io.crate.common.collections.Tuple) ListIterator(java.util.ListIterator) Task(io.crate.execution.jobs.Task) ClusterService(org.elasticsearch.cluster.service.ClusterService) ProfilingContext(io.crate.profile.ProfilingContext) CompletableFuture(java.util.concurrent.CompletableFuture) UnaryOperator(java.util.function.UnaryOperator) RootTask(io.crate.execution.jobs.RootTask) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) ArrayList(java.util.ArrayList) JobRequest(io.crate.execution.jobs.transport.JobRequest) JobSetup(io.crate.execution.jobs.JobSetup) Map(java.util.Map) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) IndicesService(org.elasticsearch.indices.IndicesService) TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) NodeOperationGrouper(io.crate.execution.dsl.phases.NodeOperationGrouper) DownstreamRXTask(io.crate.execution.jobs.DownstreamRXTask) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) CompletableFutures(io.crate.concurrent.CompletableFutures) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler) TasksService(io.crate.execution.jobs.TasksService) RowConsumer(io.crate.data.RowConsumer) List(java.util.List) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhases(io.crate.execution.dsl.phases.ExecutionPhases) Collections(java.util.Collections) ArrayList(java.util.ArrayList) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) CompletableFuture(java.util.concurrent.CompletableFuture) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) Collection(java.util.Collection) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) RowConsumer(io.crate.data.RowConsumer) CollectingRowConsumer(io.crate.data.CollectingRowConsumer)

Example 2 with ExecutionPhase

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

the class JobLauncher method getHandlerBucketReceivers.

private List<PageBucketReceiver> getHandlerBucketReceivers(RootTask rootTask, List<Tuple<ExecutionPhase, RowConsumer>> handlerPhases) {
    final List<PageBucketReceiver> pageBucketReceivers = new ArrayList<>(handlerPhases.size());
    for (Tuple<ExecutionPhase, ?> handlerPhase : handlerPhases) {
        Task ctx = rootTask.getTaskOrNull(handlerPhase.v1().phaseId());
        if (ctx instanceof DownstreamRXTask) {
            PageBucketReceiver pageBucketReceiver = ((DownstreamRXTask) ctx).getBucketReceiver((byte) 0);
            pageBucketReceivers.add(pageBucketReceiver);
        }
    }
    return pageBucketReceivers;
}
Also used : Task(io.crate.execution.jobs.Task) RootTask(io.crate.execution.jobs.RootTask) DownstreamRXTask(io.crate.execution.jobs.DownstreamRXTask) PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) ArrayList(java.util.ArrayList) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) DownstreamRXTask(io.crate.execution.jobs.DownstreamRXTask)

Example 3 with ExecutionPhase

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

the class JobLauncher method createHandlerPhaseAndReceivers.

private List<Tuple<ExecutionPhase, RowConsumer>> createHandlerPhaseAndReceivers(List<ExecutionPhase> handlerPhases, List<RowConsumer> handlerReceivers, InitializationTracker initializationTracker) {
    List<Tuple<ExecutionPhase, RowConsumer>> handlerPhaseAndReceiver = new ArrayList<>();
    ListIterator<RowConsumer> consumerIt = handlerReceivers.listIterator();
    for (ExecutionPhase handlerPhase : handlerPhases) {
        InterceptingRowConsumer interceptingBatchConsumer = new InterceptingRowConsumer(jobId, consumerIt.next(), initializationTracker, executor, transportKillJobsNodeAction);
        handlerPhaseAndReceiver.add(new Tuple<>(handlerPhase, interceptingBatchConsumer));
    }
    return handlerPhaseAndReceiver;
}
Also used : ArrayList(java.util.ArrayList) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) RowConsumer(io.crate.data.RowConsumer) Tuple(io.crate.common.collections.Tuple)

Example 4 with ExecutionPhase

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

the class JobSetup method registerContextPhases.

private void registerContextPhases(Iterable<? extends NodeOperation> nodeOperations, Context context) {
    for (NodeOperation nodeOperation : nodeOperations) {
        // context for nodeOperations without dependencies can be built immediately (e.g. FetchPhase)
        if (nodeOperation.downstreamExecutionPhaseId() == NodeOperation.NO_DOWNSTREAM) {
            LOGGER.trace("Building context for nodeOp without downstream: {}", nodeOperation);
            createContexts(nodeOperation.executionPhase(), context);
            context.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
        }
        if (ExecutionPhases.hasDirectResponseDownstream(nodeOperation.downstreamNodes())) {
            var executionPhase = nodeOperation.executionPhase();
            CircuitBreaker breaker = breaker();
            int ramAccountingBlockSizeInBytes = BlockBasedRamAccounting.blockSizeInBytes(breaker.getLimit());
            var ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, executionPhase.label()), ramAccountingBlockSizeInBytes);
            Streamer<?>[] streamers = StreamerVisitor.streamersFromOutputs(executionPhase);
            SingleBucketBuilder bucketBuilder = new SingleBucketBuilder(streamers, ramAccounting);
            context.directResponseFutures.add(bucketBuilder.completionFuture().whenComplete((res, err) -> ramAccounting.close()));
            context.registerBatchConsumer(nodeOperation.downstreamExecutionPhaseId(), bucketBuilder);
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DistributionType(io.crate.planner.distribution.DistributionType) SessionSettings(io.crate.metadata.settings.SessionSettings) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Projections.nodeProjections(io.crate.execution.dsl.projection.Projections.nodeProjections) MapSideDataCollectOperation(io.crate.execution.engine.collect.MapSideDataCollectOperation) ProjectorFactory(io.crate.execution.engine.pipeline.ProjectorFactory) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Projections.shardProjections(io.crate.execution.dsl.projection.Projections.shardProjections) IntArrayList(com.carrotsearch.hppc.IntArrayList) Map(java.util.Map) Collector(java.util.stream.Collector) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) ProjectingRowConsumer(io.crate.execution.engine.pipeline.ProjectingRowConsumer) PKLookupOperation(io.crate.execution.engine.collect.PKLookupOperation) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) IntObjectCursor(com.carrotsearch.hppc.cursors.IntObjectCursor) Tuple(io.crate.common.collections.Tuple) NestedLoopOperation(io.crate.execution.engine.join.NestedLoopOperation) ClusterService(org.elasticsearch.cluster.service.ClusterService) Operation(io.crate.metadata.table.Operation) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ArrayList(java.util.ArrayList) Routing(io.crate.metadata.Routing) RowCellsAccountingWithEstimators(io.crate.breaker.RowCellsAccountingWithEstimators) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) IndicesService(org.elasticsearch.indices.IndicesService) LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) Nullable(javax.annotation.Nullable) Executor(java.util.concurrent.Executor) SystemCollectSource(io.crate.execution.engine.collect.sources.SystemCollectSource) RamAccounting(io.crate.breaker.RamAccounting) IncrementalPageBucketReceiver(io.crate.execution.IncrementalPageBucketReceiver) ConcurrentRamAccounting(io.crate.breaker.ConcurrentRamAccounting) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Schemas(io.crate.metadata.Schemas) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) AggregationPipe(io.crate.execution.engine.aggregation.AggregationPipe) InputFactory(io.crate.expression.InputFactory) MemoryManagerFactory(io.crate.memory.MemoryManagerFactory) TransactionContext(io.crate.metadata.TransactionContext) PKAndVersion(io.crate.planner.operators.PKAndVersion) HashJoinPhase(io.crate.execution.dsl.phases.HashJoinPhase) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) MergePhase(io.crate.execution.dsl.phases.MergePhase) Settings(org.elasticsearch.common.settings.Settings) DistributingConsumerFactory(io.crate.execution.engine.distribution.DistributingConsumerFactory) Locale(java.util.Locale) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LongObjectMap(com.carrotsearch.hppc.LongObjectMap) NodeContext(io.crate.metadata.NodeContext) HashJoinOperation(io.crate.execution.engine.join.HashJoinOperation) Streamer(io.crate.Streamer) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IntContainer(com.carrotsearch.hppc.IntContainer) NestedLoopPhase(io.crate.execution.dsl.phases.NestedLoopPhase) UUID(java.util.UUID) CollectTask(io.crate.execution.engine.collect.CollectTask) Objects(java.util.Objects) List(java.util.List) ExecutionPhaseVisitor(io.crate.execution.dsl.phases.ExecutionPhaseVisitor) Projection(io.crate.execution.dsl.projection.Projection) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Paging(io.crate.data.Paging) FetchTask(io.crate.execution.engine.fetch.FetchTask) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) SingleBucketBuilder(io.crate.execution.engine.distribution.SingleBucketBuilder) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) CompletableFuture(java.util.concurrent.CompletableFuture) CountPhase(io.crate.execution.dsl.phases.CountPhase) Inject(org.elasticsearch.common.inject.Inject) ObjectProcedure(com.carrotsearch.hppc.procedures.ObjectProcedure) Node(org.elasticsearch.node.Node) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) PKLookupPhase(io.crate.execution.dsl.phases.PKLookupPhase) UpstreamPhase(io.crate.execution.dsl.phases.UpstreamPhase) CountOperation(io.crate.execution.engine.collect.count.CountOperation) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) StreamerVisitor(io.crate.planner.node.StreamerVisitor) IntHashSet(com.carrotsearch.hppc.IntHashSet) ShardCollectSource(io.crate.execution.engine.collect.sources.ShardCollectSource) IntCollection(com.carrotsearch.hppc.IntCollection) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) ProjectionToProjectorVisitor(io.crate.execution.engine.pipeline.ProjectionToProjectorVisitor) MemoryManager(io.crate.memory.MemoryManager) TransportActionProvider(io.crate.execution.TransportActionProvider) PagingIterator(io.crate.execution.engine.distribution.merge.PagingIterator) IntObjectMap(com.carrotsearch.hppc.IntObjectMap) RowConsumer(io.crate.data.RowConsumer) RowFilter(io.crate.expression.RowFilter) BitSet(java.util.BitSet) ExecutionPhases(io.crate.execution.dsl.phases.ExecutionPhases) LogManager(org.apache.logging.log4j.LogManager) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Streamer(io.crate.Streamer) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) SingleBucketBuilder(io.crate.execution.engine.distribution.SingleBucketBuilder)

Example 5 with ExecutionPhase

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

the class NodeOperationCtxTest method testFindLeafs.

@Test
public void testFindLeafs() {
    ExecutionPhase p1 = newPhase(0, "n1", "n2");
    ExecutionPhase p2 = newPhase(1, "n1", "n2");
    ExecutionPhase p3 = newPhase(2, "n2");
    NodeOperationCtx opCtx = new NodeOperationCtx("n1", List.of(NodeOperation.withDownstream(p1, p2, (byte) 0), NodeOperation.withDownstream(p2, p3, (byte) 0)));
    assertThat(opCtx.findLeafs(), is(IntArrayList.from(2)));
}
Also used : ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) NodeOperationCtx(io.crate.execution.jobs.JobSetup.NodeOperationCtx) Test(org.junit.Test)

Aggregations

ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)12 RowConsumer (io.crate.data.RowConsumer)5 NodeOperationCtx (io.crate.execution.jobs.JobSetup.NodeOperationCtx)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Tuple (io.crate.common.collections.Tuple)3 CollectingRowConsumer (io.crate.data.CollectingRowConsumer)3 NodeOperation (io.crate.execution.dsl.phases.NodeOperation)3 TransactionContext (io.crate.metadata.TransactionContext)3 Collection (java.util.Collection)3 IntHashSet (com.carrotsearch.hppc.IntHashSet)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)2 ExecutionPhases (io.crate.execution.dsl.phases.ExecutionPhases)2 StreamBucket (io.crate.execution.engine.distribution.StreamBucket)2 DownstreamRXTask (io.crate.execution.jobs.DownstreamRXTask)2 PageBucketReceiver (io.crate.execution.jobs.PageBucketReceiver)2 RootTask (io.crate.execution.jobs.RootTask)2 Task (io.crate.execution.jobs.Task)2 List (java.util.List)2 Map (java.util.Map)2