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 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 dataSegment, SegmentLazyLoadFailCallback loadFailed) Similar toSegmentCacheManager.load(DataSegment), this method loads segments during startup on data nodes.booleanReturn whether the cache manager can handle segments or not.booleancanLoadSegmentOnDemand(DataSegment dataSegment) 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 toSegmentCacheManager.acquireCachedSegment(SegmentId), to return theFilelocation of the segment files stored in the cache, instead of aOptional<Segment>.ConcurrentHashMap<DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock> getSegmentReferenceProvider(DataSegment segment) Testing use only please, any callers that want to do stuff with segments should useacquireCachedSegment(SegmentId)oracquireSegment(DataSegment)instead.CollectStorageStats, if available.voidload(DataSegment dataSegment) 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 viaSegmentCacheManager.acquireCachedSegment(SegmentId)orSegmentCacheManager.acquireSegment(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.
-
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
-
canLoadSegmentsOnDemand
public boolean canLoadSegmentsOnDemand()- Specified by:
canLoadSegmentsOnDemandin interfaceSegmentCacheManager
-
canLoadSegmentOnDemand
- Specified by:
canLoadSegmentOnDemandin 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:
-
acquireCachedSegment
Description copied from interface:SegmentCacheManagerApplies 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.- Specified by:
acquireCachedSegmentin interfaceSegmentCacheManager
-
acquireSegment
Description copied from interface:SegmentCacheManagerReturns 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.- Specified by:
acquireSegmentin interfaceSegmentCacheManager
-
load
Description copied from interface:SegmentCacheManagerGiven 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 viaSegmentCacheManager.acquireCachedSegment(SegmentId)orSegmentCacheManager.acquireSegment(DataSegment). If the segment cannot be loaded either due to error or insufficient storage space, this method throws aSegmentLoadingException.- Specified by:
loadin interfaceSegmentCacheManager- Parameters:
dataSegment- 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
public void bootstrap(DataSegment dataSegment, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException Description copied from interface:SegmentCacheManagerSimilar toSegmentCacheManager.load(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 callingSegmentCacheManager.shutdownBootstrap()- Specified by:
bootstrapin 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 or insufficient storage space- See Also:
-
getSegmentFiles
Description copied from interface:SegmentCacheManagerAlternative toSegmentCacheManager.acquireCachedSegment(SegmentId), to return theFilelocation of the segment files stored in the cache, instead of aOptional<Segment>. UnlikeSegmentCacheManager.acquireCachedSegment(SegmentId)andSegmentCacheManager.acquireSegment(DataSegment), this method does not provide any protections for callers, and should only be used by callers that are in control of whenSegmentCacheManager.drop(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 useSegmentCacheManager.load(DataSegment)before calling this method.- Specified by:
getSegmentFilesin interfaceSegmentCacheManager
-
drop
Description copied from interface:SegmentCacheManagerCleanup the segment files cache space used by the segment, releasing theStorageLocationreservation- Specified by:
dropin 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.- Specified by:
shutdownBootstrapin interfaceSegmentCacheManager
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceSegmentCacheManager
-
getStorageStats
Description copied from interface:SegmentCacheManagerCollectStorageStats, if available.- Specified by:
getStorageStatsin interfaceSegmentCacheManager
-
getSegmentLocks
public ConcurrentHashMap<DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock> getSegmentLocks() -
getSegmentReferenceProvider
Testing use only please, any callers that want to do stuff with segments should useacquireCachedSegment(SegmentId)oracquireSegment(DataSegment)instead. Does not hold locks and so is not really safe to use while the cache manager is active
-