server/src/main/java/org/apache/druid/server/coordinator/duty/NewestSegmentFirstIterator.java
/**
   * Returns the initial searchInterval which is {@code (timeline.first().start, timeline.last().end - skipOffset)}.
   *
   * @param timeline      timeline of a dataSource
   * @param skipIntervals intervals to skip
   *
   * @return found interval to search or null if it's not found
   */
Returns the initial searchInterval which is  (timeline.first().start, timeline.last().end - skipOffset).
@param timeline      timeline of a dataSource
@param skipIntervals intervals to skip

@return found interval to search or null if it's not found
Returns the initial searchInterval which is ( timeline . first () . start timeline . last () . end - skipOffset ) . @param timeline timeline of a dataSource @param skipIntervals intervals to skip @return found interval to search or null if it ' s not found
private List<Interval> findInitialSearchInterval(
      String dataSourceName,
      VersionedIntervalTimeline<String, DataSegment> timeline,
      Period skipOffset,
      Granularity configuredSegmentGranularity,
      @Nullable List<Interval> skipIntervals
  )
  {
    Preconditions.checkArgument(timeline != null && !timeline.isEmpty(), "timeline should not be null or empty");
    Preconditions.checkNotNull(skipOffset, "skipOffset");
    final TimelineObjectHolder<String, DataSegment> first = Preconditions.checkNotNull(timeline.first(), "first");
    final TimelineObjectHolder<String, DataSegment> last = Preconditions.checkNotNull(timeline.last(), "last");
    final List<Interval> fullSkipIntervals = sortAndAddSkipIntervalFromLatest(
        last.getInterval().getEnd(),
        skipOffset,
        configuredSegmentGranularity,
        skipIntervals
    );
    for (Interval skipInterval : fullSkipIntervals) {
      final List<DataSegment> segments = new ArrayList<>(timeline.findNonOvershadowedObjectsInInterval(skipInterval, Partitions.ONLY_COMPLETE));
      collectSegmentStatistics(skippedSegments, dataSourceName, new SegmentsToCompact(segments));
    }
    final Interval totalInterval = new Interval(first.getInterval().getStart(), last.getInterval().getEnd());
    final List<Interval> filteredInterval = filterSkipIntervals(totalInterval, fullSkipIntervals);
    final List<Interval> searchIntervals = new ArrayList<>();
    for (Interval lookupInterval : filteredInterval) {
      final List<DataSegment> segments = timeline
          .findNonOvershadowedObjectsInInterval(lookupInterval, Partitions.ONLY_COMPLETE)
          .stream()
          .filter(segment -> lookupInterval.contains(segment.getInterval()))
          .collect(Collectors.toList());
      if (segments.isEmpty()) {
        continue;
      }
      DateTime searchStart = segments
          .stream()
          .map(segment -> segment.getId().getIntervalStart())
          .min(Comparator.naturalOrder())
          .orElseThrow(AssertionError::new);
      DateTime searchEnd = segments
          .stream()
          .map(segment -> segment.getId().getIntervalEnd())
          .max(Comparator.naturalOrder())
          .orElseThrow(AssertionError::new);
      searchIntervals.add(new Interval(searchStart, searchEnd));
    }
    return searchIntervals;
  }
private List < Interval > findInitialSearchInterval ( String dataSourceName , VersionedIntervalTimeline < String , DataSegment > timeline , Period skipOffset , Granularity configuredSegmentGranularity , @ Nullable List < Interval > skipIntervals ) { Preconditions . checkArgument ( timeline != null && ! timeline . isEmpty ( ) , "timeline should not be null or empty" ) ; Preconditions . checkNotNull ( skipOffset , "skipOffset" ) ; final TimelineObjectHolder < String , DataSegment > first = Preconditions . checkNotNull ( timeline . first ( ) , "first" ) ; final TimelineObjectHolder < String , DataSegment > last = Preconditions . checkNotNull ( timeline . last ( ) , "last" ) ; final List < Interval > fullSkipIntervals = sortAndAddSkipIntervalFromLatest ( last . getInterval ( ) . getEnd ( ) , skipOffset , configuredSegmentGranularity , skipIntervals ) ; for ( Interval skipInterval : fullSkipIntervals ) { final List < DataSegment > segments = new ArrayList < > ( timeline . findNonOvershadowedObjectsInInterval ( skipInterval , Partitions . ONLY_COMPLETE ) ) ; collectSegmentStatistics ( skippedSegments , dataSourceName , new SegmentsToCompact ( segments ) ) ; } final Interval totalInterval = new Interval ( first . getInterval ( ) . getStart ( ) , last . getInterval ( ) . getEnd ( ) ) ; final List < Interval > filteredInterval = filterSkipIntervals ( totalInterval , fullSkipIntervals ) ; final List < Interval > searchIntervals = new ArrayList < > ( ) ; for ( Interval lookupInterval : filteredInterval ) { final List < DataSegment > segments = timeline . findNonOvershadowedObjectsInInterval ( lookupInterval , Partitions . ONLY_COMPLETE ) . stream ( ) . filter ( segment -> lookupInterval . contains ( segment . getInterval ( ) ) ) . collect ( Collectors . toList ( ) ) ; if ( segments . isEmpty ( ) ) { continue ; } DateTime searchStart = segments . stream ( ) . map ( segment -> segment . getId ( ) . getIntervalStart ( ) ) . min ( Comparator . naturalOrder ( ) ) . orElseThrow ( AssertionError :: new ) ; DateTime searchEnd = segments . stream ( ) . map ( segment -> segment . getId ( ) . getIntervalEnd ( ) ) . max ( Comparator . naturalOrder ( ) ) . orElseThrow ( AssertionError :: new ) ; searchIntervals . add ( new Interval ( searchStart , searchEnd ) ) ; } return searchIntervals ; }
Returns the initial searchInterval which is {@code (timeline.first().start, timeline.last().end - skipOffset)}.
Returns the initial searchInterval which is { @code ( timeline . first () . start timeline . last () . end - skipOffset ) } .
// Calcuate stats of all skipped segments // findNonOvershadowedObjectsInInterval() may return segments merely intersecting with lookupInterval, while // we are interested only in segments fully lying within lookupInterval here.