Package org.apache.cassandra.io.util
Class FileHandle
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.SharedCloseableImpl
-
- org.apache.cassandra.io.util.FileHandle
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,SharedCloseable
public class FileHandle extends SharedCloseableImpl
FileHandle
provides access to a file for reading, including the ones written by variousSequentialWriter
instances, and it is typically used bySSTableReader
.Use
FileHandle.Builder
to create an instance, and callcreateReader()
(and its variants) to access the readers for the underlying file.You can use
FileHandle.Builder.complete()
several times during its lifecycle with differentoverrideLength
(i.e. early opening file). For that reason, the builder keeps a reference to the file channel and makes a copy for eachFileHandle.Builder.complete()
call. Therefore, it is important to close theFileHandle.Builder
when it is no longer needed, as well as anyFileHandle
instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileHandle.Builder
Configures how the file will be read (compressed, mmapped, use cache etc.)
-
Field Summary
Fields Modifier and Type Field Description ChannelProxy
channel
long
onDiskLength
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTo(Ref.IdentityCollection identities)
java.util.Optional<CompressionMetadata>
compressionMetadata()
RandomAccessReader
createReader()
CreateRandomAccessReader
with configured method of reading content of the file.FileDataInput
createReader(long position)
RandomAccessReader
createReader(com.google.common.util.concurrent.RateLimiter limiter)
CreateRandomAccessReader
with configured method of reading content of the file.long
dataLength()
void
dropPageCache(long before)
Drop page cache from start to givenbefore
.File
file()
Rebufferer
instantiateRebufferer(com.google.common.util.concurrent.RateLimiter limiter)
java.lang.String
path()
RebuffererFactory
rebuffererFactory()
FileHandle
sharedCopy()
java.lang.String
toString()
-
Methods inherited from class org.apache.cassandra.utils.concurrent.SharedCloseableImpl
close, close, isCleanedUp
-
-
-
-
Field Detail
-
channel
public final ChannelProxy channel
-
onDiskLength
public final long onDiskLength
-
-
Method Detail
-
file
public File file()
- Returns:
- file this factory is referencing
-
path
public java.lang.String path()
-
dataLength
public long dataLength()
-
rebuffererFactory
public RebuffererFactory rebuffererFactory()
-
compressionMetadata
public java.util.Optional<CompressionMetadata> compressionMetadata()
-
addTo
public void addTo(Ref.IdentityCollection identities)
- Specified by:
addTo
in interfaceSharedCloseable
- Overrides:
addTo
in classSharedCloseableImpl
-
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()
CreateRandomAccessReader
with configured method of reading content of the file.- Returns:
- RandomAccessReader for the file
-
createReader
public RandomAccessReader createReader(com.google.common.util.concurrent.RateLimiter limiter)
CreateRandomAccessReader
with configured method of reading content of the file. Reading from file will be rate limited by givenRateLimiter
.- Parameters:
limiter
- RateLimiter to use for rate limiting read- Returns:
- RandomAccessReader for the file
-
createReader
public FileDataInput createReader(long position)
-
dropPageCache
public void dropPageCache(long before)
Drop page cache from start to givenbefore
.- 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)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-