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 the path via reserve(java.lang.String, org.apache.druid.timeline.DataSegment), so that the total size of stored files doesn't exceed the maxSizeBytes and available space is always kept smaller than freeSpaceToKeep. 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 Details

    • StorageLocation

      public StorageLocation(File path, long maxSizeBytes, @Nullable Double freeSpacePercent)
  • Method Details

    • 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, DataSegment segment)
      Remove a segment dir from this location. The segment size is subtracted from currSizeBytes.
    • reserve

      @Nullable public File reserve(String segmentDir, 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)
    • segmentDirectoryAsFile

      public File segmentDirectoryAsFile(String segmentDir)
    • maybeReserve

      public void maybeReserve(String segmentFilePathToAdd, 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. Unlike reserve(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()