Class FileHandle

All Implemented Interfaces:
AutoCloseable, SharedCloseable

public class FileHandle extends SharedCloseableImpl
FileHandle provides access to a file for reading, including the ones written by various SequentialWriter instances, and it is typically used by SSTableReader.

Use FileHandle.Builder to create an instance, and call createReader() (and its variants) to access the readers for the underlying file.

You can use FileHandle.Builder.complete() several times during its lifecycle with different overrideLength(i.e. early opening file). For that reason, the builder keeps a reference to the file channel and makes a copy for each FileHandle.Builder.complete() call. Therefore, it is important to close the FileHandle.Builder when it is no longer needed, as well as any FileHandle instances.

  • Field Details

    • channel

      public final ChannelProxy channel
    • onDiskLength

      public final long onDiskLength
  • Method Details

    • file

      public File file()
      Returns:
      file this factory is referencing
    • path

      public String path()
    • dataLength

      public long dataLength()
    • rebuffererFactory

      public RebuffererFactory rebuffererFactory()
    • compressionMetadata

      public Optional<CompressionMetadata> compressionMetadata()
    • addTo

      public void addTo(Ref.IdentityCollection identities)
      Specified by:
      addTo in interface SharedCloseable
      Overrides:
      addTo in class SharedCloseableImpl
    • sharedCopy

      public FileHandle sharedCopy()
      Returns:
      a new instance of the object representing the same state and backed by the same underlying resources. Coordinates with the original (and other instances) when the underlying resource should be closed. Throws an exception if the shared resource has already been closed.
    • createReader

      public RandomAccessReader createReader()
      Create RandomAccessReader with configured method of reading content of the file.
      Returns:
      RandomAccessReader for the file
    • createReaderForScan

      public RandomAccessReader createReaderForScan()
    • createReader

      public RandomAccessReader createReader(com.google.common.util.concurrent.RateLimiter limiter)
      Create RandomAccessReader with configured method of reading content of the file. Reading from file will be rate limited by given RateLimiter.
      Parameters:
      limiter - RateLimiter to use for rate limiting read
      Returns:
      RandomAccessReader for the file
    • createReader

      public RandomAccessReader createReader(com.google.common.util.concurrent.RateLimiter limiter, boolean forScan)
    • createReader

      public FileDataInput createReader(long position)
    • dropPageCache

      public void dropPageCache(long before)
      Drop page cache from start to given before.
      Parameters:
      before - uncompressed position from start of the file to be dropped from cache. if 0, to end of file.
    • instantiateRebufferer

      public Rebufferer instantiateRebufferer(com.google.common.util.concurrent.RateLimiter limiter)
    • instantiateRebufferer

      public Rebufferer instantiateRebufferer(com.google.common.util.concurrent.RateLimiter limiter, boolean forScan)
    • toString

      public String toString()
      Overrides:
      toString in class Object