Search in sources :

Example 36 with Task

use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.

the class TaskLockConfigTest method testNotForceTimeChunkLock.

@Test
public void testNotForceTimeChunkLock() throws EntryExistsException {
    final TaskQueue taskQueue = createTaskQueue(false);
    taskQueue.start();
    final Task task = NoopTask.create();
    Assert.assertTrue(taskQueue.add(task));
    taskQueue.stop();
    final Optional<Task> optionalTask = taskStorage.getTask(task.getId());
    Assert.assertTrue(optionalTask.isPresent());
    final Task fromTaskStorage = optionalTask.get();
    Assert.assertFalse(fromTaskStorage.getContextValue(Tasks.FORCE_TIME_CHUNK_LOCK_KEY));
}
Also used : NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) Test(org.junit.Test)

Example 37 with Task

use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.

the class TaskQueueTest method testUserProvidedContextOverrideLockConfig.

@Test
public void testUserProvidedContextOverrideLockConfig() throws EntryExistsException {
    final TaskActionClientFactory actionClientFactory = createActionClientFactory();
    final TaskQueue taskQueue = new TaskQueue(new TaskLockConfig(), new TaskQueueConfig(null, null, null, null), new DefaultTaskConfig(), getTaskStorage(), new SimpleTaskRunner(actionClientFactory), actionClientFactory, getLockbox(), new NoopServiceEmitter());
    taskQueue.setActive(true);
    final Task task = new TestTask("t1", Intervals.of("2021-01-01/P1D"), ImmutableMap.of(Tasks.FORCE_TIME_CHUNK_LOCK_KEY, false));
    taskQueue.add(task);
    final List<Task> tasks = taskQueue.getTasks();
    Assert.assertEquals(1, tasks.size());
    final Task queuedTask = tasks.get(0);
    Assert.assertFalse(queuedTask.getContextValue(Tasks.FORCE_TIME_CHUNK_LOCK_KEY));
}
Also used : Task(org.apache.druid.indexing.common.task.Task) AbstractBatchIndexTask(org.apache.druid.indexing.common.task.AbstractBatchIndexTask) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) TaskQueueConfig(org.apache.druid.indexing.overlord.config.TaskQueueConfig) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) TaskLockConfig(org.apache.druid.indexing.overlord.config.TaskLockConfig) Test(org.junit.Test)

Example 38 with Task

use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.

the class TaskQueueTest method testDefaultTaskContextOverrideDefaultLineageBasedSegmentAllocation.

@Test
public void testDefaultTaskContextOverrideDefaultLineageBasedSegmentAllocation() throws EntryExistsException {
    final TaskActionClientFactory actionClientFactory = createActionClientFactory();
    final TaskQueue taskQueue = new TaskQueue(new TaskLockConfig(), new TaskQueueConfig(null, null, null, null), new DefaultTaskConfig() {

        @Override
        public Map<String, Object> getContext() {
            return ImmutableMap.of(SinglePhaseParallelIndexTaskRunner.CTX_USE_LINEAGE_BASED_SEGMENT_ALLOCATION_KEY, false);
        }
    }, getTaskStorage(), new SimpleTaskRunner(actionClientFactory), actionClientFactory, getLockbox(), new NoopServiceEmitter());
    taskQueue.setActive(true);
    final Task task = new TestTask("t1", Intervals.of("2021-01-01/P1D"));
    taskQueue.add(task);
    final List<Task> tasks = taskQueue.getTasks();
    Assert.assertEquals(1, tasks.size());
    final Task queuedTask = tasks.get(0);
    Assert.assertFalse(queuedTask.getContextValue(SinglePhaseParallelIndexTaskRunner.CTX_USE_LINEAGE_BASED_SEGMENT_ALLOCATION_KEY));
}
Also used : Task(org.apache.druid.indexing.common.task.Task) AbstractBatchIndexTask(org.apache.druid.indexing.common.task.AbstractBatchIndexTask) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) TaskQueueConfig(org.apache.druid.indexing.overlord.config.TaskQueueConfig) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TaskLockConfig(org.apache.druid.indexing.overlord.config.TaskLockConfig) Test(org.junit.Test)

Example 39 with Task

use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.

the class TaskQueueTest method testTaskStatusWhenExceptionIsThrownInIsReady.

