Search in sources :

Example 1 with CollectTask

use of io.crate.execution.engine.collect.CollectTask in project crate by crate.

the class RootTaskTest method testFailureClosesAllSubContexts.

@Test
public void testFailureClosesAllSubContexts() throws Throwable {
    String localNodeId = "localNodeId";
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    when(collectPhase.phaseId()).thenReturn(1);
    when(collectPhase.routing()).thenReturn(routing);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    RootTask.Builder builder = new RootTask.Builder(logger, UUID.randomUUID(), "dummy-user", coordinatorNode, Collections.emptySet(), mock(JobsLogs.class));
    CollectTask collectChildTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), mock(MapSideDataCollectOperation.class), RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), new TestingRowConsumer(), mock(SharedShardContexts.class), Version.CURRENT, 4096);
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    PageBucketReceiver pageBucketReceiver = new CumulativePageBucketReceiver("n1", 2, Runnable::run, new Streamer[] { IntegerType.INSTANCE.streamer() }, batchConsumer, PassThroughPagingIterator.oneShot(), 1);
    DistResultRXTask distResultRXTask = spy(new DistResultRXTask(2, "dummy", pageBucketReceiver, RamAccounting.NO_ACCOUNTING, 1));
    builder.addTask(collectChildTask);
    builder.addTask(distResultRXTask);
    RootTask rootTask = builder.build();
    Exception failure = new Exception("failure!");
    collectChildTask.kill(failure);
    // other contexts must be killed with same failure
    verify(distResultRXTask, times(1)).kill(failure);
    assertThat(rootTask.getTask(1).completionFuture().isDone(), is(true));
    assertThat(rootTask.getTask(2).completionFuture().isDone(), is(true));
}
Also used : OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) MapSideDataCollectOperation(io.crate.execution.engine.collect.MapSideDataCollectOperation) Routing(io.crate.metadata.Routing) CollectTask(io.crate.execution.engine.collect.CollectTask) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 2 with CollectTask

use of io.crate.execution.engine.collect.CollectTask in project crate by crate.

the class ShardCollectSource method getIterator.

@Override
public CompletableFuture<BatchIterator<Row>> getIterator(TransactionContext txnCtx, CollectPhase phase, CollectTask collectTask, boolean supportMoveToStart) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    String localNodeId = clusterService.localNode().getId();
    Projectors projectors = new Projectors(collectPhase.projections(), collectPhase.jobId(), collectTask.txnCtx(), collectTask.getRamAccounting(), collectTask.memoryManager(), sharedProjectorFactory);
    boolean requireMoveToStartSupport = supportMoveToStart && !projectors.providesIndependentScroll();
    if (collectPhase.maxRowGranularity() == RowGranularity.SHARD) {
        return CompletableFuture.completedFuture(projectors.wrap(InMemoryBatchIterator.of(getShardsIterator(collectTask.txnCtx(), collectPhase, localNodeId), SentinelRow.SENTINEL, true)));
    }
    OrderBy orderBy = collectPhase.orderBy();
    if (collectPhase.maxRowGranularity() == RowGranularity.DOC && orderBy != null) {
        return createMultiShardScoreDocCollector(collectPhase, requireMoveToStartSupport, collectTask, localNodeId).thenApply(projectors::wrap);
    }
    boolean hasShardProjections = Projections.hasAnyShardProjections(collectPhase.projections());
    Map<String, IntIndexedContainer> indexShards = collectPhase.routing().locations().get(localNodeId);
    List<CompletableFuture<BatchIterator<Row>>> iterators = indexShards == null ? Collections.emptyList() : getIterators(collectTask, collectPhase, requireMoveToStartSupport, indexShards);
    final CompletableFuture<BatchIterator<Row>> result;
    switch(iterators.size()) {
        case 0:
            result = CompletableFuture.completedFuture(InMemoryBatchIterator.empty(SentinelRow.SENTINEL));
            break;
        case 1:
            result = iterators.get(0);
            break;
        default:
            if (hasShardProjections) {
                // use AsyncCompositeBatchIterator for multi-threaded loadNextBatch
                // in order to process shard-based projections concurrently
                // noinspection unchecked
                result = CompletableFutures.allAsList(iterators).thenApply(its -> CompositeBatchIterator.asyncComposite(executor, availableThreads, its.toArray(new BatchIterator[0])));
            } else {
                // noinspection unchecked
                result = CompletableFutures.allAsList(iterators).thenApply(its -> CompositeBatchIterator.seqComposite(its.toArray(new BatchIterator[0])));
            }
    }
    return result.thenApply(it -> projectors.wrap(it));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ShardId(org.elasticsearch.index.shard.ShardId) IndexParts(io.crate.metadata.IndexParts) TransactionContext(io.crate.metadata.TransactionContext) Projections(io.crate.execution.dsl.projection.Projections) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) OrderedDocCollector(io.crate.execution.engine.collect.collectors.OrderedDocCollector) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NodeLimits(io.crate.execution.jobs.NodeLimits) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ProjectorFactory(io.crate.execution.engine.pipeline.ProjectorFactory) Settings(org.elasticsearch.common.settings.Settings) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ThreadPools.numIdleThreads(io.crate.execution.support.ThreadPools.numIdleThreads) OrderingByPosition(io.crate.execution.engine.sort.OrderingByPosition) ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) DocSysColumns(io.crate.metadata.doc.DocSysColumns) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeContext(io.crate.metadata.NodeContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) OrderedLuceneBatchIteratorFactory(io.crate.execution.engine.collect.collectors.OrderedLuceneBatchIteratorFactory) StaticTableReferenceResolver(io.crate.expression.reference.StaticTableReferenceResolver) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CompletableFutures(io.crate.concurrent.CompletableFutures) RowsTransformer(io.crate.execution.engine.collect.RowsTransformer) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) Iterables(io.crate.common.collections.Iterables) CollectTask(io.crate.execution.engine.collect.CollectTask) SysShardsTableInfo(io.crate.metadata.sys.SysShardsTableInfo) OrderByPositionVisitor(io.crate.planner.consumer.OrderByPositionVisitor) List(java.util.List) Exceptions(io.crate.exceptions.Exceptions) Logger(org.apache.logging.log4j.Logger) OrderBy(io.crate.analyze.OrderBy) Row(io.crate.data.Row) Singleton(org.elasticsearch.common.inject.Singleton) Projectors(io.crate.execution.engine.pipeline.Projectors) SharedShardContext(io.crate.execution.jobs.SharedShardContext) SentinelRow(io.crate.data.SentinelRow) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) RemoteCollectorFactory(io.crate.execution.engine.collect.RemoteCollectorFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ClusterService(org.elasticsearch.cluster.service.ClusterService) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) Index(org.elasticsearch.index.Index) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(org.elasticsearch.common.inject.Inject) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) Metadata(org.elasticsearch.cluster.metadata.Metadata) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) Symbols(io.crate.expression.symbol.Symbols) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) IndicesService(org.elasticsearch.indices.IndicesService) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Executor(java.util.concurrent.Executor) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) DataType(io.crate.types.DataType) ProjectionToProjectorVisitor(io.crate.execution.engine.pipeline.ProjectionToProjectorVisitor) TransportActionProvider(io.crate.execution.TransportActionProvider) RowGranularity(io.crate.metadata.RowGranularity) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) Suppliers(io.crate.common.Suppliers) InputFactory(io.crate.expression.InputFactory) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) BatchIterator(io.crate.data.BatchIterator) Projectors(io.crate.execution.engine.pipeline.Projectors) CompletableFuture(java.util.concurrent.CompletableFuture) Row(io.crate.data.Row) SentinelRow(io.crate.data.SentinelRow) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 3 with CollectTask

