Search in sources :

Example 21 with TaskLock

use of io.druid.indexing.common.TaskLock in project druid by druid-io.

the class SegmentAllocateActionTest method testMultipleSequences.

@Test
public void testMultipleSequences() throws Exception {
    final Task task = new NoopTask(null, 0, 0, null, null, null);
    taskActionTestKit.getTaskLockbox().add(task);
    final SegmentIdentifier id1 = allocate(task, PARTY_TIME, Granularities.NONE, Granularities.HOUR, "s1", null);
    final SegmentIdentifier id2 = allocate(task, PARTY_TIME, Granularities.NONE, Granularities.HOUR, "s2", null);
    final SegmentIdentifier id3 = allocate(task, PARTY_TIME, Granularities.NONE, Granularities.HOUR, "s1", id1.getIdentifierAsString());
    final SegmentIdentifier id4 = allocate(task, THE_DISTANT_FUTURE, Granularities.NONE, Granularities.HOUR, "s1", id3.getIdentifierAsString());
    final SegmentIdentifier id5 = allocate(task, THE_DISTANT_FUTURE, Granularities.NONE, Granularities.HOUR, "s2", id2.getIdentifierAsString());
    final SegmentIdentifier id6 = allocate(task, PARTY_TIME, Granularities.NONE, Granularities.HOUR, "s1", null);
    final TaskLock partyLock = Iterables.getOnlyElement(FluentIterable.from(taskActionTestKit.getTaskLockbox().findLocksForTask(task)).filter(new Predicate<TaskLock>() {

        @Override
        public boolean apply(TaskLock input) {
            return input.getInterval().contains(PARTY_TIME);
        }
    }));
    final TaskLock futureLock = Iterables.getOnlyElement(FluentIterable.from(taskActionTestKit.getTaskLockbox().findLocksForTask(task)).filter(new Predicate<TaskLock>() {

        @Override
        public boolean apply(TaskLock input) {
            return input.getInterval().contains(THE_DISTANT_FUTURE);
        }
    }));
    assertSameIdentifier(id1, new SegmentIdentifier(DATA_SOURCE, Granularities.HOUR.bucket(PARTY_TIME), partyLock.getVersion(), new NumberedShardSpec(0, 0)));
    assertSameIdentifier(id2, new SegmentIdentifier(DATA_SOURCE, Granularities.HOUR.bucket(PARTY_TIME), partyLock.getVersion(), new NumberedShardSpec(1, 0)));
    assertSameIdentifier(id3, new SegmentIdentifier(DATA_SOURCE, Granularities.HOUR.bucket(PARTY_TIME), partyLock.getVersion(), new NumberedShardSpec(2, 0)));
    assertSameIdentifier(id4, new SegmentIdentifier(DATA_SOURCE, Granularities.HOUR.bucket(THE_DISTANT_FUTURE), futureLock.getVersion(), new NumberedShardSpec(0, 0)));
    assertSameIdentifier(id5, new SegmentIdentifier(DATA_SOURCE, Granularities.HOUR.bucket(THE_DISTANT_FUTURE), futureLock.getVersion(), new NumberedShardSpec(1, 0)));
    assertSameIdentifier(id6, id1);
}
Also used : Task(io.druid.indexing.common.task.Task) NoopTask(io.druid.indexing.common.task.NoopTask) SegmentIdentifier(io.druid.segment.realtime.appenderator.SegmentIdentifier) TaskLock(io.druid.indexing.common.TaskLock) NoopTask(io.druid.indexing.common.task.NoopTask) NumberedShardSpec(io.druid.timeline.partition.NumberedShardSpec) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 22 with TaskLock

use of io.druid.indexing.common.TaskLock in project druid by druid-io.

the class TaskLifecycleTest method testSimple.

@Test
public void testSimple() throws Exception {
    final Task task = new AbstractFixedIntervalTask("id1", "id1", new TaskResource("id1", 1), "ds", new Interval("2012-01-01/P1D"), null) {

        @Override
        public String getType() {
            return "test";
        }

        @Override
        public TaskStatus run(TaskToolbox toolbox) throws Exception {
            final TaskLock myLock = Iterables.getOnlyElement(toolbox.getTaskActionClient().submit(new LockListAction()));
            final DataSegment segment = DataSegment.builder().dataSource("ds").interval(new Interval("2012-01-01/P1D")).version(myLock.getVersion()).build();
            toolbox.getTaskActionClient().submit(new SegmentInsertAction(ImmutableSet.of(segment)));
            return TaskStatus.success(getId());
        }
    };
    final TaskStatus status = runTask(task);
    Assert.assertEquals("statusCode", TaskStatus.Status.SUCCESS, status.getStatusCode());
    Assert.assertEquals("segments published", 1, mdc.getPublished().size());
    Assert.assertEquals("segments nuked", 0, mdc.getNuked().size());
}
Also used : TaskToolbox(io.druid.indexing.common.TaskToolbox) LockListAction(io.druid.indexing.common.actions.LockListAction) IndexTask(io.druid.indexing.common.task.IndexTask) RealtimeIndexTask(io.druid.indexing.common.task.RealtimeIndexTask) Task(io.druid.indexing.common.task.Task) AbstractFixedIntervalTask(io.druid.indexing.common.task.AbstractFixedIntervalTask) KillTask(io.druid.indexing.common.task.KillTask) TaskResource(io.druid.indexing.common.task.TaskResource) TaskLock(io.druid.indexing.common.TaskLock) SegmentInsertAction(io.druid.indexing.common.actions.SegmentInsertAction) TaskStatus(io.druid.indexing.common.TaskStatus) DataSegment(io.druid.timeline.DataSegment) AbstractFixedIntervalTask(io.druid.indexing.common.task.AbstractFixedIntervalTask) Interval(org.joda.time.Interval) FireDepartmentTest(io.druid.segment.realtime.FireDepartmentTest) Test(org.junit.Test)

