Package org.apache.druid.segment.loading
Class SegmentLocalCacheManager
java.lang.Object
org.apache.druid.segment.loading.SegmentLocalCacheManager
- All Implemented Interfaces:
SegmentCacheManager
-
Constructor Summary
ConstructorsConstructorDescriptionSegmentLocalCacheManager(List<StorageLocation> locations, SegmentLoaderConfig config, StorageLocationSelectorStrategy strategy, IndexIO indexIO, com.fasterxml.jackson.databind.ObjectMapper mapper) -
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 dataSegment, SegmentLazyLoadFailCallback loadFailed) Similar toSegmentCacheManager.getSegment(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 dataSegment) Returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimeline.getSegmentFiles(DataSegment segment) Make sure segments files in loc is intact, otherwise function like loadSegments will failed because of segment files is damaged.ConcurrentHashMap<DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock> voidloadSegmentIntoPageCache(DataSegment segment) Asynchronously load the supplied segment into the page cache on each download after the service finishes bootstrapping.voidSimilar toSegmentCacheManager.loadSegmentIntoPageCache(DataSegment), but asynchronously load the supplied segment into the page cache during service bootstrap.booleanrelease(DataSegment segment) Reverts the effects ofSegmentCacheManager.reserve(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.
-
Constructor Details
-
SegmentLocalCacheManager
@Inject public SegmentLocalCacheManager(List<StorageLocation> locations, SegmentLoaderConfig config, @Nonnull StorageLocationSelectorStrategy strategy, IndexIO indexIO, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
canHandleSegments
public boolean canHandleSegments()Description copied from interface:SegmentCacheManagerReturn whether the cache manager can handle segments or not.- Specified by:
canHandleSegmentsin interfaceSegmentCacheManager
-
getCachedSegments
Description copied from interface:SegmentCacheManagerReturn a list of cached segments from local disk, if any. This should be called only whenSegmentCacheManager.canHandleSegments()is true.- Specified by:
getCachedSegmentsin interfaceSegmentCacheManager- Throws:
IOException
-
storeInfoFile
Description copied from interface:SegmentCacheManagerStore a segment info file for the supplied segment on disk. This operation is idempotent when called multiple times for a given segment.- Specified by:
storeInfoFilein interfaceSegmentCacheManager- Throws:
IOException
-
removeInfoFile
Description copied from interface:SegmentCacheManagerRemove the segment info file for the supplied segment from disk. If the file cannot be deleted, do nothing.- Specified by:
removeInfoFilein interfaceSegmentCacheManager- See Also:
-
getSegment
public ReferenceCountedSegmentProvider getSegment(DataSegment dataSegment) throws SegmentLoadingException Description copied from interface:SegmentCacheManagerReturns 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.- Specified by:
getSegmentin interfaceSegmentCacheManager- Parameters:
dataSegment- Segment to get on each download after service bootstrap- Throws:
SegmentLoadingException- If there is an error in loading the segment- See Also:
-
getBootstrapSegment
public ReferenceCountedSegmentProvider getBootstrapSegment(DataSegment dataSegment, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException Description copied from interface:SegmentCacheManagerSimilar toSegmentCacheManager.getSegment(DataSegment), this method returns aReferenceCountedSegmentProviderthat will be added by theSegmentManagerto theVersionedIntervalTimelineduring startup on data nodes.- Specified by:
getBootstrapSegmentin interfaceSegmentCacheManager- Parameters:
dataSegment- 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
Make sure segments files in loc is intact, otherwise function like loadSegments will failed because of segment files is damaged.- Specified by:
getSegmentFilesin interfaceSegmentCacheManager- Parameters:
segment-- Returns:
- Throws:
SegmentLoadingException
-
reserve
- Specified by:
reservein interfaceSegmentCacheManager
-
release
Description copied from interface:SegmentCacheManagerReverts the effects ofSegmentCacheManager.reserve(DataSegment)by releasing the location reserved for this segment. Callers that explicitly reserve the space viaSegmentCacheManager.reserve(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
SegmentCacheManager.cleanup(DataSegment). Only return a boolean instead of a pointer toStorageLocationsince we don't want callers to operate onStorageLocationdirectly outside this interface.- Specified by:
releasein interfaceSegmentCacheManager- Parameters:
segment- - Segment to release the location for.- Returns:
- - True if any location was reserved and released, false otherwise.
-
cleanup
Description copied from interface:SegmentCacheManagerCleanup the segment files cache space used by the segment. It will not release the space if the space has been explicitly reserved viaSegmentCacheManager.reserve(DataSegment).- Specified by:
cleanupin interfaceSegmentCacheManager- See Also:
-
loadSegmentIntoPageCache
Description copied from interface:SegmentCacheManagerAsynchronously 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.- Specified by:
loadSegmentIntoPageCachein interfaceSegmentCacheManager- See Also:
-
loadSegmentIntoPageCacheOnBootstrap
Description copied from interface:SegmentCacheManagerSimilar toSegmentCacheManager.loadSegmentIntoPageCache(DataSegment), but asynchronously load the supplied segment into the page cache during service bootstrap.- Specified by:
loadSegmentIntoPageCacheOnBootstrapin interfaceSegmentCacheManager- See Also:
-
shutdownBootstrap
public void shutdownBootstrap()Description copied from interface:SegmentCacheManagerShutdown any previously set up bootstrap executor to save resources. This should be called after loading bootstrap segments into the page cache.- Specified by:
shutdownBootstrapin interfaceSegmentCacheManager
-
getSegmentLocks
public ConcurrentHashMap<DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock> getSegmentLocks() -
getLocations
-