use of io.crate.execution.engine.collect.CollectTask in project crate by crate.

the class SystemCollectSource method getIterator.

@Override
public CompletableFuture<BatchIterator<Row>> getIterator(TransactionContext txnCtx, CollectPhase phase, CollectTask collectTask, boolean supportMoveToStart) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
    String table = Iterables.getOnlyElement(locations.get(clusterService.localNode().getId()).keySet());
    RelationName relationName = RelationName.fromIndexName(table);
    StaticTableDefinition<?> tableDefinition = tableDefinition(relationName);
    User user = requireNonNull(userLookup.findUser(txnCtx.sessionSettings().userName()), "User who invoked a statement must exist");
    return CompletableFuture.completedFuture(CollectingBatchIterator.newInstance(() -> {
    }, // If data is already local, then `CollectingBatchIterator` takes care of kill handling.
    t -> {
    }, () -> tableDefinition.retrieveRecords(txnCtx, user).thenApply(records -> recordsToRows(collectPhase, collectTask.txnCtx(), tableDefinition.getReferenceResolver(), supportMoveToStart, records)), tableDefinition.involvesIO()));
}
Also used : UserLookup(io.crate.user.UserLookup) TransactionContext(io.crate.metadata.TransactionContext) InformationSchemaTableDefinitions(io.crate.metadata.information.InformationSchemaTableDefinitions) RelationName(io.crate.metadata.RelationName) ClusterService(org.elasticsearch.cluster.service.ClusterService) BatchIterator(io.crate.data.BatchIterator) ReferenceResolver(io.crate.expression.reference.ReferenceResolver) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysRowUpdater(io.crate.expression.reference.sys.SysRowUpdater) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) SysNodeChecks(io.crate.expression.reference.sys.check.node.SysNodeChecks) SchemaUnknownException(io.crate.exceptions.SchemaUnknownException) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) PgCatalogTableDefinitions(io.crate.metadata.pgcatalog.PgCatalogTableDefinitions) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeContext(io.crate.metadata.NodeContext) User(io.crate.user.User) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) RowsTransformer(io.crate.execution.engine.collect.RowsTransformer) StaticTableDefinition(io.crate.expression.reference.StaticTableDefinition) Iterables(io.crate.common.collections.Iterables) CollectingBatchIterator(io.crate.data.CollectingBatchIterator) CollectTask(io.crate.execution.engine.collect.CollectTask) SysNodeChecksTableInfo(io.crate.metadata.sys.SysNodeChecksTableInfo) Row(io.crate.data.Row) SysTableDefinitions(io.crate.metadata.sys.SysTableDefinitions) UserManager(io.crate.user.UserManager) InputFactory(io.crate.expression.InputFactory) RelationUnknown(io.crate.exceptions.RelationUnknown) User(io.crate.user.User) RelationName(io.crate.metadata.RelationName) Map(java.util.Map) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Aggregations

RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)3 CollectTask (io.crate.execution.engine.collect.CollectTask)3 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)2 Iterables (io.crate.common.collections.Iterables)2 BatchIterator (io.crate.data.BatchIterator)2 Row (io.crate.data.Row)2 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)2 RowsTransformer (io.crate.execution.engine.collect.RowsTransformer)2 InputFactory (io.crate.expression.InputFactory)2 NodeContext (io.crate.metadata.NodeContext)2 TransactionContext (io.crate.metadata.TransactionContext)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 Inject (org.elasticsearch.common.inject.Inject)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 OrderBy (io.crate.analyze.OrderBy)1 RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)1 Suppliers (io.crate.common.Suppliers)1