Search in sources :

Example 1 with SegmentLockTryAcquireAction

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

the class TaskLockHelper method tryLockSegments.

private boolean tryLockSegments(TaskActionClient actionClient, List<DataSegment> segments) throws IOException {
    final Map<Interval, List<DataSegment>> intervalToSegments = SegmentUtils.groupSegmentsByInterval(segments);
    for (Entry<Interval, List<DataSegment>> entry : intervalToSegments.entrySet()) {
        final Interval interval = entry.getKey();
        final List<DataSegment> segmentsInInterval = entry.getValue();
        final boolean hasSameVersion = segmentsInInterval.stream().allMatch(segment -> segment.getVersion().equals(segmentsInInterval.get(0).getVersion()));
        Preconditions.checkState(hasSameVersion, "Segments %s should have same version", SegmentUtils.commaSeparatedIdentifiers(segmentsInInterval));
        final List<LockResult> lockResults = actionClient.submit(new SegmentLockTryAcquireAction(TaskLockType.EXCLUSIVE, interval, segmentsInInterval.get(0).getVersion(), segmentsInInterval.stream().map(segment -> segment.getShardSpec().getPartitionNum()).collect(Collectors.toSet())));
        if (lockResults.stream().anyMatch(result -> !result.isOk())) {
            return false;
        }
        lockedExistingSegments.addAll(segmentsInInterval);
        verifyAndFindRootPartitionRangeAndMinorVersion(segmentsInInterval);
    }
    return true;
}
Also used : SegmentLockTryAcquireAction(org.apache.druid.indexing.common.actions.SegmentLockTryAcquireAction) Granularity(org.apache.druid.java.util.common.granularity.Granularity) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) LockGranularity(org.apache.druid.indexing.common.LockGranularity) ArrayList(java.util.ArrayList) SegmentLockTryAcquireAction(org.apache.druid.indexing.common.actions.SegmentLockTryAcquireAction) HashSet(java.util.HashSet) Interval(org.joda.time.Interval) List(java.util.List) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) TaskLockType(org.apache.druid.indexing.common.TaskLockType) Map(java.util.Map) SegmentUtils(org.apache.druid.segment.SegmentUtils) DataSegment(org.apache.druid.timeline.DataSegment) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) LockResult(org.apache.druid.indexing.overlord.LockResult) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) LockResult(org.apache.druid.indexing.overlord.LockResult) ArrayList(java.util.ArrayList) List(java.util.List) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 LockGranularity (org.apache.druid.indexing.common.LockGranularity)1 TaskLockType (org.apache.druid.indexing.common.TaskLockType)1 SegmentLockTryAcquireAction (org.apache.druid.indexing.common.actions.SegmentLockTryAcquireAction)1 TaskActionClient (org.apache.druid.indexing.common.actions.TaskActionClient)1 LockResult (org.apache.druid.indexing.overlord.LockResult)1 ISE (org.apache.druid.java.util.common.ISE)1 Granularity (org.apache.druid.java.util.common.granularity.Granularity)1 SegmentUtils (org.apache.druid.segment.SegmentUtils)1