Search in sources :

Example 1 with SharedShardContexts

use of io.crate.action.job.SharedShardContexts in project crate by crate.

the class FetchContextTest method testSearcherIsAcquiredForShard.

@Test
public void testSearcherIsAcquiredForShard() throws Exception {
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("dummy", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", ImmutableList.of(1, 2)).map()).map());
    IndexBaseVisitor ibv = new IndexBaseVisitor();
    routing.walkLocations(ibv);
    HashMultimap<TableIdent, String> tableIndices = HashMultimap.create();
    tableIndices.put(new TableIdent(null, "i1"), "i1");
    final FetchContext context = new FetchContext(new FetchPhase(1, null, ibv.build(), tableIndices, ImmutableList.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS)), ImmutableList.of(routing));
    context.prepare();
    assertThat(context.searcher(1), Matchers.notNullValue());
    assertThat(context.searcher(2), Matchers.notNullValue());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) SharedShardContexts(io.crate.action.job.SharedShardContexts) FetchPhase(io.crate.planner.node.fetch.FetchPhase) IndexBaseVisitor(io.crate.planner.fetch.IndexBaseVisitor) Routing(io.crate.metadata.Routing) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with SharedShardContexts

use of io.crate.action.job.SharedShardContexts in project crate by crate.

the class DocLevelCollectTest method collect.

private Bucket collect(RoutedCollectPhase collectNode) throws Throwable {
    ContextPreparer contextPreparer = internalCluster().getDataNodeInstance(ContextPreparer.class);
    JobContextService contextService = internalCluster().getDataNodeInstance(JobContextService.class);
    SharedShardContexts sharedShardContexts = new SharedShardContexts(internalCluster().getDataNodeInstance(IndicesService.class));
    JobExecutionContext.Builder builder = contextService.newBuilder(collectNode.jobId());
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectNode, mock(ExecutionPhase.class), (byte) 0, "remoteNode");
    List<CompletableFuture<Bucket>> results = contextPreparer.prepareOnRemote(ImmutableList.of(nodeOperation), builder, sharedShardContexts);
    JobExecutionContext context = contextService.createContext(builder);
    context.start();
    return results.get(0).get(2, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.action.job.SharedShardContexts) ContextPreparer(io.crate.action.job.ContextPreparer) IndicesService(org.elasticsearch.indices.IndicesService) JobExecutionContext(io.crate.jobs.JobExecutionContext) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) JobContextService(io.crate.jobs.JobContextService)

Example 3 with SharedShardContexts

use of io.crate.action.job.SharedShardContexts in project crate by crate.

the class ShardCollectSource method createMultiShardScoreDocCollector.

private CrateCollector createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext, String localNodeId) {
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    SharedShardContexts sharedShardContexts = jobCollectContext.sharedShardContexts();
    Map<String, List<Integer>> indexShards = locations.get(localNodeId);
    List<OrderedDocCollector> orderedDocCollectors = new ArrayList<>();
    for (Map.Entry<String, List<Integer>> entry : indexShards.entrySet()) {
        String indexName = entry.getKey();
        for (Integer shardNum : entry.getValue()) {
            ShardId shardId = new ShardId(indexName, shardNum);
            SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                orderedDocCollectors.add(shardCollectorProvider.getOrderedCollector(collectPhase, context, jobCollectContext, consumer.requiresScroll()));
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                throw e;
            } catch (IndexNotFoundException e) {
                if (PartitionName.isPartition(indexName)) {
                    break;
                }
                throw e;
            } catch (Throwable t) {
                throw new UnhandledServerException(t);
            }
        }
    }
    OrderBy orderBy = collectPhase.orderBy();
    assert orderBy != null : "orderBy must not be null";
    return BatchIteratorCollectorBridge.newInstance(OrderedLuceneBatchIteratorFactory.newInstance(orderedDocCollectors, collectPhase.toCollect().size(), OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), executor, consumer.requiresScroll()), consumer);
}
Also used : OrderBy(io.crate.analyze.OrderBy) ArrayList(java.util.ArrayList) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) OrderedDocCollector(io.crate.operation.collect.collectors.OrderedDocCollector) ShardId(org.elasticsearch.index.shard.ShardId) SharedShardContexts(io.crate.action.job.SharedShardContexts) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SharedShardContext(io.crate.action.job.SharedShardContext)

