Search in sources :

Example 1 with JobCollectContext

use of io.crate.operation.collect.JobCollectContext in project crate by crate.

the class JobExecutionContextTest method testFailureClosesAllSubContexts.

@Test
public void testFailureClosesAllSubContexts() throws Exception {
    String localNodeId = "localNodeId";
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    when(collectPhase.routing()).thenReturn(routing);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    JobExecutionContext.Builder builder = new JobExecutionContext.Builder(UUID.randomUUID(), coordinatorNode, Collections.emptyList(), mock(JobsLogs.class));
    JobCollectContext jobCollectContext = new JobCollectContext(collectPhase, mock(MapSideDataCollectOperation.class), localNodeId, mock(RamAccountingContext.class), new TestingBatchConsumer(), mock(SharedShardContexts.class));
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    PageDownstreamContext pageDownstreamContext = spy(new PageDownstreamContext(Loggers.getLogger(PageDownstreamContext.class), "n1", 2, "dummy", batchConsumer, PassThroughPagingIterator.oneShot(), new Streamer[] { IntegerType.INSTANCE.streamer() }, mock(RamAccountingContext.class), 1));
    builder.addSubContext(jobCollectContext);
    builder.addSubContext(pageDownstreamContext);
    JobExecutionContext jobExecutionContext = builder.build();
    Exception failure = new Exception("failure!");
    jobCollectContext.close(failure);
    // other contexts must be killed with same failure
    verify(pageDownstreamContext, times(1)).innerKill(failure);
    final Field subContexts = JobExecutionContext.class.getDeclaredField("subContexts");
    subContexts.setAccessible(true);
    int size = ((ConcurrentMap<Integer, ExecutionSubContext>) subContexts.get(jobExecutionContext)).size();
    assertThat(size, is(0));
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext) MapSideDataCollectOperation(io.crate.operation.collect.MapSideDataCollectOperation) ConcurrentMap(java.util.concurrent.ConcurrentMap) Routing(io.crate.metadata.Routing) JobCollectContext(io.crate.operation.collect.JobCollectContext) Field(java.lang.reflect.Field) SharedShardContexts(io.crate.action.job.SharedShardContexts) Streamer(io.crate.Streamer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with JobCollectContext

use of io.crate.operation.collect.JobCollectContext in project crate by crate.

the class SystemCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    // sys.operations can contain a _node column - these refs need to be normalized into literals
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, ReplaceMode.COPY, new NodeSysReferenceResolver(nodeSysExpression), null);
    final RoutedCollectPhase routedCollectPhase = collectPhase.normalize(normalizer, null);
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    String table = Iterables.getOnlyElement(locations.get(clusterService.localNode().getId()).keySet());
    Supplier<CompletableFuture<? extends Iterable<?>>> iterableGetter = iterableGetters.get(table);
    assert iterableGetter != null : "iterableGetter for " + table + " must exist";
    boolean requiresScroll = consumer.requiresScroll();
    return BatchIteratorCollectorBridge.newInstance(() -> iterableGetter.get().thenApply(dataIterable -> RowsBatchIterator.newInstance(dataIterableToRowsIterable(routedCollectPhase, requiresScroll, dataIterable), collectPhase.toCollect().size())), consumer);
}
Also used : BatchIteratorCollectorBridge(io.crate.operation.collect.BatchIteratorCollectorBridge) Iterables(com.google.common.collect.Iterables) CompletableFuture(java.util.concurrent.CompletableFuture) ReplaceMode(io.crate.metadata.ReplaceMode) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) JobCollectContext(io.crate.operation.collect.JobCollectContext) SysSnapshots(io.crate.operation.reference.sys.snapshot.SysSnapshots) ImmutableList(com.google.common.collect.ImmutableList) Functions(io.crate.metadata.Functions) BatchConsumer(io.crate.data.BatchConsumer) io.crate.metadata.sys(io.crate.metadata.sys) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver) ClusterService(org.elasticsearch.cluster.ClusterService) Map(java.util.Map) SysRowUpdater(io.crate.operation.reference.sys.SysRowUpdater) SysRepositoriesService(io.crate.operation.reference.sys.repositories.SysRepositoriesService) RowsBatchIterator(io.crate.data.RowsBatchIterator) CrateCollector(io.crate.operation.collect.CrateCollector) SysCheck(io.crate.operation.reference.sys.check.SysCheck) ImmutableMap(com.google.common.collect.ImmutableMap) RowsTransformer(io.crate.operation.collect.RowsTransformer) Set(java.util.Set) SysChecker(io.crate.operation.reference.sys.check.SysChecker) TableIdent(io.crate.metadata.TableIdent) RowContextReferenceResolver(io.crate.operation.reference.sys.RowContextReferenceResolver) JobsLogs(io.crate.operation.collect.stats.JobsLogs) CollectPhase(io.crate.planner.node.dql.CollectPhase) PgCatalogTables(io.crate.metadata.pg_catalog.PgCatalogTables) InputFactory(io.crate.operation.InputFactory) SysNodeChecks(io.crate.operation.reference.sys.check.node.SysNodeChecks) io.crate.metadata.information(io.crate.metadata.information) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) List(java.util.List) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) NodeSysExpression(io.crate.operation.reference.sys.node.local.NodeSysExpression) PgTypeTable(io.crate.metadata.pg_catalog.PgTypeTable) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) CompletableFuture(java.util.concurrent.CompletableFuture) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver)

Aggregations

JobCollectContext (io.crate.operation.collect.JobCollectContext)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Streamer (io.crate.Streamer)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 EvaluatingNormalizer (io.crate.analyze.EvaluatingNormalizer)1 RamAccountingContext (io.crate.breaker.RamAccountingContext)1 BatchConsumer (io.crate.data.BatchConsumer)1 Row (io.crate.data.Row)1 RowsBatchIterator (io.crate.data.RowsBatchIterator)1 Functions (io.crate.metadata.Functions)1 ReplaceMode (io.crate.metadata.ReplaceMode)1 Routing (io.crate.metadata.Routing)1 RowGranularity (io.crate.metadata.RowGranularity)1 TableIdent (io.crate.metadata.TableIdent)1 io.crate.metadata.information (io.crate.metadata.information)1 PgCatalogTables (io.crate.metadata.pg_catalog.PgCatalogTables)1