@Test
public void testTaskStatusWhenExceptionIsThrownInIsReady() throws EntryExistsException {
    final TaskActionClientFactory actionClientFactory = createActionClientFactory();
    final TaskQueue taskQueue = new TaskQueue(new TaskLockConfig(), new TaskQueueConfig(null, null, null, null), new DefaultTaskConfig(), getTaskStorage(), new SimpleTaskRunner(actionClientFactory), actionClientFactory, getLockbox(), new NoopServiceEmitter());
    taskQueue.setActive(true);
    final Task task = new TestTask("t1", Intervals.of("2021-01-01/P1D")) {

        @Override
        public boolean isReady(TaskActionClient taskActionClient) {
            throw new RuntimeException("isReady failure test");
        }
    };
    taskQueue.add(task);
    taskQueue.manageInternal();
    Optional<TaskStatus> statusOptional = getTaskStorage().getStatus(task.getId());
    Assert.assertTrue(statusOptional.isPresent());
    Assert.assertEquals(TaskState.FAILED, statusOptional.get().getStatusCode());
    Assert.assertNotNull(statusOptional.get().getErrorMsg());
    Assert.assertTrue(StringUtils.format("Actual message is: %s", statusOptional.get().getErrorMsg()), statusOptional.get().getErrorMsg().startsWith("Failed while waiting for the task to be ready to run"));
}
Also used : Task(org.apache.druid.indexing.common.task.Task) AbstractBatchIndexTask(org.apache.druid.indexing.common.task.AbstractBatchIndexTask) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DefaultTaskConfig(org.apache.druid.indexing.overlord.config.DefaultTaskConfig) TaskStatus(org.apache.druid.indexer.TaskStatus) TaskLockConfig(org.apache.druid.indexing.overlord.config.TaskLockConfig) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) TaskQueueConfig(org.apache.druid.indexing.overlord.config.TaskQueueConfig) Test(org.junit.Test)

Example 40 with Task

use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.

the class TestTaskRunner method run.

@Override
public ListenableFuture<TaskStatus> run(final Task task) {
    final TaskToolbox toolbox = toolboxFactory.build(task);
    final Object taskPriorityObj = task.getContextValue(TaskThreadPriority.CONTEXT_KEY);
    int taskPriority = 0;
    try {
        taskPriority = taskPriorityObj == null ? 0 : Numbers.parseInt(taskPriorityObj);
    } catch (NumberFormatException e) {
        log.error(e, "Error parsing task priority [%s] for task [%s]", taskPriorityObj, task.getId());
    }
    final int finalTaskPriority = taskPriority;
    final ListenableFuture<TaskStatus> statusFuture = exec.computeIfAbsent(taskPriority, k -> buildExecutorService(finalTaskPriority)).submit(new TestTaskRunnerCallable(task, toolbox));
    final TestTaskRunnerWorkItem taskRunnerWorkItem = new TestTaskRunnerWorkItem(task, statusFuture);
    runningItems.add(taskRunnerWorkItem);
    Futures.addCallback(statusFuture, new FutureCallback<TaskStatus>() {

        @Override
        public void onSuccess(TaskStatus result) {
            runningItems.remove(taskRunnerWorkItem);
        }

        @Override
        public void onFailure(Throwable t) {
            runningItems.remove(taskRunnerWorkItem);
        }
    });
    return statusFuture;
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TaskThreadPriority(org.apache.druid.concurrent.TaskThreadPriority) Callable(java.util.concurrent.Callable) TaskStatus(org.apache.druid.indexer.TaskStatus) ScalingStats(org.apache.druid.indexing.overlord.autoscaling.ScalingStats) Pair(org.apache.druid.java.util.common.Pair) Interval(org.joda.time.Interval) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) Optional(com.google.common.base.Optional) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) QueryRunner(org.apache.druid.query.QueryRunner) Numbers(org.apache.druid.java.util.common.Numbers) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) DateTimes(org.apache.druid.java.util.common.DateTimes) TaskToolboxFactory(org.apache.druid.indexing.common.TaskToolboxFactory) Execs(org.apache.druid.java.util.common.concurrent.Execs) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) RE(org.apache.druid.java.util.common.RE) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskLocation(org.apache.druid.indexer.TaskLocation) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Preconditions(com.google.common.base.Preconditions) SegmentDescriptor(org.apache.druid.query.SegmentDescriptor) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TaskStatus(org.apache.druid.indexer.TaskStatus)

Aggregations

Task (org.apache.druid.indexing.common.task.Task)383 Test (org.junit.Test)307 NoopTask (org.apache.druid.indexing.common.task.NoopTask)177 HashMap (java.util.HashMap)132 Map (java.util.Map)132 RealtimeIndexTask (org.apache.druid.indexing.common.task.RealtimeIndexTask)120 ArrayList (java.util.ArrayList)114 ImmutableMap (com.google.common.collect.ImmutableMap)104 TreeMap (java.util.TreeMap)100 TaskStatus (org.apache.druid.indexer.TaskStatus)100 TaskRunnerListener (org.apache.druid.indexing.overlord.TaskRunnerListener)98 Executor (java.util.concurrent.Executor)86 List (java.util.List)78 AbstractTask (org.apache.druid.indexing.common.task.AbstractTask)78 Collection (java.util.Collection)70 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)68 TaskLocation (org.apache.druid.indexer.TaskLocation)62 TaskLock (org.apache.druid.indexing.common.TaskLock)60 ImmutableList (com.google.common.collect.ImmutableList)58 ISE (org.apache.druid.java.util.common.ISE)58