Search in sources :

Example 1 with NodeOperation

use of io.crate.operation.NodeOperation in project crate by crate.

the class JobRequest method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeLong(jobId.getMostSignificantBits());
    out.writeLong(jobId.getLeastSignificantBits());
    out.writeString(coordinatorNodeId);
    out.writeVInt(nodeOperations.size());
    for (NodeOperation nodeOperation : nodeOperations) {
        nodeOperation.writeTo(out);
    }
}
Also used : NodeOperation(io.crate.operation.NodeOperation)

Example 2 with NodeOperation

use of io.crate.operation.NodeOperation in project crate by crate.

the class ExecutionPhasesTaskTest method testGroupByServer.

@Test
public void testGroupByServer() throws Exception {
    Routing twoNodeRouting = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("node1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(1, 2)).map()).put("node2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(3, 4)).map()).map());
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    m1.executionNodes(Sets.newHashSet("node3", "node4"));
    MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    m2.executionNodes(Sets.newHashSet("node1", "node3"));
    String localNodeId = "node1";
    NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0, localNodeId);
    NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0, localNodeId);
    NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0, localNodeId);
    Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(ImmutableList.of(n1, n2, n3));
    assertThat(groupByServer.containsKey("node1"), is(true));
    assertThat(groupByServer.get("node1"), Matchers.containsInAnyOrder(n1, n3));
    assertThat(groupByServer.containsKey("node2"), is(true));
    assertThat(groupByServer.get("node2"), Matchers.containsInAnyOrder(n1));
    assertThat(groupByServer.containsKey("node3"), is(true));
    assertThat(groupByServer.get("node3"), Matchers.containsInAnyOrder(n2, n3));
    assertThat(groupByServer.containsKey("node4"), is(true));
    assertThat(groupByServer.get("node4"), Matchers.containsInAnyOrder(n2));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Routing(io.crate.metadata.Routing) ImmutableList(com.google.common.collect.ImmutableList) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test)

Example 3 with NodeOperation

use of io.crate.operation.NodeOperation 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 4 with NodeOperation

use of io.crate.operation.NodeOperation in project crate by crate.

the class JobRequest method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    jobId = new UUID(in.readLong(), in.readLong());
    coordinatorNodeId = in.readString();
    int numNodeOperations = in.readVInt();
    ArrayList<NodeOperation> nodeOperations = new ArrayList<>(numNodeOperations);
    for (int i = 0; i < numNodeOperations; i++) {
        nodeOperations.add(new NodeOperation(in));
    }
    this.nodeOperations = nodeOperations;
}
Also used : ArrayList(java.util.ArrayList) NodeOperation(io.crate.operation.NodeOperation) UUID(java.util.UUID)

Example 5 with NodeOperation

use of io.crate.operation.NodeOperation in project crate by crate.

the class DistributingDownstreamFactoryTest method createDownstream.

private BatchConsumer createDownstream(Set<String> downstreamExecutionNodes) {
    UUID jobId = UUID.randomUUID();
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).map()).map());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, ImmutableList.<Symbol>of(), ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
    MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(LongType.INSTANCE), ImmutableList.<Projection>of(), DistributionInfo.DEFAULT_BROADCAST, null);
    mergePhase.executionNodes(downstreamExecutionNodes);
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0, "nodeName");
    return rowDownstreamFactory.create(nodeOperation, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Routing(io.crate.metadata.Routing) ImmutableList(com.google.common.collect.ImmutableList) NodeOperation(io.crate.operation.NodeOperation) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Aggregations

NodeOperation (io.crate.operation.NodeOperation)7 SharedShardContexts (io.crate.action.job.SharedShardContexts)3 ExecutionPhase (io.crate.planner.node.ExecutionPhase)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ImmutableList (com.google.common.collect.ImmutableList)2 ContextPreparer (io.crate.action.job.ContextPreparer)2 Routing (io.crate.metadata.Routing)2 MergePhase (io.crate.planner.node.dql.MergePhase)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2 Tuple (org.elasticsearch.common.collect.Tuple)2 IndicesService (org.elasticsearch.indices.IndicesService)2 Function (com.google.common.base.Function)1 FluentIterable (com.google.common.collect.FluentIterable)1 JobRequest (io.crate.action.job.JobRequest)1 TransportJobAction (io.crate.action.job.TransportJobAction)1 CompletableFutures (io.crate.concurrent.CompletableFutures)1 BatchConsumer (io.crate.data.BatchConsumer)1 Bucket (io.crate.data.Bucket)1 CollectingBatchConsumer (io.crate.data.CollectingBatchConsumer)1 Row (io.crate.data.Row)1