Search in sources :

Example 6 with SharedShardContexts

use of io.crate.execution.jobs.SharedShardContexts 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 7 with SharedShardContexts

use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.

the class JobLauncher method setupTasks.

private void setupTasks(TransactionContext txnCtx, Map<String, Collection<NodeOperation>> operationByServer, List<ExecutionPhase> handlerPhases, List<RowConsumer> handlerConsumers) throws Throwable {
    assert handlerPhases.size() == handlerConsumers.size() : "handlerPhases size must match handlerConsumers size";
    String localNodeId = clusterService.localNode().getId();
    Collection<NodeOperation> localNodeOperations = operationByServer.remove(localNodeId);
    if (localNodeOperations == null) {
        localNodeOperations = Collections.emptyList();
    }
    // + 1 for localTask which is always created
    InitializationTracker initializationTracker = new InitializationTracker(operationByServer.size() + 1);
    List<Tuple<ExecutionPhase, RowConsumer>> handlerPhaseAndReceiver = createHandlerPhaseAndReceivers(handlerPhases, handlerConsumers, initializationTracker);
    RootTask.Builder builder = tasksService.newBuilder(jobId, txnCtx.sessionSettings().userName(), localNodeId, operationByServer.keySet());
    SharedShardContexts sharedShardContexts = maybeInstrumentProfiler(builder);
    List<CompletableFuture<StreamBucket>> directResponseFutures = jobSetup.prepareOnHandler(txnCtx.sessionSettings(), localNodeOperations, builder, handlerPhaseAndReceiver, sharedShardContexts);
    RootTask localTask = tasksService.createTask(builder);
    List<PageBucketReceiver> pageBucketReceivers = getHandlerBucketReceivers(localTask, handlerPhaseAndReceiver);
    int bucketIdx = 0;
    /*
         * If you touch anything here make sure the following tests pass with > 1k iterations:
         *
         * Seed: 112E1807417E925A - testInvalidPatternSyntax
         * Seed: Any              - testRegularSelectWithFewAvailableThreadsShouldNeverGetStuck
         * Seed: CC456FF5004F35D3 - testFailureOfJoinDownstream
         */
    if (!localNodeOperations.isEmpty() && !directResponseFutures.isEmpty()) {
        assert directResponseFutures.size() == pageBucketReceivers.size() : "directResponses size must match pageBucketReceivers";
        CompletableFutures.allAsList(directResponseFutures).whenComplete(BucketForwarder.asConsumer(pageBucketReceivers, bucketIdx, initializationTracker));
        bucketIdx++;
        try {
            // initializationTracker for localNodeOperations is triggered via SetBucketCallback
            localTask.start();
        } catch (Throwable t) {
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    } else {
        try {
            localTask.start();
            initializationTracker.jobInitialized();
        } catch (Throwable t) {
            initializationTracker.jobInitializationFailed(t);
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    }
    sendJobRequests(txnCtx, localNodeId, operationByServer, pageBucketReceivers, handlerPhaseAndReceiver, bucketIdx, initializationTracker);
}
Also used : NodeOperation(io.crate.execution.dsl.phases.NodeOperation) RootTask(io.crate.execution.jobs.RootTask) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) Tuple(io.crate.common.collections.Tuple)

Example 8 with SharedShardContexts

use of io.crate.execution.jobs.SharedShardContexts in project crate by crate.

the class TransportJobAction method nodeOperation.

@Override
public CompletableFuture<JobResponse> nodeOperation(final JobRequest request) {
    RootTask.Builder contextBuilder = tasksService.newBuilder(request.jobId(), request.sessionSettings().userName(), request.coordinatorNodeId(), Collections.emptySet());
    SharedShardContexts sharedShardContexts = maybeInstrumentProfiler(request.enableProfiling(), contextBuilder);
    List<CompletableFuture<StreamBucket>> directResponseFutures = jobSetup.prepareOnRemote(request.sessionSettings(), request.nodeOperations(), contextBuilder, sharedShardContexts);
    try {
        RootTask context = tasksService.createTask(contextBuilder);
        context.start();
    } catch (Throwable t) {
        return CompletableFuture.failedFuture(t);
    }
    if (directResponseFutures.size() == 0) {
        return CompletableFuture.completedFuture(new JobResponse(List.of()));
    } else {
        return CompletableFutures.allAsList(directResponseFutures).thenApply(JobResponse::new);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) 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