Search in sources :

Example 1 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class NodeDisconnectJobMonitorServiceTest method testOnParticipatingNodeDisconnectedKillsJob.

@Test
public void testOnParticipatingNodeDisconnectedKillsJob() throws Exception {
    JobContextService jobContextService = jobContextService();
    DiscoveryNode coordinator_node = new DiscoveryNode("coordinator_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNode data_node = new DiscoveryNode("data_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().localNodeId("coordinator_node_id").put(coordinator_node).put(data_node).build();
    JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID(), coordinator_node.getId(), Arrays.asList(coordinator_node.getId(), data_node.getId()));
    builder.addSubContext(new DummySubContext());
    jobContextService.createContext(builder);
    TransportKillJobsNodeAction killAction = mock(TransportKillJobsNodeAction.class);
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, mock(ThreadPool.class), jobContextService, mock(TransportService.class), killAction);
    monitorService.onNodeDisconnected(discoveryNodes.get("data_node_id"));
    verify(killAction, times(1)).broadcast(any(KillJobsRequest.class), any(ActionListener.class), eq(Arrays.asList(discoveryNodes.get("data_node_id").getId())));
}
Also used : TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DummySubContext(io.crate.jobs.DummySubContext) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) KillJobsRequest(io.crate.executor.transport.kill.KillJobsRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobExecutionContext(io.crate.jobs.JobExecutionContext) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class TransportKillAllNodeActionTest method testKillIsCalledOnJobContextService.

@Test
public void testKillIsCalledOnJobContextService() throws Exception {
    TransportService transportService = mock(TransportService.class);
    JobContextService jobContextService = mock(JobContextService.class, Answers.RETURNS_MOCKS.get());
    NoopClusterService noopClusterService = new NoopClusterService();
    TransportKillAllNodeAction transportKillAllNodeAction = new TransportKillAllNodeAction(Settings.EMPTY, jobContextService, noopClusterService, transportService);
    final CountDownLatch latch = new CountDownLatch(1);
    transportKillAllNodeAction.nodeOperation(new KillAllRequest(), new ActionListener<KillResponse>() {

        @Override
        public void onResponse(KillResponse killResponse) {
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable throwable) {
            latch.countDown();
        }
    });
    latch.await(1, TimeUnit.SECONDS);
    verify(jobContextService, times(1)).killAll();
}
Also used : TransportService(org.elasticsearch.transport.TransportService) CountDownLatch(java.util.concurrent.CountDownLatch) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test)

Example 3 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class JobContextIntegrationTest method testAllContextAreClosed.

@Test
public void testAllContextAreClosed() throws Exception {
    // lets create some contexts which must be closed after statement execution
    // group-by query (job collect context with sub-contexts + PageDownstreamContext are created)
    setup.groupBySetup();
    execute("select age, name from characters group by 1, 2");
    // system table query (job collect context without sub-contexts is created)
    execute("select random(), random() from sys.cluster limit 1");
    // information_schema table query (job collect context without sub-contexts is created)
    execute("select table_name from information_schema.tables");
    // multiple upserts (SymbolBasedBulkShardProcessorContext is created)
    execute("create table upserts (id int primary key, d long)");
    ensureYellow();
    execute("insert into upserts (id, d) values (?, ?)", new Object[][] { new Object[] { 1, -7L }, new Object[] { 2, 3L } });
    refresh();
    // upsert-by-id (UpsertByIdContext is created)
    execute("update upserts set d = 5 where id = 1");
    // get by id (ESJobContext is created)
    execute("select * from upserts where id = 1");
    // count (CountContext is created)
    execute("select count(*) from upserts");
    // now check if all contexts are gone
    final Field activeContexts = JobContextService.class.getDeclaredField("activeContexts");
    activeContexts.setAccessible(true);
    assertBusy(new Runnable() {

        @Override
        public void run() {
            for (JobContextService jobContextService : internalCluster().getInstances(JobContextService.class)) {
                Map<UUID, JobExecutionContext> contextMap = null;
                try {
                    contextMap = (Map<UUID, JobExecutionContext>) activeContexts.get(jobContextService);
                    assertThat(contextMap.size(), is(0));
                } catch (Exception e) {
                    fail(e.getMessage());
                }
            }
        }
    }, 1, TimeUnit.SECONDS);
}
Also used : Field(java.lang.reflect.Field) Map(java.util.Map) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test)

Example 4 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class RemoteCollectorFactory method createCollector.

/**
     * create a RemoteCollector
     * The RemoteCollector will collect data from another node using a wormhole as if it was collecting on this node.
     * <p>
     * This should only be used if a shard is not available on the current node due to a relocation
     */
public CrateCollector.Builder createCollector(String index, Integer shardId, RoutedCollectPhase collectPhase, final RamAccountingContext ramAccountingContext) {
    // new job because subContexts can't be merged into an existing job
    final UUID childJobId = UUID.randomUUID();
    IndexShardRoutingTable shardRoutings = clusterService.state().routingTable().shardRoutingTable(index, shardId);
    // for update operations primaryShards must be used
    // (for others that wouldn't be the case, but at this point it is not easily visible which is the case)
    ShardRouting shardRouting = shardRoutings.primaryShard();
    final String remoteNodeId = shardRouting.currentNodeId();
    assert remoteNodeId != null : "primaryShard not assigned :(";
    final String localNodeId = clusterService.localNode().getId();
    final RoutedCollectPhase newCollectPhase = createNewCollectPhase(childJobId, collectPhase, index, shardId, remoteNodeId);
    return consumer -> new RemoteCollector(childJobId, localNodeId, remoteNodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), jobContextService, ramAccountingContext, consumer, newCollectPhase);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) java.util(java.util) Projections(io.crate.planner.projection.Projections) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) TreeMapBuilder(io.crate.core.collections.TreeMapBuilder) Routing(io.crate.metadata.Routing) Singleton(org.elasticsearch.common.inject.Singleton) ClusterService(org.elasticsearch.cluster.ClusterService) JobContextService(io.crate.jobs.JobContextService) TransportActionProvider(io.crate.executor.transport.TransportActionProvider) DistributionInfo(io.crate.planner.distribution.DistributionInfo) RamAccountingContext(io.crate.breaker.RamAccountingContext) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 5 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class RemoteCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
    consumer = new TestingBatchConsumer();
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
    remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.action.job.TransportJobAction) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) JobContextService(io.crate.jobs.JobContextService) Before(org.junit.Before)

Aggregations

JobContextService (io.crate.jobs.JobContextService)9 Test (org.junit.Test)5 JobExecutionContext (io.crate.jobs.JobExecutionContext)4 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)4 TransportService (org.elasticsearch.transport.TransportService)4 TransportKillJobsNodeAction (io.crate.executor.transport.kill.TransportKillJobsNodeAction)3 UUID (java.util.UUID)3 KillJobsRequest (io.crate.executor.transport.kill.KillJobsRequest)2 DummySubContext (io.crate.jobs.DummySubContext)2 Routing (io.crate.metadata.Routing)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ActionListener (org.elasticsearch.action.ActionListener)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 ImmutableMap (com.google.common.collect.ImmutableMap)1