Package org.apache.druid.server
Class SegmentManager
java.lang.Object
org.apache.druid.server.SegmentManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresent the state of a data source including the timeline, total segment size, and number of segments. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn whether the cache manager can handle segments or not.voiddropSegment(DataSegment segment) Return a list of cached segments, if any.Returns a map of dataSource to the number of segments managed by this segmentManager.Returns a map of dataSource to the total byte size of segments managed by this segmentManager.getIndexedTables(TableDataSource dataSource) Returns the collection ofIndexedTablefor 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.getTimeline(TableDataSource dataSource) Returns the timeline for a datasource, if it exists.booleanhasIndexedTables(String dataSourceName) voidloadSegment(DataSegment dataSegment) Load the supplied segment into page cache.voidloadSegmentOnBootstrap(DataSegment dataSegment, SegmentLazyLoadFailCallback loadFailed) Load the supplied segment into page cache on bootstrap.voidShutdown the bootstrap executor to save resources.
-
Constructor Details
-
SegmentManager
-
-
Method Details
-
getDataSourceNames
-
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
-
getRowCountDistribution
-
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
public Optional<VersionedIntervalTimeline<String,ReferenceCountedSegmentProvider>> getTimeline(TableDataSource dataSource) 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 ofIndexedTablefor 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
-
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 bootstraploadFailed- callback to execute when segment lazy load fails. This applies only when lazy loading is enabled.- Throws:
SegmentLoadingException- if the segment cannot be loadedIOException- if the segment info cannot be cached on disk
-
loadSegment
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. UnlikeloadSegmentOnBootstrap(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 loadedIOException- if the segment info cannot be cached on disk
-
dropSegment
-
canHandleSegments
public boolean canHandleSegments()Return whether the cache manager can handle segments or not. -
getCachedSegments
Return a list of cached segments, if any. This should be called only whencanHandleSegments()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.
-