Example 4 with SharedShardContexts

use of io.crate.action.job.SharedShardContexts in project crate by crate.

the class ExecutionPhasesTask method setupContext.

private void setupContext(Map<String, Collection<NodeOperation>> operationByServer, List<ExecutionPhase> handlerPhases, List<BatchConsumer> 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 localJobContext which is always created
    InitializationTracker initializationTracker = new InitializationTracker(operationByServer.size() + 1);
    List<Tuple<ExecutionPhase, BatchConsumer>> handlerPhaseAndReceiver = createHandlerPhaseAndReceivers(handlerPhases, handlerConsumers, initializationTracker);
    JobExecutionContext.Builder builder = jobContextService.newBuilder(jobId(), localNodeId, operationByServer.keySet());
    List<CompletableFuture<Bucket>> directResponseFutures = contextPreparer.prepareOnHandler(localNodeOperations, builder, handlerPhaseAndReceiver, new SharedShardContexts(indicesService));
    JobExecutionContext localJobContext = jobContextService.createContext(builder);
    List<PageBucketReceiver> pageBucketReceivers = getHandlerBucketReceivers(localJobContext, 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()) {
        CompletableFutures.allAsList(directResponseFutures).whenComplete(new SetBucketCallback(pageBucketReceivers, bucketIdx, initializationTracker));
        bucketIdx++;
        try {
            // initializationTracker for localNodeOperations is triggered via SetBucketCallback
            localJobContext.start();
        } catch (Throwable t) {
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    } else {
        try {
            localJobContext.start();
            initializationTracker.jobInitialized();
        } catch (Throwable t) {
            initializationTracker.jobInitializationFailed(t);
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    }
    sendJobRequests(localNodeId, operationByServer, pageBucketReceivers, handlerPhaseAndReceiver, bucketIdx, initializationTracker);
}
Also used : NodeOperation(io.crate.operation.NodeOperation) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.action.job.SharedShardContexts) Tuple(org.elasticsearch.common.collect.Tuple)

Example 5 with SharedShardContexts

use of io.crate.action.job.SharedShardContexts in project crate by crate.

the class FetchContextTest method testGetIndexServiceForInvalidReaderId.

@Test
public void testGetIndexServiceForInvalidReaderId() throws Exception {
    final FetchContext context = new FetchContext(new FetchPhase(1, null, new TreeMap<String, Integer>(), HashMultimap.<TableIdent, String>create(), ImmutableList.<Reference>of()), "dummy", new SharedShardContexts(mock(IndicesService.class)), Collections.<Routing>emptyList());
    expectedException.expect(IllegalArgumentException.class);
    context.indexService(10);
}
Also used : SharedShardContexts(io.crate.action.job.SharedShardContexts) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference) Reference(io.crate.metadata.Reference) FetchPhase(io.crate.planner.node.fetch.FetchPhase) TableIdent(io.crate.metadata.TableIdent) TreeMap(java.util.TreeMap) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

SharedShardContexts (io.crate.action.job.SharedShardContexts)5 TableIdent (io.crate.metadata.TableIdent)2 NodeOperation (io.crate.operation.NodeOperation)2 FetchPhase (io.crate.planner.node.fetch.FetchPhase)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ContextPreparer (io.crate.action.job.ContextPreparer)1 SharedShardContext (io.crate.action.job.SharedShardContext)1 OrderBy (io.crate.analyze.OrderBy)1 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 JobContextService (io.crate.jobs.JobContextService)1 JobExecutionContext (io.crate.jobs.JobExecutionContext)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Reference (io.crate.metadata.Reference)1 Routing (io.crate.metadata.Routing)1 OrderedDocCollector (io.crate.operation.collect.collectors.OrderedDocCollector)1 IndexBaseVisitor (io.crate.planner.fetch.IndexBaseVisitor)1