Package org.apache.druid.segment.loading
Class StorageLocation
- java.lang.Object
-
- org.apache.druid.segment.loading.StorageLocation
-
public class StorageLocation extends Object
This class is a very simple logical representation of a local path. It keeps track of files stored under thepathviareserve(java.lang.String, org.apache.druid.timeline.DataSegment), so that the total size of stored files doesn't exceed themaxSizeBytesand available space is always kept smaller thanfreeSpaceToKeep. This class is thread-safe, so that multiple threads can update its state at the same time. One example usage is that a historical can use multiple threads to load different segments in parallel from deep storage.
-
-
Constructor Summary
Constructors Constructor Description StorageLocation(File path, long maxSizeBytes, Double freeSpacePercent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longavailableSizeBytes()longcurrSizeBytes()FilegetPath()booleanisReserved(String segmentDir)voidmaybeReserve(String segmentFilePathToAdd, org.apache.druid.timeline.DataSegment segment)Reserves space to store the given segment, only if it has not been done already.booleanrelease(String segmentFilePath, long segmentSize)voidremoveFile(File file)Remove a segment file from this location.voidremoveSegmentDir(File segmentDir, org.apache.druid.timeline.DataSegment segment)Remove a segment dir from this location.Filereserve(String segmentFilePathToAdd, String segmentId, long segmentSize)Reserves space to store the given segment.Filereserve(String segmentDir, org.apache.druid.timeline.DataSegment segment)Reserves space to store the given segment.FilesegmentDirectoryAsFile(String segmentDir)
-
-
-
Method Detail
-
getPath
public File getPath()
-
removeFile
public void removeFile(File file)
Remove a segment file from this location. The given file argument must be a file rather than directory.
-
removeSegmentDir
public void removeSegmentDir(File segmentDir, org.apache.druid.timeline.DataSegment segment)
Remove a segment dir from this location. The segment size is subtracted from currSizeBytes.
-
reserve
@Nullable public File reserve(String segmentDir, org.apache.druid.timeline.DataSegment segment)
Reserves space to store the given segment. The segment size is added to currSizeBytes. If it succeeds, it returns a file for the given segmentDir in this storage location. Returns null otherwise.
-
isReserved
public boolean isReserved(String segmentDir)
-
maybeReserve
public void maybeReserve(String segmentFilePathToAdd, org.apache.druid.timeline.DataSegment segment)
Reserves space to store the given segment, only if it has not been done already. This can be used when segment is already downloaded on the disk. Unlikereserve(String, DataSegment), this function skips the check on disk availability. We also account for segment usage even if available size dips below 0. Such a situation indicates a configuration problem or a bug and we don't let segment loading fail because of this.
-
reserve
@Nullable public File reserve(String segmentFilePathToAdd, String segmentId, long segmentSize)
Reserves space to store the given segment. If it succeeds, it returns a file for the given segmentFilePathToAdd in this storage location. Returns null otherwise.
-
release
public boolean release(String segmentFilePath, long segmentSize)
-
availableSizeBytes
public long availableSizeBytes()
-
currSizeBytes
public long currSizeBytes()
-
-