Package org.apache.druid.segment.loading
Interface SegmentCacheManager
- All Known Implementing Classes:
SegmentLocalCacheManager
public interface SegmentCacheManager
A class to fetch segment files from deep storage to local disk and manage the local cache. Implementations must be
thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionacquireCachedSegment(SegmentId segmentId) Applies aSegmentMapFunctionto aSegmentif it is available in the cache.acquireSegment(DataSegment dataSegment) Returns aAcquireSegmentActionfor a givenDataSegmentandSegmentDescriptor, which returns a reference provider for theSegmentif already present in the cache, or tries to fetch from deep storage and map if not.voidbootstrap(DataSegment segment, SegmentLazyLoadFailCallback loadFailed) Similar toload(DataSegment), this method loads segments during startup on data nodes.booleanReturn whether the cache manager can handle segments or not.booleancanLoadSegmentOnDemand(DataSegment segment) booleanvoiddrop(DataSegment segment) Cleanup the segment files cache space used by the segment, releasing theStorageLocationreservationReturn a list of cached segments from local disk, if any.getSegmentFiles(DataSegment segment) Alternative toacquireCachedSegment(SegmentId), to return theFilelocation of the segment files stored in the cache, instead of aOptional<Segment>.CollectStorageStats, if available.voidload(DataSegment segment) Given aDataSegment, which contains the instructions for where and how to fetch aSegmentfrom deep storage, this method tries to load and subsequently serve it to callers viaacquireCachedSegment(SegmentId)oracquireSegment(DataSegment).voidremoveInfoFile(DataSegment segment) Remove the segment info file for the supplied segment from disk.voidshutdown()voidShutdown any previously set-up bootstrap executor to save resources.voidstoreInfoFile(DataSegment segment) Store a segment info file for the supplied segment on disk.
-
Method Details
-
canHandleSegments
boolean canHandleSegments()Return whether the cache manager can handle segments or not. -
canLoadSegmentsOnDemand
boolean canLoadSegmentsOnDemand() -
canLoadSegmentOnDemand
-
getCachedSegments
Return a list of cached segments from local disk, if any. This should be called only whencanHandleSegments()is true.- Throws:
IOException
-
storeInfoFile
Store a segment info file for the supplied segment on disk. This operation is idempotent when called multiple times for a given segment.- Throws:
IOException
-
removeInfoFile
Remove the segment info file for the supplied segment from disk. If the file cannot be deleted, do nothing.- See Also:
-
load
Given aDataSegment, which contains the instructions for where and how to fetch aSegmentfrom deep storage, this method tries to load and subsequently serve it to callers viaacquireCachedSegment(SegmentId)oracquireSegment(DataSegment). If the segment cannot be loaded either due to error or insufficient storage space, this method throws aSegmentLoadingException.- Parameters:
segment- Segment to get on each download (after service bootstrap)- Throws:
SegmentLoadingException- If there is an error in loading the segment or insufficient storage space- See Also:
-
bootstrap
void bootstrap(DataSegment segment, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException Similar toload(DataSegment), this method loads segments during startup on data nodes. Implementations of this method may be configured to use a larger than normal work pool that only exists during startup and is shutdown after startup by callingshutdownBootstrap()- Parameters:
segment- Segment to retrieve during service bootstraploadFailed- Callback to execute when segment lazy load failed. This applies only whenlazyLoadOnStartis enabled- Throws:
SegmentLoadingException- - If there is an error in loading the segment or insufficient storage space- See Also:
-
drop
Cleanup the segment files cache space used by the segment, releasing theStorageLocationreservation- See Also:
-
acquireCachedSegment
Applies aSegmentMapFunctionto aSegmentif it is available in the cache. If not present in any storage location, this method will not attempt to download theDataSegmentfrom deep storage. TheSegmentreturned by this method is considered an open reference, cache implementations must not allow it to be dropped until it has been closed. As such, the returnedSegmentmust be closed when the caller is finished doing segment things. -
acquireSegment
Returns aAcquireSegmentActionfor a givenDataSegmentandSegmentDescriptor, which returns a reference provider for theSegmentif already present in the cache, or tries to fetch from deep storage and map if not. TheSegmentreturned by the provider returned by this method are considered an open reference, cache implementations must not allow the segment to be dropped until it has been closed. As such, the returnedSegmentfromReferenceCountedObjectProvider.acquireReference()must be closed when the caller is finished doing segment things. -
getSegmentFiles
Alternative toacquireCachedSegment(SegmentId), to return theFilelocation of the segment files stored in the cache, instead of aOptional<Segment>. UnlikeacquireCachedSegment(SegmentId)andacquireSegment(DataSegment), this method does not provide any protections for callers, and should only be used by callers that are in control of whendrop(DataSegment)is called. This method will not download the segment files from deep storage if they do not already exist in the cache, callers should useload(DataSegment)before calling this method.- Throws:
SegmentLoadingException
-
shutdownBootstrap
void shutdownBootstrap()Shutdown any previously set-up bootstrap executor to save resources. This should be called after loading bootstrap segments. -
shutdown
void shutdown() -
getStorageStats
CollectStorageStats, if available.
-