Class SegmentManager

java.lang.Object
org.apache.druid.server.SegmentManager

public class SegmentManager extends Object
This class is responsible for managing data sources and their states like timeline, total segment size, and number of segments. All public methods of this class must be thread-safe.
  • Constructor Details

  • Method Details

    • getDataSourceNames

      public Set<String> getDataSourceNames()
    • getDataSourceSizes

      public Map<String,Long> getDataSourceSizes()
      Returns a map of dataSource to the total byte size of segments managed by this segmentManager. This method should be used carefully because the returned map might be different from the actual data source states.
      Returns:
      a map of dataSources and their total byte sizes
    • getAverageRowCountForDatasource

      public Map<String,Long> getAverageRowCountForDatasource()
    • getRowCountDistribution

      public Map<String,SegmentRowCountDistribution> getRowCountDistribution()
    • getDataSourceCounts

      public Map<String,Long> getDataSourceCounts()
      Returns a map of dataSource to the number of segments managed by this segmentManager. This method should be carefully because the returned map might be different from the actual data source states.
      Returns:
      a map of dataSources and number of segments
    • getTimeline

      Returns the timeline for a datasource, if it exists. The analysis object passed in must represent a scan-based datasource of a single table.
    • getIndexedTables

      public Optional<Stream<ReferenceCountedIndexedTableProvider>> getIndexedTables(TableDataSource dataSource)
      Returns the collection of IndexedTable for the entire timeline (since join conditions do not currently consider the queries intervals), if the timeline exists for each of its segments that are joinable.
    • hasIndexedTables

      public boolean hasIndexedTables(String dataSourceName)
    • loadSegmentOnBootstrap

      public void loadSegmentOnBootstrap(DataSegment dataSegment, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException, IOException
      Load the supplied segment into page cache on bootstrap. If the segment is already loaded, this method does not reload the segment into the page cache.
      Parameters:
      dataSegment - segment to bootstrap
      loadFailed - callback to execute when segment lazy load fails. This applies only when lazy loading is enabled.
      Throws:
      SegmentLoadingException - if the segment cannot be loaded
      IOException - if the segment info cannot be cached on disk
    • loadSegment

      public void loadSegment(DataSegment dataSegment) throws SegmentLoadingException, IOException
      Load the supplied segment into page cache. If the segment is already loaded, this method does not reload the segment into the page cache. This method should be called for non-bootstrapping flows. Unlike loadSegmentOnBootstrap(DataSegment, SegmentLazyLoadFailCallback), this method doesn't accept a lazy load fail callback because the segment is loaded immediately.
      Parameters:
      dataSegment - segment to load
      Throws:
      SegmentLoadingException - if the segment cannot be loaded
      IOException - if the segment info cannot be cached on disk
    • dropSegment

      public void dropSegment(DataSegment segment)
    • canHandleSegments

      public boolean canHandleSegments()
      Return whether the cache manager can handle segments or not.
    • getCachedSegments

      public List<DataSegment> getCachedSegments() throws IOException
      Return a list of cached segments, if any. This should be called only when canHandleSegments() is true.
      Throws:
      IOException
    • shutdownBootstrap

      public void shutdownBootstrap()
      Shutdown the bootstrap executor to save resources. This should be called after loading bootstrap segments into the page cache.