Search in sources :

Example 21 with Task

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

the class TaskLocksTest method testCheckSegmentLockCoversSegments.

@Test
public void testCheckSegmentLockCoversSegments() {
    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.assertTrue(TaskLocks.isLockCoversSegments(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)

Example 22 with Task

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

the class TimeChunkLockTryAcquireActionTest method testWithLockType.

@Test(timeout = 60_000L)
public void testWithLockType() {
    final Task task = NoopTask.create();
    final TimeChunkLockTryAcquireAction action = new TimeChunkLockTryAcquireAction(TaskLockType.EXCLUSIVE, Intervals.of("2017-01-01/2017-01-02"));
    actionTestKit.getTaskLockbox().add(task);
    final TaskLock lock = action.perform(task, actionTestKit.getTaskActionToolbox());
    Assert.assertNotNull(lock);
}
Also used : NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) TaskLock(org.apache.druid.indexing.common.TaskLock) Test(org.junit.Test)

Example 23 with Task

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

the class SegmentTransactionalInsertActionTest method testFailBadVersion.

@Test
public void testFailBadVersion() throws Exception {
    final Task task = NoopTask.create();
    final SegmentTransactionalInsertAction action = SegmentTransactionalInsertAction.overwriteAction(null, null, 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"));
    SegmentPublishResult result = action.perform(task, actionTestKit.getTaskActionToolbox());
    Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT3)), result);
}
Also used : SegmentPublishResult(org.apache.druid.indexing.overlord.SegmentPublishResult) NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) Test(org.junit.Test)

Example 24 with Task

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

the class SegmentTransactionalInsertActionTest method testFailTransactionalDropSegment.

@Test
public void testFailTransactionalDropSegment() throws Exception {
    final Task task = NoopTask.create();
    actionTestKit.getTaskLockbox().add(task);
    acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
    SegmentPublishResult result = SegmentTransactionalInsertAction.overwriteAction(null, // SEGMENT1 does not exist, hence will fail to drop
    ImmutableSet.of(SEGMENT1), ImmutableSet.of(SEGMENT2)).perform(task, actionTestKit.getTaskActionToolbox());
    Assert.assertEquals(SegmentPublishResult.fail("org.apache.druid.metadata.RetryTransactionException: Aborting transaction!"), result);
}
Also used : SegmentPublishResult(org.apache.druid.indexing.overlord.SegmentPublishResult) NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) Test(org.junit.Test)

Example 25 with Task

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

the class SegmentTransactionalInsertActionTest method testTransactionalUpdateDataSourceMetadata.

@Test
public void testTransactionalUpdateDataSourceMetadata() throws Exception {
    final Task task = NoopTask.create();
    actionTestKit.getTaskLockbox().add(task);
    acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
    SegmentPublishResult result1 = SegmentTransactionalInsertAction.appendAction(ImmutableSet.of(SEGMENT1), new ObjectMetadata(null), new ObjectMetadata(ImmutableList.of(1))).perform(task, actionTestKit.getTaskActionToolbox());
    Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT1)), result1);
    SegmentPublishResult result2 = SegmentTransactionalInsertAction.appendAction(ImmutableSet.of(SEGMENT2), new ObjectMetadata(ImmutableList.of(1)), new ObjectMetadata(ImmutableList.of(2))).perform(task, actionTestKit.getTaskActionToolbox());
    Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT2)), result2);
    Assertions.assertThat(actionTestKit.getMetadataStorageCoordinator().retrieveUsedSegmentsForInterval(DATA_SOURCE, INTERVAL, Segments.ONLY_VISIBLE)).containsExactlyInAnyOrder(SEGMENT1, SEGMENT2);
    Assert.assertEquals(new ObjectMetadata(ImmutableList.of(2)), actionTestKit.getMetadataStorageCoordinator().retrieveDataSourceMetadata(DATA_SOURCE));
}
Also used : SegmentPublishResult(org.apache.druid.indexing.overlord.SegmentPublishResult) NoopTask(org.apache.druid.indexing.common.task.NoopTask) Task(org.apache.druid.indexing.common.task.Task) ObjectMetadata(org.apache.druid.indexing.overlord.ObjectMetadata) 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