use of org.apache.druid.indexing.common.TaskToolbox in project druid by druid-io.
the class HashPartitionTaskKillTest method failsInThirdPhase.
@Test(timeout = 5000L)
public void failsInThirdPhase() throws Exception {
final ParallelIndexSupervisorTask task = createTestTask(TIMESTAMP_SPEC, DIMENSIONS_SPEC, INPUT_FORMAT, null, INTERVAL_TO_INDEX, inputDir, "test_*", new HashedPartitionsSpec(null, 3, ImmutableList.of("dim1", "dim2")), 2, false, true, 1);
final TaskActionClient actionClient = createActionClient(task);
final TaskToolbox toolbox = createTaskToolbox(task, actionClient);
prepareTaskForLocking(task);
Assert.assertTrue(task.isReady(actionClient));
task.stopGracefully(null);
TaskStatus taskStatus = task.runHashPartitionMultiPhaseParallel(toolbox);
Assert.assertTrue(taskStatus.isFailure());
Assert.assertEquals("Failed in phase[PHASE-3]. See task logs for details.", taskStatus.getErrorMsg());
}
use of org.apache.druid.indexing.common.TaskToolbox in project druid by druid-io.
the class HashPartitionTaskKillTest method failsInFirstPhase.
@Test(timeout = 5000L)
public void failsInFirstPhase() throws Exception {
final ParallelIndexSupervisorTask task = createTestTask(TIMESTAMP_SPEC, DIMENSIONS_SPEC, INPUT_FORMAT, null, INTERVAL_TO_INDEX, inputDir, "test_*", new // num shards is null to force it to go to first phase
HashedPartitionsSpec(// num shards is null to force it to go to first phase
null, // num shards is null to force it to go to first phase
null, ImmutableList.of("dim1", "dim2")), 2, false, true, 0);
final TaskActionClient actionClient = createActionClient(task);
final TaskToolbox toolbox = createTaskToolbox(task, actionClient);
prepareTaskForLocking(task);
Assert.assertTrue(task.isReady(actionClient));
task.stopGracefully(null);
TaskStatus taskStatus = task.runHashPartitionMultiPhaseParallel(toolbox);
Assert.assertTrue(taskStatus.isFailure());
Assert.assertEquals("Failed in phase[PHASE-1]. See task logs for details.", taskStatus.getErrorMsg());
}
use of org.apache.druid.indexing.common.TaskToolbox in project druid by druid-io.
the class ParallelIndexPhaseRunnerTest method testLargeEstimatedNumSplits.
@Test
public void testLargeEstimatedNumSplits() throws Exception {
final NoopTask task = NoopTask.create();
final TaskActionClient actionClient = createActionClient(task);
final TaskToolbox toolbox = createTaskToolbox(task, actionClient);
final TestPhaseRunner runner = new TestPhaseRunner(toolbox, "supervisorTaskId", "groupId", AbstractParallelIndexSupervisorTaskTest.DEFAULT_TUNING_CONFIG_FOR_PARALLEL_INDEXING, 10, 12);
Assert.assertEquals(TaskState.SUCCESS, runner.run());
}
use of org.apache.druid.indexing.common.TaskToolbox in project druid by druid-io.
the class SinglePhaseParallelIndexingTest method testIsReady.
@Test
public void testIsReady() throws Exception {
final ParallelIndexSupervisorTask task = newTask(INTERVAL_TO_INDEX, false, true);
final TaskActionClient actionClient = createActionClient(task);
final TaskToolbox toolbox = createTaskToolbox(task, actionClient);
prepareTaskForLocking(task);
Assert.assertTrue(task.isReady(actionClient));
final SinglePhaseParallelIndexTaskRunner runner = task.createSinglePhaseTaskRunner(toolbox);
final Iterator<SubTaskSpec<SinglePhaseSubTask>> subTaskSpecIterator = runner.subTaskSpecIterator();
while (subTaskSpecIterator.hasNext()) {
final SinglePhaseSubTaskSpec spec = (SinglePhaseSubTaskSpec) subTaskSpecIterator.next();
final SinglePhaseSubTask subTask = new SinglePhaseSubTask(null, spec.getGroupId(), null, spec.getSupervisorTaskId(), spec.getId(), 0, spec.getIngestionSpec(), spec.getContext());
final TaskActionClient subTaskActionClient = createActionClient(subTask);
prepareTaskForLocking(subTask);
Assert.assertTrue(subTask.isReady(subTaskActionClient));
}
}
use of org.apache.druid.indexing.common.TaskToolbox in project druid by druid-io.
the class ThreadingTaskRunner method run.
@Override
public ListenableFuture<TaskStatus> run(Task task) {
synchronized (tasks) {
tasks.computeIfAbsent(task.getId(), k -> new ThreadingTaskRunnerWorkItem(task, taskExecutor.submit(new Callable<TaskStatus>() {
@Override
public TaskStatus call() {
final String attemptUUID = UUID.randomUUID().toString();
final File taskDir = taskConfig.getTaskDir(task.getId());
final File attemptDir = new File(taskDir, attemptUUID);
final TaskLocation taskLocation = TaskLocation.create(node.getHost(), node.getPlaintextPort(), node.getTlsPort());
final ThreadingTaskRunnerWorkItem taskWorkItem;
try {
FileUtils.mkdirp(attemptDir);
final File taskFile = new File(taskDir, "task.json");
final File reportsFile = new File(attemptDir, "report.json");
taskReportFileWriter.add(task.getId(), reportsFile);
// time to adjust process holders
synchronized (tasks) {
taskWorkItem = tasks.get(task.getId());
if (taskWorkItem == null) {
LOGGER.makeAlert("TaskInfo disappeared").addData("task", task.getId()).emit();
throw new ISE("TaskInfo disappeared for task[%s]!", task.getId());
}
if (taskWorkItem.shutdown) {
throw new IllegalStateException("Task has been shut down!");
}
}
if (!taskFile.exists()) {
jsonMapper.writeValue(taskFile, task);
}
// This will block for a while. So we append the thread information with more details
final String priorThreadName = Thread.currentThread().getName();
Thread.currentThread().setName(StringUtils.format("[%s]-%s", task.getId(), priorThreadName));
TaskStatus taskStatus;
final TaskToolbox toolbox = toolboxFactory.build(task);
TaskRunnerUtils.notifyLocationChanged(listeners, task.getId(), taskLocation);
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), TaskStatus.running(task.getId()));
taskWorkItem.setState(RunnerTaskState.RUNNING);
try {
taskStatus = task.run(toolbox);
} catch (Throwable t) {
LOGGER.error(t, "Exception caught while running the task.");
taskStatus = TaskStatus.failure(task.getId(), "Failed with an exception. See indexer logs for more details.");
} finally {
taskWorkItem.setState(RunnerTaskState.NONE);
Thread.currentThread().setName(priorThreadName);
if (reportsFile.exists()) {
taskLogPusher.pushTaskReports(task.getId(), reportsFile);
}
}
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), taskStatus);
return taskStatus;
} catch (Throwable t) {
LOGGER.error(t, "Exception caught during execution");
throw new RuntimeException(t);
} finally {
try {
taskReportFileWriter.delete(task.getId());
appenderatorsManager.removeAppenderatorsForTask(task.getId(), task.getDataSource());
synchronized (tasks) {
tasks.remove(task.getId());
if (!stopping) {
saveRunningTasks();
}
}
try {
if (!stopping && taskDir.exists()) {
FileUtils.deleteDirectory(taskDir);
LOGGER.info("Removed task directory: %s", taskDir);
}
} catch (Exception e) {
LOGGER.makeAlert(e, "Failed to delete task directory").addData("taskDir", taskDir.toString()).addData("task", task.getId()).emit();
}
} catch (Exception e) {
LOGGER.error(e, "Suppressing exception caught while cleaning up task");
}
}
}
})));
saveRunningTasks();
return tasks.get(task.getId()).getResult();
}
}
Aggregations