Package org.apache.druid.segment.loading
Class SegmentLocalCacheManager
- java.lang.Object
-
- org.apache.druid.segment.loading.SegmentLocalCacheManager
-
- All Implemented Interfaces:
SegmentCacheManager
public class SegmentLocalCacheManager extends Object implements SegmentCacheManager
-
-
Constructor Summary
Constructors Constructor Description SegmentLocalCacheManager(List<StorageLocation> locations, SegmentLoaderConfig config, StorageLocationSelectorStrategy strategy, com.fasterxml.jackson.databind.ObjectMapper mapper)SegmentLocalCacheManager(SegmentLoaderConfig config, com.fasterxml.jackson.databind.ObjectMapper mapper)creates instance with default storage location selector strategy This ctor is mainly for test cases, including test cases in other modules
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup(org.apache.druid.timeline.DataSegment segment)Cleanup the cache space used by the segment.List<StorageLocation>getLocations()FilegetSegmentFiles(org.apache.druid.timeline.DataSegment segment)Make sure segments files in loc is intact, otherwise function like loadSegments will failed because of segment files is damaged.ConcurrentHashMap<org.apache.druid.timeline.DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock>getSegmentLocks()booleanisSegmentCached(org.apache.druid.timeline.DataSegment segment)Checks whether a segment is already cached.voidloadSegmentIntoPageCache(org.apache.druid.timeline.DataSegment segment, ExecutorService exec)Asyncly load segment into page cache.booleanrelease(org.apache.druid.timeline.DataSegment segment)Reverts the effects ofSegmentCacheManager.reserve(DataSegment)(DataSegment)} by releasing the location reserved for this segment.booleanreserve(org.apache.druid.timeline.DataSegment segment)Tries to reserve the space for a segment on any location.
-
-
-
Constructor Detail
-
SegmentLocalCacheManager
@Inject public SegmentLocalCacheManager(List<StorageLocation> locations, SegmentLoaderConfig config, @Nonnull StorageLocationSelectorStrategy strategy, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
SegmentLocalCacheManager
public SegmentLocalCacheManager(SegmentLoaderConfig config, com.fasterxml.jackson.databind.ObjectMapper mapper)
creates instance with default storage location selector strategy This ctor is mainly for test cases, including test cases in other modules
-
-
Method Detail
-
isSegmentCached
public boolean isSegmentCached(org.apache.druid.timeline.DataSegment segment)
Description copied from interface:SegmentCacheManagerChecks whether a segment is already cached. It can return false even ifSegmentCacheManager.reserve(DataSegment)has been successful for a segment but is not downloaded yet.- Specified by:
isSegmentCachedin interfaceSegmentCacheManager
-
getSegmentFiles
public File getSegmentFiles(org.apache.druid.timeline.DataSegment segment) throws org.apache.druid.segment.loading.SegmentLoadingException
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:
org.apache.druid.segment.loading.SegmentLoadingException
-
reserve
public boolean reserve(org.apache.druid.timeline.DataSegment segment)
Description copied from interface:SegmentCacheManagerTries to reserve the space for a segment on any location. When the space has been reserved,SegmentCacheManager.getSegmentFiles(DataSegment)should download the segment on the reserved location or fail otherwise. This function is useful for custom extensions. Extensions can try to reserve the space first and if not successful, make some space by cleaning up other segments, etc. There is also improved concurrency for extensions with this function. Since reserve is a cheaper operation to invoke till the space has been reserved. Hence it can be put inside a lock if required by the extensions. getSegment can't be put inside a lock since it is a time-consuming operation, on account of downloading the files.- Specified by:
reservein interfaceSegmentCacheManager- Parameters:
segment- - Segment to reserve- Returns:
- True if enough space found to store the segment, false otherwise
-
release
public boolean release(org.apache.druid.timeline.DataSegment segment)
Description copied from interface:SegmentCacheManagerReverts the effects ofSegmentCacheManager.reserve(DataSegment)(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 viaSegmentCacheManager.cleanup(DataSegment)- Specified by:
releasein interfaceSegmentCacheManager- Parameters:
segment- - Segment to release the location for.- Returns:
- - True if any location was reserved and released, false otherwise.
-
cleanup
public void cleanup(org.apache.druid.timeline.DataSegment segment)
Description copied from interface:SegmentCacheManagerCleanup the 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
-
loadSegmentIntoPageCache
public void loadSegmentIntoPageCache(org.apache.druid.timeline.DataSegment segment, ExecutorService exec)Description copied from interface:SegmentCacheManagerAsyncly load segment into page cache. 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- Parameters:
segment- The segment to load its index files into page cacheexec- The thread pool to use
-
getSegmentLocks
public ConcurrentHashMap<org.apache.druid.timeline.DataSegment,org.apache.druid.segment.loading.SegmentLocalCacheManager.ReferenceCountingLock> getSegmentLocks()
-
getLocations
public List<StorageLocation> getLocations()
-
-