Package org.apache.druid.segment.loading
Interface SegmentCacheManager
- All Known Implementing Classes:
SegmentLocalCacheManager
public interface SegmentCacheManager
A class to fetch segment files to local disk and manage the local cache.
Implementations must be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn whether the cache manager can handle segments or not.voidcleanup(DataSegment segment) Cleanup the segment files cache space used by the segment.getBootstrapSegment(DataSegment segment, SegmentLazyLoadFailCallback loadFailed) Similar togetSegment(DataSegment), this method returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimelineduring startup on data nodes.Return a list of cached segments from local disk, if any.getSegment(DataSegment segment) Returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimeline.getSegmentFiles(DataSegment segment) This method fetches the files for the given segment if the segment is not downloaded already.voidloadSegmentIntoPageCache(DataSegment segment) Asynchronously load the supplied segment into the page cache on each download after the service finishes bootstrapping.voidSimilar toloadSegmentIntoPageCache(DataSegment), but asynchronously load the supplied segment into the page cache during service bootstrap.booleanrelease(DataSegment segment) Reverts the effects ofreserve(DataSegment)by releasing the location reserved for this segment.voidremoveInfoFile(DataSegment segment) Remove the segment info file for the supplied segment from disk.booleanreserve(DataSegment segment) 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. -
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:
-
getSegment
Returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimeline. This method can be called multiple times by theSegmentManagerand implementation can either return sameReferenceCountedSegmentProvideror a differentReferenceCountedSegmentProvider. Caller should not assume any particular behavior.Returning a
ReferenceCountingSegmentwill let custom implementations keep track of reference count for segments that the custom implementations are creating. That way, custom implementations can know when the segment is in use or not.- Parameters:
segment- Segment to get on each download after service bootstrap- Throws:
SegmentLoadingException- If there is an error in loading the segment- See Also:
-
getBootstrapSegment
ReferenceCountedSegmentProvider getBootstrapSegment(DataSegment segment, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException Similar togetSegment(DataSegment), this method returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimelineduring startup on data nodes.- 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- See Also:
-
getSegmentFiles
This method fetches the files for the given segment if the segment is not downloaded already. It is not required toreserve(DataSegment)before calling this method. If caller has not reserved the space explicitly viareserve(DataSegment), the implementation should reserve space on caller's behalf. If the space has been explicitly reserved already - implementation should use only the reserved space to store segment files. - implementation should not release the location in case of download erros and leave it to the caller.- Throws:
SegmentLoadingException- if there is an error in downloading files
-
loadSegmentIntoPageCache
Asynchronously load the supplied segment into the page cache on each download after the service finishes bootstrapping. Equivalent to `cat segment_files > /dev/null` to force loading the segment index files into page cache so that later when the segment is queried, they are already in page cache and only a minor page fault needs to be triggered instead of a major page fault to make the query latency more consistent. -
loadSegmentIntoPageCacheOnBootstrap
Similar toloadSegmentIntoPageCache(DataSegment), but asynchronously load the supplied segment into the page cache during service bootstrap.- See Also:
-
shutdownBootstrap
void shutdownBootstrap()Shutdown any previously set up bootstrap executor to save resources. This should be called after loading bootstrap segments into the page cache. -
reserve
-
release
Reverts the effects ofreserve(DataSegment)by releasing the location reserved for this segment. Callers that explicitly reserve the space viareserve(DataSegment)should use this method to release the space.Implementation can throw error if the space is being released but there is data present. Callers are supposed to ensure that any data is removed via
cleanup(DataSegment). Only return a boolean instead of a pointer toStorageLocationsince we don't want callers to operate onStorageLocationdirectly outside this interface.- Parameters:
segment- - Segment to release the location for.- Returns:
- - True if any location was reserved and released, false otherwise.
-
cleanup
Cleanup the segment files cache space used by the segment. It will not release the space if the space has been explicitly reserved viareserve(DataSegment).- See Also:
-