Search in sources :

Example 6 with LockListAction

use of io.druid.indexing.common.actions.LockListAction 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)6 LockListAction (io.druid.indexing.common.actions.LockListAction)6 Interval (org.joda.time.Interval)6 TaskToolbox (io.druid.indexing.common.TaskToolbox)5 SegmentInsertAction (io.druid.indexing.common.actions.SegmentInsertAction)5 DataSegment (io.druid.timeline.DataSegment)5 TaskStatus (io.druid.indexing.common.TaskStatus)3 AbstractFixedIntervalTask (io.druid.indexing.common.task.AbstractFixedIntervalTask)3 IndexTask (io.druid.indexing.common.task.IndexTask)3 KillTask (io.druid.indexing.common.task.KillTask)3 RealtimeIndexTask (io.druid.indexing.common.task.RealtimeIndexTask)3 Task (io.druid.indexing.common.task.Task)3 FireDepartmentTest (io.druid.segment.realtime.FireDepartmentTest)3 Test (org.junit.Test)3 LockAcquireAction (io.druid.indexing.common.actions.LockAcquireAction)2 TaskAction (io.druid.indexing.common.actions.TaskAction)2 TaskActionClient (io.druid.indexing.common.actions.TaskActionClient)2 DataSegmentPusher (io.druid.segment.loading.DataSegmentPusher)2 File (java.io.File)2 LockReleaseAction (io.druid.indexing.common.actions.LockReleaseAction)1