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;
}
Aggregations