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())));
}
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();
}
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);
}
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);
}
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);
}
Aggregations