Example 23 with TaskLock

use of io.druid.indexing.common.TaskLock in project druid by druid-io.

the class TaskLockboxTest method testTrySmallerLock.

@Test
public void testTrySmallerLock() throws InterruptedException {
    Task task = NoopTask.create();
    lockbox.add(task);
    Optional<TaskLock> lock1 = lockbox.tryLock(task, new Interval("2015-01-01/2015-01-03"));
    Assert.assertTrue(lock1.isPresent());
    Assert.assertEquals(new Interval("2015-01-01/2015-01-03"), lock1.get().getInterval());
    // same task tries to take partially overlapping interval; should fail
    Assert.assertFalse(lockbox.tryLock(task, new Interval("2015-01-02/2015-01-04")).isPresent());
    // same task tries to take contained interval; should succeed and should match the original lock
    Optional<TaskLock> lock2 = lockbox.tryLock(task, new Interval("2015-01-01/2015-01-02"));
    Assert.assertTrue(lock2.isPresent());
    Assert.assertEquals(new Interval("2015-01-01/2015-01-03"), lock2.get().getInterval());
    // only the first lock should actually exist
    Assert.assertEquals(ImmutableList.of(lock1.get()), lockbox.findLocksForTask(task));
}
Also used : Task(io.druid.indexing.common.task.Task) NoopTask(io.druid.indexing.common.task.NoopTask) TaskLock(io.druid.indexing.common.TaskLock) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 24 with TaskLock

use of io.druid.indexing.common.TaskLock in project druid by druid-io.

the class RealtimeishTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final Interval interval1 = new Interval("2010-01-01T00/PT1H");
    final Interval interval2 = new Interval("2010-01-01T01/PT1H");
    // Sort of similar to what realtime tasks do:
    // Acquire lock for first interval
    final TaskLock lock1 = toolbox.getTaskActionClient().submit(new LockAcquireAction(interval1));
    final List<TaskLock> locks1 = toolbox.getTaskActionClient().submit(new LockListAction());
    // (Confirm lock sanity)
    Assert.assertEquals("lock1 interval", interval1, lock1.getInterval());
    Assert.assertEquals("locks1", ImmutableList.of(lock1), locks1);
    // Acquire lock for second interval
    final TaskLock lock2 = toolbox.getTaskActionClient().submit(new LockAcquireAction(interval2));
    final List<TaskLock> locks2 = toolbox.getTaskActionClient().submit(new LockListAction());
    // (Confirm lock sanity)
    Assert.assertEquals("lock2 interval", interval2, lock2.getInterval());
    Assert.assertEquals("locks2", ImmutableList.of(lock1, lock2), locks2);
    // Push first segment
    toolbox.getTaskActionClient().submit(new SegmentInsertAction(ImmutableSet.of(DataSegment.builder().dataSource("foo").interval(interval1).version(lock1.getVersion()).build())));
    // Release first lock
    toolbox.getTaskActionClient().submit(new LockReleaseAction(interval1));
    final List<TaskLock> locks3 = toolbox.getTaskActionClient().submit(new LockListAction());
    // (Confirm lock sanity)
    Assert.assertEquals("locks3", ImmutableList.of(lock2), locks3);
    // Push second segment
    toolbox.getTaskActionClient().submit(new SegmentInsertAction(ImmutableSet.of(DataSegment.builder().dataSource("foo").interval(interval2).version(lock2.getVersion()).build())));
    // Release second lock
    toolbox.getTaskActionClient().submit(new LockReleaseAction(interval2));
    final List<TaskLock> locks4 = toolbox.getTaskActionClient().submit(new LockListAction());
    // (Confirm lock sanity)
    Assert.assertEquals("locks4", ImmutableList.<TaskLock>of(), locks4);
    // Exit
    return TaskStatus.success(getId());
}
Also used : LockListAction(io.druid.indexing.common.actions.LockListAction) TaskLock(io.druid.indexing.common.TaskLock) SegmentInsertAction(io.druid.indexing.common.actions.SegmentInsertAction) LockAcquireAction(io.druid.indexing.common.actions.LockAcquireAction) LockReleaseAction(io.druid.indexing.common.actions.LockReleaseAction) Interval(org.joda.time.Interval)

Aggregations

TaskLock (io.druid.indexing.common.TaskLock)24 DataSegment (io.druid.timeline.DataSegment)13 Interval (org.joda.time.Interval)13 Task (io.druid.indexing.common.task.Task)8 Test (org.junit.Test)7 LockListAction (io.druid.indexing.common.actions.LockListAction)6 TaskToolbox (io.druid.indexing.common.TaskToolbox)5 LockAcquireAction (io.druid.indexing.common.actions.LockAcquireAction)5 SegmentInsertAction (io.druid.indexing.common.actions.SegmentInsertAction)5 ISE (io.druid.java.util.common.ISE)5 SegmentIdentifier (io.druid.segment.realtime.appenderator.SegmentIdentifier)5 SegmentListUnusedAction (io.druid.indexing.common.actions.SegmentListUnusedAction)4 NoopTask (io.druid.indexing.common.task.NoopTask)4 NumberedShardSpec (io.druid.timeline.partition.NumberedShardSpec)4 File (java.io.File)4 Predicate (com.google.common.base.Predicate)3 TaskStatus (io.druid.indexing.common.TaskStatus)3 SegmentMetadataUpdateAction (io.druid.indexing.common.actions.SegmentMetadataUpdateAction)3 AbstractFixedIntervalTask (io.druid.indexing.common.task.AbstractFixedIntervalTask)3 IndexTask (io.druid.indexing.common.task.IndexTask)3