Search in sources :

Example 1 with SharedShardContexts

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());
    }
}
Also used : InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ArrayList(java.util.ArrayList) ProfilingContext(io.crate.profile.ProfilingContext) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler)

Example 2 with SharedShardContexts

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));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DataType(io.crate.types.DataType) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SharedShardContext(io.crate.execution.jobs.SharedShardContext)

Example 3 with SharedShardContexts

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());
    }
}
Also used : InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ArrayList(java.util.ArrayList) ProfilingContext(io.crate.profile.ProfilingContext) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler)

Example 4 with SharedShardContexts

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);
}
Also used : SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) HashMap(java.util.HashMap) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) TreeMap(java.util.TreeMap) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with SharedShardContexts

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) JobSetup(io.crate.execution.jobs.JobSetup) IndicesService(org.elasticsearch.indices.IndicesService) TasksService(io.crate.execution.jobs.TasksService) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) RootTask(io.crate.execution.jobs.RootTask)

Aggregations

SharedShardContexts (io.crate.execution.jobs.SharedShardContexts)8 CompletableFuture (java.util.concurrent.CompletableFuture)4 RootTask (io.crate.execution.jobs.RootTask)3 ArrayList (java.util.ArrayList)3 FetchPhase (io.crate.execution.dsl.phases.FetchPhase)2 NodeOperation (io.crate.execution.dsl.phases.NodeOperation)2 InstrumentedIndexSearcher (io.crate.execution.jobs.InstrumentedIndexSearcher)2 ProfilingContext (io.crate.profile.ProfilingContext)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 HashMap (java.util.HashMap)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Metadata (org.elasticsearch.cluster.metadata.Metadata)2 QueryProfiler (org.elasticsearch.search.profile.query.QueryProfiler)2 Test (org.junit.Test)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 OrderBy (io.crate.analyze.OrderBy)1 RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)1 Tuple (io.crate.common.collections.Tuple)1