Search in sources :

Example 16 with Task

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

the class SegmentAllocateActionTest method testAllocateAllGranularity.

@Test
public void testAllocateAllGranularity() {
    final Task task = NoopTask.create();
    taskActionTestKit.getTaskLockbox().add(task);
    final SegmentIdWithShardSpec id1 = allocate(task, PARTY_TIME, Granularities.MINUTE, Granularities.ALL, "s1", null);
    final SegmentIdWithShardSpec id2 = allocate(task, PARTY_TIME, Granularities.MINUTE, Granularities.ALL, "s2", null);
    Assert.assertNotNull(id1);
    Assert.assertNotNull(id2);
    Assert.assertEquals(Intervals.ETERNITY, id1.getInterval());
    Assert.assertEquals(Intervals.ETERNITY, id2.getInterval());
}
Also used : Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) SegmentIdWithShardSpec(org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec) Test(org.junit.Test)

Example 17 with Task

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

the class WorkerTaskManager method initAssignedTasks.

private void initAssignedTasks() throws IOException {
    File assignedTaskDir = getAssignedTaskDir();
    log.debug("Looking for any previously assigned tasks on disk[%s].", assignedTaskDir);
    FileUtils.mkdirp(assignedTaskDir);
    for (File taskFile : assignedTaskDir.listFiles()) {
        try {
            String taskId = taskFile.getName();
            Task task = jsonMapper.readValue(taskFile, Task.class);
            if (taskId.equals(task.getId())) {
                assignedTasks.put(taskId, task);
            } else {
                throw new ISE("Corrupted assigned task on disk[%s].", taskFile.getAbsoluteFile());
            }
        } catch (IOException ex) {
            log.noStackTrace().error(ex, "Failed to read assigned task from disk at [%s]. Ignored.", taskFile.getAbsoluteFile());
        }
    }
    if (!assignedTasks.isEmpty()) {
        log.info("Found %,d running tasks from previous run: %s", assignedTasks.size(), assignedTasks.values().stream().map(Task::getId).collect(Collectors.joining(", ")));
    }
    for (Task task : assignedTasks.values()) {
        submitNoticeToExec(new RunNotice(task));
    }
}
Also used : Task(org.apache.druid.indexing.common.task.Task) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) File(java.io.File)

Example 18 with Task

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

the class WorkerTaskManager method getChangesSince.

public ListenableFuture<ChangeRequestsSnapshot<WorkerHistoryItem>> getChangesSince(ChangeRequestHistory.Counter counter) {
    Preconditions.checkState(lifecycleLock.awaitStarted(1, TimeUnit.SECONDS), "not started");
    if (counter.getCounter() < 0) {
        synchronized (lock) {
            List<WorkerHistoryItem> items = new ArrayList<>();
            items.add(new WorkerHistoryItem.Metadata(disabled.get()));
            for (Task task : assignedTasks.values()) {
                items.add(new WorkerHistoryItem.TaskUpdate(TaskAnnouncement.create(task, TaskStatus.running(task.getId()), TaskLocation.unknown())));
            }
            for (TaskDetails details : runningTasks.values()) {
                items.add(new WorkerHistoryItem.TaskUpdate(TaskAnnouncement.create(details.task, details.status, details.location)));
            }
            for (TaskAnnouncement taskAnnouncement : completedTasks.values()) {
                items.add(new WorkerHistoryItem.TaskUpdate(taskAnnouncement));
            }
            SettableFuture<ChangeRequestsSnapshot<WorkerHistoryItem>> future = SettableFuture.create();
            future.set(ChangeRequestsSnapshot.success(changeHistory.getLastCounter(), Lists.newArrayList(items)));
            return future;
        }
    } else {
        return changeHistory.getRequestsSince(counter);
    }
}
Also used : Task(org.apache.druid.indexing.common.task.Task) ArrayList(java.util.ArrayList) ChangeRequestsSnapshot(org.apache.druid.server.coordination.ChangeRequestsSnapshot)

Example 19 with Task

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

the class SegmentInsertActionTest method testFailBadVersion.

@Test
public void testFailBadVersion() throws Exception {
    final Task task = NoopTask.create();
    final SegmentInsertAction action = new SegmentInsertAction(ImmutableSet.of(SEGMENT3));
    actionTestKit.getTaskLockbox().add(task);
    acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(CoreMatchers.containsString("are not covered by locks"));
    final Set<DataSegment> segments = actionTestKit.getTaskLockbox().doInCriticalSection(task, Collections.singletonList(INTERVAL), CriticalAction.<Set<DataSegment>>builder().onValidLocks(() -> action.perform(task, actionTestKit.getTaskActionToolbox())).onInvalidLocks(() -> {
        Assert.fail();
        return null;
    }).build());
    Assert.assertEquals(ImmutableSet.of(SEGMENT3), segments);
}
Also used : NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 20 with Task

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

the class TaskLocksTest method testFindSegmentLocksForSegments.

@Test
public void testFindSegmentLocksForSegments() {
    final Set<DataSegment> segments = createNumberedPartitionedSegments();
    final Interval interval = Intervals.of("2017-01-01/2017-01-02");
    final String version = DateTimes.nowUtc().toString();
    final List<TaskLock> locks = IntStream.range(0, 5).mapToObj(partitionId -> {
        final TaskLock lock = trySegmentLock(task, interval, version, partitionId).getTaskLock();
        Assert.assertNotNull(lock);
        return lock;
    }).collect(Collectors.toList());
    Assert.assertEquals(5, locks.size());
    Assert.assertEquals(ImmutableList.of(newSegmentLock(interval, locks.get(0).getVersion(), 0), newSegmentLock(interval, locks.get(0).getVersion(), 1), newSegmentLock(interval, locks.get(0).getVersion(), 2), newSegmentLock(interval, locks.get(0).getVersion(), 3), newSegmentLock(interval, locks.get(0).getVersion(), 4)), TaskLocks.findLocksForSegments(task, lockbox, segments));
}
Also used : IntStream(java.util.stream.IntStream) Intervals(org.apache.druid.java.util.common.Intervals) TaskStorageConfig(org.apache.druid.indexing.common.config.TaskStorageConfig) Function(java.util.function.Function) SpecificSegmentLockRequest(org.apache.druid.indexing.overlord.SpecificSegmentLockRequest) Interval(org.joda.time.Interval) ImmutableList(com.google.common.collect.ImmutableList) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskLock(org.apache.druid.indexing.common.TaskLock) Before(org.junit.Before) DateTimes(org.apache.druid.java.util.common.DateTimes) ImmutableSet(com.google.common.collect.ImmutableSet) TaskLockbox(org.apache.druid.indexing.overlord.TaskLockbox) TestIndexerMetadataStorageCoordinator(org.apache.druid.indexing.test.TestIndexerMetadataStorageCoordinator) NumberedShardSpec(org.apache.druid.timeline.partition.NumberedShardSpec) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) NoopTask(org.apache.druid.indexing.common.task.NoopTask) List(java.util.List) HeapMemoryTaskStorage(org.apache.druid.indexing.overlord.HeapMemoryTaskStorage) SegmentLock(org.apache.druid.indexing.common.SegmentLock) TaskLockType(org.apache.druid.indexing.common.TaskLockType) LinearShardSpec(org.apache.druid.timeline.partition.LinearShardSpec) DataSegment(org.apache.druid.timeline.DataSegment) LockResult(org.apache.druid.indexing.overlord.LockResult) TimeChunkLockRequest(org.apache.druid.indexing.overlord.TimeChunkLockRequest) Assert(org.junit.Assert) TaskLock(org.apache.druid.indexing.common.TaskLock) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

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