server/src/main/java/org/apache/druid/server/SegmentManager.java
/**
   * Load a single segment.
   *
   * @param segment segment to load
   * @param lazy    whether to lazy load columns metadata
   * @param loadFailed callBack to execute when segment lazy load failed
   * @param loadSegmentIntoPageCacheExec If null is specified, the default thread pool in segment loader to load
   *                                     segments into page cache on download will be used. You can specify a dedicated
   *                                     thread pool of larger capacity when this function is called during historical
   *                                     process bootstrap to speed up initial loading.
   *
   * @return true if the segment was newly loaded, false if it was already loaded
   *
   * @throws SegmentLoadingException if the segment cannot be loaded
   */
Load a single segment.
@param segment segment to load
@param lazy    whether to lazy load columns metadata
@param loadFailed callBack to execute when segment lazy load failed
@param loadSegmentIntoPageCacheExec If null is specified, the default thread pool in segment loader to load
segments into page cache on download will be used. You can specify a dedicated
thread pool of larger capacity when this function is called during historical
process bootstrap to speed up initial loading.

@return true if the segment was newly loaded, false if it was already loaded

@throws SegmentLoadingException if the segment cannot be loaded
Load a single segment . @param segment segment to load @param lazy whether to lazy load columns metadata @param loadFailed callBack to execute when segment lazy load failed @param loadSegmentIntoPageCacheExec If null is specified the default thread pool in segment loader to load segments into page cache on download will be used . You can specify a dedicated thread pool of larger capacity when this function is called during historical process bootstrap to speed up initial loading . @return true if the segment was newly loaded false if it was already loaded @throws SegmentLoadingException if the segment cannot be loaded
public boolean loadSegment(final DataSegment segment, boolean lazy, SegmentLazyLoadFailCallback loadFailed,
                             ExecutorService loadSegmentIntoPageCacheExec) throws SegmentLoadingException
  {
    final ReferenceCountingSegment adapter = getSegmentReference(segment, lazy, loadFailed);
    final SettableSupplier<Boolean> resultSupplier = new SettableSupplier<>();
    dataSources.compute(
        segment.getDataSource(),
        (k, v) -> {
          final DataSourceState dataSourceState = v == null ? new DataSourceState() : v;
          final VersionedIntervalTimeline<String, ReferenceCountingSegment> loadedIntervals =
              dataSourceState.getTimeline();
          final PartitionChunk<ReferenceCountingSegment> entry = loadedIntervals.findChunk(
              segment.getInterval(),
              segment.getVersion(),
              segment.getShardSpec().getPartitionNum()
          );
          if (entry != null) {
            log.warn("Told to load an adapter for segment[%s] that already exists", segment.getId());
            resultSupplier.set(false);
          } else {
            IndexedTable table = adapter.as(IndexedTable.class);
            if (table != null) {
              if (dataSourceState.isEmpty() || dataSourceState.numSegments == dataSourceState.tablesLookup.size()) {
                dataSourceState.tablesLookup.put(segment.getId(), new ReferenceCountingIndexedTable(table));
              } else {
                log.error("Cannot load segment[%s] with IndexedTable, no existing segments are joinable", segment.getId());
              }
            } else if (dataSourceState.tablesLookup.size() > 0) {
              log.error("Cannot load segment[%s] without IndexedTable, all existing segments are joinable", segment.getId());
            }
            loadedIntervals.add(
                segment.getInterval(),
                segment.getVersion(),
                segment.getShardSpec().createChunk(adapter)
            );
            dataSourceState.addSegment(segment);
            segmentLoader.loadSegmentIntoPageCache(segment, loadSegmentIntoPageCacheExec);
            resultSupplier.set(true);
          }
          return dataSourceState;
        }
    );
    return resultSupplier.get();
  }
public boolean loadSegment ( final DataSegment segment , boolean lazy , SegmentLazyLoadFailCallback loadFailed , ExecutorService loadSegmentIntoPageCacheExec ) throws SegmentLoadingException { final ReferenceCountingSegment adapter = getSegmentReference ( segment , lazy , loadFailed ) ; final SettableSupplier < Boolean > resultSupplier = new SettableSupplier < > ( ) ; dataSources . compute ( segment . getDataSource ( ) , ( k , v ) -> { final DataSourceState dataSourceState = v == null ? new DataSourceState ( ) : v ; final VersionedIntervalTimeline < String , ReferenceCountingSegment > loadedIntervals = dataSourceState . getTimeline ( ) ; final PartitionChunk < ReferenceCountingSegment > entry = loadedIntervals . findChunk ( segment . getInterval ( ) , segment . getVersion ( ) , segment . getShardSpec ( ) . getPartitionNum ( ) ) ; if ( entry != null ) { log . warn ( "Told to load an adapter for segment[%s] that already exists" , segment . getId ( ) ) ; resultSupplier . set ( false ) ; } else { IndexedTable table = adapter . as ( IndexedTable . class ) ; if ( table != null ) { if ( dataSourceState . isEmpty ( ) || dataSourceState . numSegments == dataSourceState . tablesLookup . size ( ) ) { dataSourceState . tablesLookup . put ( segment . getId ( ) , new ReferenceCountingIndexedTable ( table ) ) ; } else { log . error ( "Cannot load segment[%s] with IndexedTable, no existing segments are joinable" , segment . getId ( ) ) ; } } else if ( dataSourceState . tablesLookup . size ( ) > 0 ) { log . error ( "Cannot load segment[%s] without IndexedTable, all existing segments are joinable" , segment . getId ( ) ) ; } loadedIntervals . add ( segment . getInterval ( ) , segment . getVersion ( ) , segment . getShardSpec ( ) . createChunk ( adapter ) ) ; dataSourceState . addSegment ( segment ) ; segmentLoader . loadSegmentIntoPageCache ( segment , loadSegmentIntoPageCacheExec ) ; resultSupplier . set ( true ) ; } return dataSourceState ; } ) ; return resultSupplier . get ( ) ; }
Load a single segment.
Load a single segment .
// compute() is used to ensure that the operation for a data source is executed atomically // Asyncly load segment index files into page cache in a thread pool