Search in sources :

Example 1 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase 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 RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class SystemCollectSourceTest method testReadIsolation.

@Test
public void testReadIsolation() throws Exception {
    SystemCollectSource systemCollectSource = internalCluster().getInstance(SystemCollectSource.class);
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(ImmutableMap.of()), RowGranularity.SHARD, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    // No read isolation
    List<String> noReadIsolationIterable = new ArrayList<>();
    noReadIsolationIterable.add("a");
    noReadIsolationIterable.add("b");
    Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, false).apply(noReadIsolationIterable);
    assertThat(Iterables.size(rows), is(2));
    noReadIsolationIterable.add("c");
    assertThat(Iterables.size(rows), is(3));
    // Read isolation
    List<String> readIsolationIterable = new ArrayList<>();
    readIsolationIterable.add("a");
    readIsolationIterable.add("b");
    rows = systemCollectSource.toRowsIterableTransformation(collectPhase, true).apply(readIsolationIterable);
    assertThat(Iterables.size(rows), is(2));
    readIsolationIterable.add("c");
    assertThat(Iterables.size(rows), is(2));
}
Also used : ArrayList(java.util.ArrayList) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 3 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class ExecutionPhasesTaskTest method testGroupByServer.

@Test
public void testGroupByServer() throws Exception {
    Routing twoNodeRouting = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("node1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(1, 2)).map()).put("node2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(3, 4)).map()).map());
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    m1.executionNodes(Sets.newHashSet("node3", "node4"));
    MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    m2.executionNodes(Sets.newHashSet("node1", "node3"));
    String localNodeId = "node1";
    NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0, localNodeId);
    NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0, localNodeId);
    NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0, localNodeId);
    Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(ImmutableList.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.planner.node.dql.MergePhase) Routing(io.crate.metadata.Routing) ImmutableList(com.google.common.collect.ImmutableList) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test)

Example 4 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class RemoteCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
    consumer = new TestingBatchConsumer();
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
    remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.action.job.TransportJobAction) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) JobContextService(io.crate.jobs.JobContextService) Before(org.junit.Before)

Example 5 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class DocLevelCollectTest method testCollectWithPartitionedColumns.

@Test
public void testCollectWithPartitionedColumns() throws Throwable {
    TableIdent tableIdent = new TableIdent(Schemas.DEFAULT_SCHEMA_NAME, PARTITIONED_TABLE_NAME);
    Routing routing = schemas.getTableInfo(tableIdent).getRouting(WhereClause.MATCH_ALL, null);
    RoutedCollectPhase collectNode = getCollectNode(Arrays.<Symbol>asList(new Reference(new ReferenceIdent(tableIdent, "id"), RowGranularity.DOC, DataTypes.INTEGER), new Reference(new ReferenceIdent(tableIdent, "date"), RowGranularity.SHARD, DataTypes.TIMESTAMP)), routing, WhereClause.MATCH_ALL);
    Bucket result = collect(collectNode);
    for (Row row : result) {
        System.out.println("Row:" + Arrays.toString(row.materialize()));
    }
    assertThat(result, containsInAnyOrder(isRow(1, 0L), isRow(2, 1L)));
}
Also used : Bucket(io.crate.data.Bucket) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Row(io.crate.data.Row) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)26 Test (org.junit.Test)14 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 Routing (io.crate.metadata.Routing)8 Bucket (io.crate.data.Bucket)6 Symbol (io.crate.analyze.symbol.Symbol)4 Row (io.crate.data.Row)4 Collect (io.crate.planner.node.dql.Collect)4 ArrayList (java.util.ArrayList)4 ImmutableList (com.google.common.collect.ImmutableList)3 CollectionBucket (io.crate.data.CollectionBucket)3 InputFactory (io.crate.operation.InputFactory)3 JobsLogs (io.crate.operation.collect.stats.JobsLogs)3 Map (java.util.Map)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 OrderBy (io.crate.analyze.OrderBy)2 WhereClause (io.crate.analyze.WhereClause)2 Function (io.crate.analyze.symbol.Function)2 RamAccountingContext (io.crate.breaker.RamAccountingContext)2 BatchConsumer (io.crate.data.BatchConsumer)2