Search in sources :

Example 1 with TaskLockPosse

use of org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse in project druid by druid-io.

the class TaskLockboxTest method testFindLockPosseAfterRevokeWithDifferentLockIntervals.

@Test
public void testFindLockPosseAfterRevokeWithDifferentLockIntervals() throws EntryExistsException {
    final Task lowPriorityTask = NoopTask.create(0);
    final Task highPriorityTask = NoopTask.create(10);
    taskStorage.insert(lowPriorityTask, TaskStatus.running(lowPriorityTask.getId()));
    taskStorage.insert(highPriorityTask, TaskStatus.running(highPriorityTask.getId()));
    lockbox.add(lowPriorityTask);
    lockbox.add(highPriorityTask);
    Assert.assertTrue(tryTimeChunkLock(TaskLockType.EXCLUSIVE, lowPriorityTask, Intervals.of("2018-12-16T09:00:00/2018-12-16T10:00:00")).isOk());
    Assert.assertTrue(tryTimeChunkLock(TaskLockType.EXCLUSIVE, highPriorityTask, Intervals.of("2018-12-16T09:00:00/2018-12-16T09:30:00")).isOk());
    final List<TaskLockPosse> highLockPosses = lockbox.getOnlyTaskLockPosseContainingInterval(highPriorityTask, Intervals.of("2018-12-16T09:00:00/2018-12-16T09:30:00"));
    Assert.assertEquals(1, highLockPosses.size());
    Assert.assertTrue(highLockPosses.get(0).containsTask(highPriorityTask));
    Assert.assertFalse(highLockPosses.get(0).getTaskLock().isRevoked());
    final List<TaskLockPosse> lowLockPosses = lockbox.getOnlyTaskLockPosseContainingInterval(lowPriorityTask, Intervals.of("2018-12-16T09:00:00/2018-12-16T10:00:00"));
    Assert.assertEquals(1, lowLockPosses.size());
    Assert.assertTrue(lowLockPosses.get(0).containsTask(lowPriorityTask));
    Assert.assertTrue(lowLockPosses.get(0).getTaskLock().isRevoked());
}
Also used : AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TaskLockPosse(org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse) Test(org.junit.Test)

Example 2 with TaskLockPosse

use of org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse in project druid by druid-io.

the class TaskLockboxTest method testGetTimeChunkAndSegmentLockForSameGroup.

@Test
public void testGetTimeChunkAndSegmentLockForSameGroup() {
    final Task task1 = NoopTask.withGroupId("groupId");
    final Task task2 = NoopTask.withGroupId("groupId");
    lockbox.add(task1);
    lockbox.add(task2);
    Assert.assertTrue(lockbox.tryLock(task1, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2017/2018"), null)).isOk());
    Assert.assertTrue(lockbox.tryLock(task2, new SpecificSegmentLockRequest(TaskLockType.EXCLUSIVE, task2, Intervals.of("2017/2018"), "version", 0)).isOk());
    final List<TaskLockPosse> posses = lockbox.getAllLocks().get(task1.getDataSource()).get(DateTimes.of("2017")).get(Intervals.of("2017/2018"));
    Assert.assertEquals(2, posses.size());
    Assert.assertEquals(LockGranularity.TIME_CHUNK, posses.get(0).getTaskLock().getGranularity());
    final TimeChunkLock timeChunkLock = (TimeChunkLock) posses.get(0).getTaskLock();
    Assert.assertEquals("none", timeChunkLock.getDataSource());
    Assert.assertEquals("groupId", timeChunkLock.getGroupId());
    Assert.assertEquals(Intervals.of("2017/2018"), timeChunkLock.getInterval());
    Assert.assertEquals(LockGranularity.SEGMENT, posses.get(1).getTaskLock().getGranularity());
    final SegmentLock segmentLock = (SegmentLock) posses.get(1).getTaskLock();
    Assert.assertEquals("none", segmentLock.getDataSource());
    Assert.assertEquals("groupId", segmentLock.getGroupId());
    Assert.assertEquals(Intervals.of("2017/2018"), segmentLock.getInterval());
    Assert.assertEquals(0, segmentLock.getPartitionId());
}
Also used : AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) SegmentLock(org.apache.druid.indexing.common.SegmentLock) TaskLockPosse(org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse) Test(org.junit.Test)

Example 3 with TaskLockPosse

use of org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse in project druid by druid-io.

the class TaskLockboxTest method testLockPosseEquals.

@Test
public void testLockPosseEquals() {
    final Task task1 = NoopTask.create();
    final Task task2 = NoopTask.create();
    TaskLock taskLock1 = new TimeChunkLock(TaskLockType.EXCLUSIVE, task1.getGroupId(), task1.getDataSource(), Intervals.of("2018/2019"), "v1", task1.getPriority());
    TaskLock taskLock2 = new TimeChunkLock(TaskLockType.EXCLUSIVE, task2.getGroupId(), task2.getDataSource(), Intervals.of("2018/2019"), "v2", task2.getPriority());
    TaskLockPosse taskLockPosse1 = new TaskLockPosse(taskLock1);
    TaskLockPosse taskLockPosse2 = new TaskLockPosse(taskLock2);
    TaskLockPosse taskLockPosse3 = new TaskLockPosse(taskLock1);
    Assert.assertNotEquals(taskLockPosse1, null);
    Assert.assertNotEquals(null, taskLockPosse1);
    Assert.assertNotEquals(taskLockPosse1, taskLockPosse2);
    Assert.assertEquals(taskLockPosse1, taskLockPosse3);
}
Also used : AbstractTask(org.apache.druid.indexing.common.task.AbstractTask) Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) TaskLock(org.apache.druid.indexing.common.TaskLock) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) TaskLockPosse(org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse) Test(org.junit.Test)

Aggregations

AbstractTask (org.apache.druid.indexing.common.task.AbstractTask)3 NoopTask (org.apache.druid.indexing.common.task.NoopTask)3 Task (org.apache.druid.indexing.common.task.Task)3 TaskLockPosse (org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse)3 Test (org.junit.Test)3 TimeChunkLock (org.apache.druid.indexing.common.TimeChunkLock)2 SegmentLock (org.apache.druid.indexing.common.SegmentLock)1 TaskLock (org.apache.druid.indexing.common.TaskLock)1