Search in sources :

Example 1 with NodeOperation

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

the class JobRequest method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeLong(jobId.getMostSignificantBits());
    out.writeLong(jobId.getLeastSignificantBits());
    out.writeString(coordinatorNodeId);
    out.writeVInt(nodeOperations.size());
    for (NodeOperation nodeOperation : nodeOperations) {
        nodeOperation.writeTo(out);
    }
    out.writeBoolean(enableProfiling);
    sessionSettings.writeTo(out);
}
Also used : NodeOperation(io.crate.execution.dsl.phases.NodeOperation)

Example 2 with NodeOperation

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

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

the class JobSetup method prepareSourceOperations.

/**
 * recursively build all contexts that depend on startPhaseId (excl. startPhaseId)
 * <p>
 * {@link Context#opCtx#targetToSourceMap} will be used to traverse the nodeOperations
 */
private void prepareSourceOperations(int startPhaseId, Context context) {
    IntContainer sourcePhaseIds = context.opCtx.targetToSourceMap.get(startPhaseId);
    if (sourcePhaseIds == null) {
        return;
    }
    for (IntCursor sourcePhaseId : sourcePhaseIds) {
        NodeOperation nodeOperation = context.opCtx.nodeOperationByPhaseId.get(sourcePhaseId.value);
        createContexts(nodeOperation.executionPhase(), context);
        context.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
    }
    for (IntCursor sourcePhaseId : sourcePhaseIds) {
        prepareSourceOperations(sourcePhaseId.value, context);
    }
}
Also used : IntContainer(com.carrotsearch.hppc.IntContainer) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) NodeOperation(io.crate.execution.dsl.phases.NodeOperation)

Example 4 with NodeOperation

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

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

the class ExecutionPhasesRootTaskTest method testGroupByServer.

@Test
public void testGroupByServer() throws Exception {
    var routingMap = new TreeMap<String, Map<String, IntIndexedContainer>>();
    routingMap.put("node1", Map.of("t1", IntArrayList.from(1, 2)));
    routingMap.put("node2", Map.of("t1", IntArrayList.from(3, 4)));
    Routing twoNodeRouting = new Routing(routingMap);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, 1, Set.of("node3", "node4"), List.of(), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, 1, Set.of("node1", "node3"), List.of(), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0);
    NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0);
    NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0);
    Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(List.of(n1, n2, n3));
    assertThat(groupByServer.containsKey("node1"), is(true));
    assertThat(groupByServer.get("node1"), Matchers.containsInAnyOrder(n1, n3));
    assertThat(groupByServer.containsKey("node2"), is(true));
    assertThat(groupByServer.get("node2"), Matchers.containsInAnyOrder(n1));
    assertThat(groupByServer.containsKey("node3"), is(true));
    assertThat(groupByServer.get("node3"), Matchers.containsInAnyOrder(n2, n3));
    assertThat(groupByServer.containsKey("node4"), is(true));
    assertThat(groupByServer.get("node4"), Matchers.containsInAnyOrder(n2));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Routing(io.crate.metadata.Routing) Collection(java.util.Collection) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) TreeMap(java.util.TreeMap) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

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