Class SegmentManager
-
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 TypeMethodDescriptionacquireCachedSegment(DataSegment dataSegment) Convenience overload ofacquireCachedSegment(SegmentId)that accepts aDataSegment.acquireCachedSegment(SegmentId segmentId) Returns aSegmenttransformed with aSegmentMapFunction, if it is available in the cache.acquireSegment(DataSegment dataSegment) Returns aAcquireSegmentAction, where callingAcquireSegmentAction.getSegmentFuture()will either return immediately if theSegmentis in the cache, or possibly try to fetch the segment from deep storage if not.booleanReturn whether the cache manager can handle segments or not.booleancanLoadSegmentOnDemand(DataSegment dataSegment) booleanvoiddropSegment(DataSegment dataSegment) 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.getSegmentsBundle(List<DataSegmentAndDescriptor> segments, SegmentMapFunction segmentMapFunction) Given a list ofDataSegmentAndDescriptorproduce aLeafSegmentsBundlewhich partitions segments into cached, loadable, or missing segments.getTimeline(TableDataSource dataSource) Returns the timeline for a datasource, if it exists.booleanhasIndexedTables(String dataSourceName) voidloadSegment(DataSegment dataSegment) Load the supplied segment into segment cache.voidloadSegmentOnBootstrap(DataSegment dataSegment, SegmentLazyLoadFailCallback loadFailed) Load the supplied segment into segment cache on bootstrap.voidshutdown()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 used 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,DataSegment>> 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. -
getSegmentsBundle
public LeafSegmentsBundle getSegmentsBundle(List<DataSegmentAndDescriptor> segments, SegmentMapFunction segmentMapFunction) Given a list ofDataSegmentAndDescriptorproduce aLeafSegmentsBundlewhich partitions segments into cached, loadable, or missing segments. This gives callers the flexibilty to decide to perform operations on segments which are already cached prior to or alongside the operation to load any segments which are not already present in the cache on demand.What this means mechanically, is that for each
DataSegmentAndDescriptorwe check if it is already cached withacquireCachedSegment(DataSegment)to add toLeafSegmentsBundle.cachedSegments, else ifcanLoadSegmentOnDemand(DataSegment)is true it is added toLeafSegmentsBundle.loadableSegmentsorLeafSegmentsBundle.missingSegmentsif not.The segments in
LeafSegmentsBundle.loadableSegmentscan be retrieved withacquireSegment(DataSegment)to ensure they are loaded from deep storage. -
acquireCachedSegment
Returns aSegmenttransformed with aSegmentMapFunction, if it is available in the cache. The returnedSegmentmust be closed when the caller is finished doing segment things. This method will not download aDataSegmentif it is not already present incacheManager, useacquireSegment(DataSegment)instead. -
acquireCachedSegment
Convenience overload ofacquireCachedSegment(SegmentId)that accepts aDataSegment. -
acquireSegment
Returns aAcquireSegmentAction, where callingAcquireSegmentAction.getSegmentFuture()will either return immediately if theSegmentis in the cache, or possibly try to fetch the segment from deep storage if not. The returnedSegment, if present, must be closed when the caller is finished doing segment things.Calling this method is treated as an intent to acquire and use the segment via resolving the future, and cache manager implementations will place a hold on this segment until the 'loadCleanup' closer is closed - typically after resolving the future to acquire the reference to the actual
Segmentobject. -
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 segment cache on bootstrap. If the segment is already loaded, this method does not reload the segment into the segment 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 segment cache. If the segment is already loaded, this method does not reload the segment into the segment 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. -
canLoadSegmentsOnDemand
public boolean canLoadSegmentsOnDemand() -
canLoadSegmentOnDemand
-
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. -
shutdown
public void shutdown()
-