use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.
the class TransportJobAction method maybeInstrumentProfiler.
private SharedShardContexts maybeInstrumentProfiler(boolean enableProfiling, RootTask.Builder contextBuilder) {
if (enableProfiling) {
var profilers = new ArrayList<QueryProfiler>();
ProfilingContext profilingContext = new ProfilingContext(profilers);
contextBuilder.profilingContext(profilingContext);
return new SharedShardContexts(indicesService, indexSearcher -> {
var queryProfiler = new QueryProfiler();
profilers.add(queryProfiler);
return new InstrumentedIndexSearcher(indexSearcher, queryProfiler);
});
} else {
return new SharedShardContexts(indicesService, UnaryOperator.identity());
}
}
use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.
the class ShardCollectSource method createMultiShardScoreDocCollector.
private CompletableFuture<BatchIterator<Row>> createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, boolean supportMoveToStart, CollectTask collectTask, String localNodeId) {
Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
SharedShardContexts sharedShardContexts = collectTask.sharedShardContexts();
Map<String, IntIndexedContainer> indexShards = locations.get(localNodeId);
List<CompletableFuture<OrderedDocCollector>> orderedDocCollectors = new ArrayList<>();
Metadata metadata = clusterService.state().metadata();
for (Map.Entry<String, IntIndexedContainer> entry : indexShards.entrySet()) {
String indexName = entry.getKey();
Index index = metadata.index(indexName).getIndex();
for (IntCursor shard : entry.getValue()) {
ShardId shardId = new ShardId(index, shard.value);
try {
SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
orderedDocCollectors.add(shardCollectorProvider.getFutureOrderedCollector(collectPhase, context, collectTask, supportMoveToStart));
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
throw e;
} catch (IndexNotFoundException e) {
if (IndexParts.isPartitioned(indexName)) {
break;
}
throw e;
}
}
}
List<DataType<?>> columnTypes = Symbols.typeView(collectPhase.toCollect());
OrderBy orderBy = collectPhase.orderBy();
assert orderBy != null : "orderBy must not be null";
return CompletableFutures.allAsList(orderedDocCollectors).thenApply(collectors -> OrderedLuceneBatchIteratorFactory.newInstance(collectors, OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), new RowAccountingWithEstimators(columnTypes, collectTask.getRamAccounting()), executor, availableThreads, supportMoveToStart));
}
use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.
the class JobLauncher method maybeInstrumentProfiler.
private SharedShardContexts maybeInstrumentProfiler(RootTask.Builder builder) {
if (enableProfiling) {
var profilers = new ArrayList<QueryProfiler>();
ProfilingContext profilingContext = new ProfilingContext(profilers);
builder.profilingContext(profilingContext);
return new SharedShardContexts(indicesService, indexSearcher -> {
var queryProfiler = new QueryProfiler();
profilers.add(queryProfiler);
return new InstrumentedIndexSearcher(indexSearcher, queryProfiler);
});
} else {
return new SharedShardContexts(indicesService, UnaryOperator.identity());
}
}
use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.
the class FetchTaskTest method testGetIndexServiceForInvalidReaderId.
@Test
public void testGetIndexServiceForInvalidReaderId() throws Exception {
final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, new TreeMap<>(), new HashMap<>(), List.of()), "dummy", new SharedShardContexts(mock(IndicesService.class), UnaryOperator.identity()), clusterService.state().getMetadata(), relationName -> null, Collections.emptyList());
expectedException.expect(IllegalArgumentException.class);
context.indexService(10);
}
use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.
the class DocLevelCollectTest method collect.
private Bucket collect(RoutedCollectPhase collectNode) throws Throwable {
JobSetup jobSetup = internalCluster().getDataNodeInstance(JobSetup.class);
TasksService tasksService = internalCluster().getDataNodeInstance(TasksService.class);
SharedShardContexts sharedShardContexts = new SharedShardContexts(internalCluster().getDataNodeInstance(IndicesService.class), UnaryOperator.identity());
RootTask.Builder builder = tasksService.newBuilder(collectNode.jobId());
NodeOperation nodeOperation = NodeOperation.withDirectResponse(collectNode, mock(ExecutionPhase.class), (byte) 0, "remoteNode");
List<CompletableFuture<StreamBucket>> results = jobSetup.prepareOnRemote(DUMMY_SESSION_INFO, List.of(nodeOperation), builder, sharedShardContexts);
RootTask rootTask = tasksService.createTask(builder);
rootTask.start();
return results.get(0).get(2, TimeUnit.SECONDS);
}
Aggregations