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));
}
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()));
}
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());
}
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);
}
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));
}
Aggregations