Search in sources :

Example 1 with TaskLockHelper

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

the class SegmentTransactionalInsertAction method checkWithSegmentLock.

private void checkWithSegmentLock() {
    final Map<Interval, List<DataSegment>> oldSegmentsMap = groupSegmentsByIntervalAndSort(segmentsToBeOverwritten);
    final Map<Interval, List<DataSegment>> newSegmentsMap = groupSegmentsByIntervalAndSort(segments);
    oldSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
    newSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
    oldSegmentsMap.forEach((interval, oldSegmentsPerInterval) -> {
        final List<DataSegment> newSegmentsPerInterval = Preconditions.checkNotNull(newSegmentsMap.get(interval), "segments of interval[%s]", interval);
        // These lists are already sorted in groupSegmentsByIntervalAndSort().
        final int oldStartRootPartitionId = oldSegmentsPerInterval.get(0).getStartRootPartitionId();
        final int oldEndRootPartitionId = oldSegmentsPerInterval.get(oldSegmentsPerInterval.size() - 1).getEndRootPartitionId();
        final int newStartRootPartitionId = newSegmentsPerInterval.get(0).getStartRootPartitionId();
        final int newEndRootPartitionId = newSegmentsPerInterval.get(newSegmentsPerInterval.size() - 1).getEndRootPartitionId();
        if (oldStartRootPartitionId != newStartRootPartitionId || oldEndRootPartitionId != newEndRootPartitionId) {
            throw new ISE("Root partition range[%d, %d] of new segments doesn't match to root partition range[%d, %d] of old segments", newStartRootPartitionId, newEndRootPartitionId, oldStartRootPartitionId, oldEndRootPartitionId);
        }
        newSegmentsPerInterval.forEach(eachNewSegment -> oldSegmentsPerInterval.forEach(eachOldSegment -> {
            if (eachNewSegment.getMinorVersion() <= eachOldSegment.getMinorVersion()) {
                throw new ISE("New segment[%s] have a smaller minor version than old segment[%s]", eachNewSegment, eachOldSegment);
            }
        }));
    });
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DruidMetrics(org.apache.druid.query.DruidMetrics) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CriticalAction(org.apache.druid.indexing.overlord.CriticalAction) Interval(org.joda.time.Interval) DataSourceMetadata(org.apache.druid.indexing.overlord.DataSourceMetadata) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskLock(org.apache.druid.indexing.common.TaskLock) TaskLockHelper(org.apache.druid.indexing.common.task.TaskLockHelper) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) SegmentPublishResult(org.apache.druid.indexing.overlord.SegmentPublishResult) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Collectors(java.util.stream.Collectors) LockGranularity(org.apache.druid.indexing.common.LockGranularity) List(java.util.List) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) SegmentUtils(org.apache.druid.segment.SegmentUtils) DataSegment(org.apache.druid.timeline.DataSegment) IndexTaskUtils(org.apache.druid.indexing.common.task.IndexTaskUtils) Preconditions(com.google.common.base.Preconditions) TaskLockHelper(org.apache.druid.indexing.common.task.TaskLockHelper) ArrayList(java.util.ArrayList) List(java.util.List) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval)

Aggregations

JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)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 TaskLock (org.apache.druid.indexing.common.TaskLock)1 IndexTaskUtils (org.apache.druid.indexing.common.task.IndexTaskUtils)1 Task (org.apache.druid.indexing.common.task.Task)1 TaskLockHelper (org.apache.druid.indexing.common.task.TaskLockHelper)1 CriticalAction (org.apache.druid.indexing.overlord.CriticalAction)1 DataSourceMetadata (org.apache.druid.indexing.overlord.DataSourceMetadata)1