Search in sources :

Example 1 with Routing

use of io.crate.metadata.Routing 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 Routing

use of io.crate.metadata.Routing in project crate by crate.

the class FetchContextTest method testSearcherIsAcquiredForShard.

@Test
public void testSearcherIsAcquiredForShard() throws Exception {
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("dummy", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", ImmutableList.of(1, 2)).map()).map());
    IndexBaseVisitor ibv = new IndexBaseVisitor();
    routing.walkLocations(ibv);
    HashMultimap<TableIdent, String> tableIndices = HashMultimap.create();
    tableIndices.put(new TableIdent(null, "i1"), "i1");
    final FetchContext context = new FetchContext(new FetchPhase(1, null, ibv.build(), tableIndices, ImmutableList.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS)), ImmutableList.of(routing));
    context.prepare();
    assertThat(context.searcher(1), Matchers.notNullValue());
    assertThat(context.searcher(2), Matchers.notNullValue());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) SharedShardContexts(io.crate.action.job.SharedShardContexts) FetchPhase(io.crate.planner.node.fetch.FetchPhase) IndexBaseVisitor(io.crate.planner.fetch.IndexBaseVisitor) Routing(io.crate.metadata.Routing) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Routing

use of io.crate.metadata.Routing 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 Routing

use of io.crate.metadata.Routing 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 Routing

use of io.crate.metadata.Routing in project crate by crate.

the class JobCollectContextTest method testThreadPoolNameForNonDocTables.

@Test
public void testThreadPoolNameForNonDocTables() throws Exception {
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(collectPhase.routing()).thenReturn(routing);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // sys.cluster (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.CLUSTER);
    String threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // partition values only of a partitioned doc table (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.PARTITION);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // sys.nodes (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.NODE);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    // sys.shards
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.SHARD);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // information_schema.*
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
}
Also used : Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

Routing (io.crate.metadata.Routing)41 Test (org.junit.Test)23 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)18 Reference (io.crate.metadata.Reference)9 RelationName (io.crate.metadata.RelationName)8 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)8 ArrayList (java.util.ArrayList)7 Symbol (io.crate.expression.symbol.Symbol)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 List (java.util.List)6 Map (java.util.Map)6 UUID (java.util.UUID)6 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)5 Row (io.crate.data.Row)5 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)5 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)5 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)5 ImmutableList (com.google.common.collect.ImmutableList)4 WhereClause (io.crate.analyze.WhereClause)4 TableInfo (io.crate.metadata.table.TableInfo)4