Search in sources :

Example 6 with TimeChunkLock

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

the class TaskLocks method isLockCoversSegments.

public static boolean isLockCoversSegments(NavigableMap<DateTime, List<TaskLock>> taskLockMap, Collection<DataSegment> segments) {
    return segments.stream().allMatch(segment -> {
        final Entry<DateTime, List<TaskLock>> entry = taskLockMap.floorEntry(segment.getInterval().getStart());
        if (entry == null) {
            return false;
        }
        final List<TaskLock> locks = entry.getValue();
        return locks.stream().anyMatch(lock -> {
            if (lock.getGranularity() == LockGranularity.TIME_CHUNK) {
                final TimeChunkLock timeChunkLock = (TimeChunkLock) lock;
                return timeChunkLock.getInterval().contains(segment.getInterval()) && timeChunkLock.getDataSource().equals(segment.getDataSource()) && timeChunkLock.getVersion().compareTo(segment.getVersion()) >= 0;
            } else {
                final SegmentLock segmentLock = (SegmentLock) lock;
                return segmentLock.getInterval().contains(segment.getInterval()) && segmentLock.getDataSource().equals(segment.getDataSource()) && segmentLock.getVersion().compareTo(segment.getVersion()) >= 0 && segmentLock.getPartitionId() == segment.getShardSpec().getPartitionNum();
            }
        });
    });
}
Also used : TaskLock(org.apache.druid.indexing.common.TaskLock) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) SegmentLock(org.apache.druid.indexing.common.SegmentLock) ArrayList(java.util.ArrayList) List(java.util.List) DateTime(org.joda.time.DateTime)

Example 7 with TimeChunkLock

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

the class RemoteTaskActionClientTest method testSubmitSimple.

@Test
public void testSubmitSimple() throws Exception {
    Request request = new Request(HttpMethod.POST, new URL("http://localhost:1234/xx"));
    EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/action")).andReturn(request);
    // return status code 200 and a list with size equals 1
    Map<String, Object> responseBody = new HashMap<>();
    final List<TaskLock> expectedLocks = Collections.singletonList(new TimeChunkLock(TaskLockType.SHARED, "groupId", "dataSource", Intervals.of("2019/2020"), "version", 0));
    responseBody.put("result", expectedLocks);
    String strResult = objectMapper.writeValueAsString(responseBody);
    final HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    EasyMock.expect(response.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
    EasyMock.replay(response);
    StringFullResponseHolder responseHolder = new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk(strResult);
    // set up mocks
    EasyMock.expect(druidLeaderClient.go(request)).andReturn(responseHolder);
    EasyMock.replay(druidLeaderClient);
    Task task = NoopTask.create("id", 0);
    RemoteTaskActionClient client = new RemoteTaskActionClient(task, druidLeaderClient, new RetryPolicyFactory(new RetryPolicyConfig()), objectMapper);
    final List<TaskLock> locks = client.submit(new LockListAction());
    Assert.assertEquals(expectedLocks, locks);
    EasyMock.verify(druidLeaderClient);
}
Also used : Task(org.apache.druid.indexing.common.task.Task) NoopTask(org.apache.druid.indexing.common.task.NoopTask) RetryPolicyConfig(org.apache.druid.indexing.common.RetryPolicyConfig) HashMap(java.util.HashMap) TimeChunkLock(org.apache.druid.indexing.common.TimeChunkLock) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) RetryPolicyFactory(org.apache.druid.indexing.common.RetryPolicyFactory) URL(java.net.URL) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) TaskLock(org.apache.druid.indexing.common.TaskLock) Test(org.junit.Test)

Example 8 with TimeChunkLock

use of org.apache.druid.indexing.common.TimeChunkLock 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

TimeChunkLock (org.apache.druid.indexing.common.TimeChunkLock)8 SegmentLock (org.apache.druid.indexing.common.SegmentLock)5 TaskLock (org.apache.druid.indexing.common.TaskLock)5 NoopTask (org.apache.druid.indexing.common.task.NoopTask)5 Task (org.apache.druid.indexing.common.task.Task)5 Test (org.junit.Test)5 AbstractTask (org.apache.druid.indexing.common.task.AbstractTask)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TaskLockPosse (org.apache.druid.indexing.overlord.TaskLockbox.TaskLockPosse)3 ISE (org.apache.druid.java.util.common.ISE)3 HashMap (java.util.HashMap)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Iterables (com.google.common.collect.Iterables)1 URL (java.net.URL)1