Search in sources :

Example 36 with Routing

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

the class BlobShardCollectorProviderTest method testReadIsolation.

@Test
public void testReadIsolation() throws Exception {
    execute("create blob table b1 clustered into 1 shards with (number_of_replicas = 0)");
    upload("b1", "foo");
    upload("b1", "bar");
    ensureGreen();
    assertBusy(new Initializer());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Map.of()), RowGranularity.SHARD, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    // No read Isolation
    Iterable<Row> iterable = getBlobRows(collectPhase, false);
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(2L));
    upload("b1", "newEntry1");
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
    // Read isolation
    iterable = getBlobRows(collectPhase, true);
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
    upload("b1", "newEntry2");
    assertThat(StreamSupport.stream(iterable.spliterator(), false).count(), is(3L));
}
Also used : Routing(io.crate.metadata.Routing) Row(io.crate.data.Row) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) SQLHttpIntegrationTest(io.crate.integrationtests.SQLHttpIntegrationTest) Test(org.junit.Test)

Example 37 with Routing

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

the class RoutedCollectPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    List<Symbol> toCollect = List.of(Literal.of(DataTypes.STRING, null));
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase cn = new RoutedCollectPhase(jobId, 0, "cn", new Routing(Map.of()), RowGranularity.DOC, toCollect, List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_MODULO);
    BytesStreamOutput out = new BytesStreamOutput();
    cn.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    RoutedCollectPhase cn2 = new RoutedCollectPhase(in);
    assertThat(cn, equalTo(cn2));
    assertThat(cn.toCollect(), is(cn2.toCollect()));
    assertThat(cn.nodeIds(), is(cn2.nodeIds()));
    assertThat(cn.jobId(), is(cn2.jobId()));
    assertThat(cn.phaseId(), is(cn2.phaseId()));
    assertThat(cn.maxRowGranularity(), is(cn2.maxRowGranularity()));
    assertThat(cn.distributionInfo(), is(cn2.distributionInfo()));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) UUID(java.util.UUID) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 38 with Routing

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

the class FetchTaskTest method testSearcherIsAcquiredForShard.

@Test
public void testSearcherIsAcquiredForShard() throws Exception {
    IntArrayList shards = IntArrayList.from(1, 2);
    Routing routing = new Routing(Map.of("dummy", Map.of("i1", shards)));
    IndexBaseBuilder ibb = new IndexBaseBuilder();
    ibb.allocate("i1", shards);
    Map<RelationName, Collection<String>> tableIndices = new HashMap<>();
    tableIndices.put(new RelationName(Schemas.DOC_SCHEMA_NAME, "i1"), List.of("i1"));
    Metadata metadata = Metadata.builder().put(IndexMetadata.builder("i1").settings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_VERSION_CREATED, Version.CURRENT)).build(), true).build();
    final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, ibb.build(), tableIndices, List.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS), UnaryOperator.identity()), metadata, relationName -> null, List.of(routing));
    context.start();
    assertThat(context.searcher(1), Matchers.notNullValue());
    assertThat(context.searcher(2), Matchers.notNullValue());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) HashMap(java.util.HashMap) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) Routing(io.crate.metadata.Routing) RelationName(io.crate.metadata.RelationName) Collection(java.util.Collection) IntArrayList(com.carrotsearch.hppc.IntArrayList) IndexBaseBuilder(io.crate.planner.fetch.IndexBaseBuilder) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 39 with Routing

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

the class DistributingConsumerFactoryTest method createDownstream.

private RowConsumer createDownstream(Set<String> downstreamExecutionNodes) {
    UUID jobId = UUID.randomUUID();
    Routing routing = new Routing(Map.of("n1", Map.of("i1", IntArrayList.from(1, 2))));
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_MODULO);
    MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, 1, downstreamExecutionNodes, List.of(LongType.INSTANCE), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0);
    return rowDownstreamFactory.create(nodeOperation, RamAccounting.NO_ACCOUNTING, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Routing(io.crate.metadata.Routing) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 40 with Routing

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

the class UpdatePlanner method createCollectAndMerge.

private static ExecutionPlan createCollectAndMerge(PlannerContext plannerCtx, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause where, int numOutPuts, int maxRowsPerNode, Projection... mergeProjections) {
    SessionContext sessionContext = plannerCtx.transactionContext().sessionContext();
    Routing routing = plannerCtx.allocateRouting(tableInfo, where, RoutingProvider.ShardSelection.PRIMARIES, sessionContext);
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerCtx.jobId(), plannerCtx.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), List.of(idReference), singletonList(updateProjection), Optimizer.optimizeCasts(where.queryOrFallback(), plannerCtx), DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, numOutPuts, maxRowsPerNode, null);
    return Merge.ensureOnHandler(collect, plannerCtx, List.of(mergeProjections));
}
Also used : Collect(io.crate.planner.node.dql.Collect) SessionContext(io.crate.action.sql.SessionContext) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

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