Class SSTableReader
- java.lang.Object
-
- org.apache.cassandra.io.sstable.SSTable
-
- org.apache.cassandra.io.sstable.format.SSTableReader
-
- All Implemented Interfaces:
UnfilteredSource
,RefCounted<SSTableReader>
,SelfRefCounted<SSTableReader>
- Direct Known Subclasses:
SSTableReaderWithFilter
public abstract class SSTableReader extends SSTable implements UnfilteredSource, SelfRefCounted<SSTableReader>
An SSTableReader can be constructed in a number of places, but typically is either read from disk at startup, or constructed from a flushed memtable, or after compaction to replace some existing sstables. However once created, an sstablereader may also be modified.A reader's
SSTableReader.OpenReason
describes its current stage in its lifecycle. Note that in parallel to this, there are two different Descriptor types; TMPLINK and FINAL; the latter corresponds toSSTableReader.OpenReason.NORMAL
state readers and all readers that replace aSSTableReader.OpenReason.NORMAL
one. TMPLINK is used forSSTableReader.OpenReason.EARLY
state readers and no others.When a reader is being compacted, if the result is large its replacement may be opened as
SSTableReader.OpenReason.EARLY
before compaction completes in order to present the result to consumers earlier. In this case the reader will itself be changed to aSSTableReader.OpenReason.MOVED_START
state, where its start no longer represents its on-disk minimum key. This is to permit reads to be directed to only one reader when the two represent the same data. TheSSTableReader.OpenReason.EARLY
file can represent a compaction result that is either partially complete and still in-progress, or a complete and immutable sstable that is part of a larger macro compaction action that has not yet fully completed.Currently ALL compaction results at least briefly go through an
SSTableReader.OpenReason.EARLY
open state prior to completion, regardless of if early opening is enabled.Since a reader can be created multiple times over the same shared underlying resources, and the exact resources it shares between each instance differ subtly, we track the lifetime of any underlying resource with its own reference count, which each instance takes a
Ref
to. Each instance then tracks references to itself, and once these all expire it releases all itsRef
to these underlying resources.There is some shared cleanup behaviour needed only once all readers in a certain stage of their lifecycle (i.e.
SSTableReader.OpenReason.EARLY
orSSTableReader.OpenReason.NORMAL
opening), and some that must only occur once all readers of any kind over a single logical sstable have expired. These are managed by theSSTableReader.InstanceTidier
andSSTableReader.GlobalTidy
classes at the bottom, and are effectively managed as another resource each instance tracks its ownRef
instance to, to ensure all of these resources are cleaned up safely and can be debugged otherwise.TODO: fill in details about Tracker and lifecycle interactions for tools, and for compaction strategies
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SSTableReader.Builder<R extends SSTableReader,B extends SSTableReader.Builder<R,B>>
A builder of this sstable reader.static class
SSTableReader.IndexesBounds
protected static class
SSTableReader.InstanceTidier
One instance per SSTableReader we create.static class
SSTableReader.OpenReason
static class
SSTableReader.Operator
TODO: Move someplace reusablestatic class
SSTableReader.PartitionPositionBounds
static class
SSTableReader.UniqueIdentifier
-
Nested classes/interfaces inherited from class org.apache.cassandra.io.sstable.SSTable
SSTable.Owner
-
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.RefCounted
RefCounted.Tidy
-
-
Field Summary
Fields Modifier and Type Field Description AbstractBounds<Token>
bounds
protected FileHandle
dfile
protected DecoratedKey
first
static java.util.Comparator<SSTableReader>
firstKeyComparator
static com.google.common.collect.Ordering<SSTableReader>
firstKeyOrdering
SerializationHeader
header
static java.util.Comparator<SSTableReader>
idComparator
static java.util.Comparator<SSTableReader>
idReverseComparator
SSTableReader.UniqueIdentifier
instanceId
java.util.concurrent.atomic.AtomicBoolean
isSuspect
protected DecoratedKey
last
static java.util.Comparator<SSTableReader>
lastKeyComparator
long
maxDataAge
maxDataAge is a timestamp in local server time (e.g.static java.util.Comparator<SSTableReader>
maxTimestampAscending
static java.util.Comparator<SSTableReader>
maxTimestampDescending
SSTableReader.OpenReason
openReason
static java.util.Comparator<SSTableReader>
sizeComparator
protected StatsMetadata
sstableMetadata
-
Fields inherited from class org.apache.cassandra.io.sstable.SSTable
chunkCache, components, compression, descriptor, ioOptions, metadata, TOMBSTONE_HISTOGRAM_BIN_SIZE, TOMBSTONE_HISTOGRAM_SPOOL_SIZE, TOMBSTONE_HISTOGRAM_TTL_ROUND_SECONDS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SSTableReader(SSTableReader.Builder<?,?> builder, SSTable.Owner owner)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addTo(Ref.IdentityCollection identities)
long
bytesOnDisk()
abstract SSTableReader
cloneWithNewStart(DecoratedKey newStart)
abstract SSTableReader
cloneWithRestoredStart(DecoratedKey restoredStart)
protected void
closeInternalComponent(java.lang.AutoCloseable closeable)
All the resources which should be released upon closing this sstable reader are registered with inSSTableReader.GlobalTidy
.void
createLinks(java.lang.String snapshotDirectoryPath)
void
createLinks(java.lang.String snapshotDirectoryPath, com.google.common.util.concurrent.RateLimiter rateLimiter)
static void
createLinks(Descriptor descriptor, java.util.Set<Component> components, java.lang.String snapshotDirectoryPath)
static void
createLinks(Descriptor descriptor, java.util.Set<Component> components, java.lang.String snapshotDirectoryPath, com.google.common.util.concurrent.RateLimiter limiter)
boolean
equals(java.lang.Object that)
abstract long
estimatedKeys()
Calculates an estimate of the number of keys in the sstable represented by this reader.abstract long
estimatedKeysForRanges(java.util.Collection<Range<Token>> ranges)
Calculates an estimate of the number of keys for the given ranges in the sstable represented by this reader.abstract DecoratedKey
firstKeyBeyond(PartitionPosition token)
Finds and returns the first key beyond a given token in this SSTable or null if no such key exists.static long
getApproximateKeyCount(java.lang.Iterable<SSTableReader> sstables)
Calculate approximate key count.int
getAvgColumnSetPerRow()
AbstractBounds<Token>
getBounds()
CompressionMetadata
getCompressionMetadata()
Returns the compression metadata for this sstable.long
getCompressionMetadataOffHeapSize()
Returns the amount of memory in bytes used off heap by the compression meta-data.double
getCompressionRatio()
double
getCrcCheckChance()
ChannelProxy
getDataChannel()
long
getDataCreationTime()
double
getDroppableTombstonesBefore(long gcBefore)
EstimatedHistogram
getEstimatedCellPerPartitionCount()
double
getEstimatedDroppableTombstoneRatio(long gcBefore)
EstimatedHistogram
getEstimatedPartitionSize()
FileDataInput
getFileDataInput(long position)
Create aFileDataInput
for the data file of the sstable represented by this reader.java.lang.String
getFilename()
DecoratedKey
getFirst()
abstract java.lang.Iterable<DecoratedKey>
getKeySamples(Range<Token> range)
Returns sample keys for the provided token range.DecoratedKey
getLast()
long
getMaxLocalDeletionTime()
long
getMaxTimestamp()
int
getMaxTTL()
long
getMinLocalDeletionTime()
Minimum local deletion time in the memtablelong
getMinTimestamp()
Minimum timestamp of all stored dataint
getMinTTL()
TimeUUID
getPendingRepair()
long
getPosition(PartitionPosition key, SSTableReader.Operator op)
Retrieves the position while updating the key cache and the stats.long
getPosition(PartitionPosition key, SSTableReader.Operator op, boolean updateStats)
protected long
getPosition(PartitionPosition key, SSTableReader.Operator op, boolean updateStats, SSTableReadsListener listener)
Retrieve a position in data file according to the provided key and operator.long
getPosition(PartitionPosition key, SSTableReader.Operator op, SSTableReadsListener listener)
java.util.List<SSTableReader.PartitionPositionBounds>
getPositionsForRanges(java.util.Collection<Range<Token>> ranges)
Determine the minimal set of sections that can be extracted from this SSTable to cover the given ranges.RestorableMeter
getReadMeter()
long
getRepairedAt()
protected abstract AbstractRowIndexEntry
getRowIndexEntry(PartitionPosition key, SSTableReader.Operator op, boolean updateStats, SSTableReadsListener listener)
Retrieve an index entry for the partition found according to the provided key and operator.abstract ISSTableScanner
getScanner()
Direct I/O SSTableScanner over the entirety of the sstable..abstract ISSTableScanner
getScanner(java.util.Collection<Range<Token>> ranges)
Direct I/O SSTableScanner over a defined collection of ranges of tokens.abstract ISSTableScanner
getScanner(java.util.Iterator<AbstractBounds<PartitionPosition>> rangeIterator)
Direct I/O SSTableScanner over an iterator of bounds.ISSTableScanner
getScanner(Range<Token> range)
Direct I/O SSTableScanner over a defined range of tokens.int
getSSTableLevel()
StatsMetadata
getSSTableMetadata()
static long
getTotalBytes(java.lang.Iterable<SSTableReader> sstables)
long
getTotalColumnsSet()
long
getTotalRows()
static long
getTotalUncompressedBytes(java.lang.Iterable<SSTableReader> sstables)
abstract IVerifier
getVerifier(ColumnFamilyStore cfs, OutputHandler outputHandler, boolean isOffline, IVerifier.Options options)
Returns a new verifier for this sstable.int
hashCode()
void
incrementReadCount()
Increment the total read count and read rate for this SSTable.boolean
intersects(java.util.Collection<Range<Token>> ranges)
abstract boolean
isEstimationInformative()
Returns whether methods likeestimatedKeys()
orestimatedKeysForRanges(Collection)
can return sensible estimations.boolean
isMarkedCompacted()
boolean
isMarkedSuspect()
boolean
isPendingRepair()
boolean
isRepaired()
boolean
isReplaced()
boolean
isTransient()
abstract DecoratedKey
keyAtPositionFromSecondaryIndex(long keyPositionFromSecondaryIndex)
Reads the key stored at the position saved in SASI.KeyIterator
keyIterator()
Returns aKeyIterator
over all keys in the sstable.abstract KeyReader
keyReader()
Returns aKeyReader
over all keys in the sstable.long
logicalBytesOnDisk()
void
markObsolete(java.lang.Runnable tidier)
Mark the sstable as obsolete, i.e., compacted into newer sstables.void
markSuspect()
DataIntegrityMetadata.ChecksumValidator
maybeGetChecksumValidator()
DataIntegrityMetadata.FileDigestValidator
maybeGetDigestValidator()
void
maybePersistSSTableReadMeter()
abstract boolean
mayContainAssumingKeyIsInRange(DecoratedKey key)
The method verifies whether the sstable may contain the provided key.boolean
mayHaveTombstones()
Whether the sstable may contain tombstones or if it is guaranteed to not contain any.static SSTableReader
moveAndOpenSSTable(ColumnFamilyStore cfs, Descriptor oldDescriptor, Descriptor newDescriptor, java.util.Set<Component> components, boolean copyData)
Moves the sstable in oldDescriptor to a new place (with generation etc) in newDescriptor.void
mutateLevelAndReload(int newLevel)
Mutate sstable level with a lock to avoid racing with entire-sstable-streaming and then reload sstable metadatavoid
mutateRepairedAndReload(long newRepairedAt, TimeUUID newPendingRepair, boolean isTransient)
Mutate sstable repair metadata with a lock to avoid racing with entire-sstable-streaming and then reload sstable metadataboolean
newSince(long timestampMillis)
Tests if the sstable contains data newer than the given age param (in localhost currentMillis time).protected void
notifySelected(SSTableReadsListener.SelectionReason reason, SSTableReadsListener localListener, SSTableReader.Operator op, boolean updateStats, AbstractRowIndexEntry entry)
A method to be called bygetPosition(PartitionPosition, Operator, boolean, SSTableReadsListener)
andgetRowIndexEntry(PartitionPosition, Operator, boolean, SSTableReadsListener)
methods when a searched key is found.protected void
notifySkipped(SSTableReadsListener.SkippingReason reason, SSTableReadsListener localListener, SSTableReader.Operator op, boolean updateStats)
A method to be called bygetPosition(PartitionPosition, Operator, boolean, SSTableReadsListener)
andgetRowIndexEntry(PartitionPosition, Operator, boolean, SSTableReadsListener)
methods when a searched key is not found.long
onDiskLength()
The length in bytes of the on disk size for this SSTable.static SSTableReader
open(SSTable.Owner owner, Descriptor descriptor)
static SSTableReader
open(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata)
static SSTableReader
open(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata, boolean validate, boolean isOffline)
Open an SSTable for readingstatic SSTableReader
open(SSTable.Owner owner, Descriptor desc, TableMetadataRef metadata)
static java.util.Collection<SSTableReader>
openAll(SSTable.Owner owner, java.util.Set<java.util.Map.Entry<Descriptor,java.util.Set<Component>>> entries, TableMetadataRef metadata)
RandomAccessReader
openDataReader()
RandomAccessReader
openDataReader(com.google.common.util.concurrent.RateLimiter limiter)
static SSTableReader
openForBatch(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata)
Open SSTable reader to be used in batch mode(such as sstableloader).static SSTableReader
openNoValidation(Descriptor descriptor, java.util.Set<Component> components, ColumnFamilyStore cfs)
static SSTableReader
openNoValidation(SSTable.Owner owner, Descriptor descriptor, TableMetadataRef metadata)
void
overrideReadMeter(RestorableMeter readMeter)
Ref<SSTableReader>
ref()
abstract void
releaseInMemoryComponents()
This method is expected to close the components which occupy memory but are not needed when we just want to stream the components (for example, when SSTable is opened with SSTableLoader).void
reloadSSTableMetadata()
Reloads the sstable metadata from disk.static void
resetTidying()
void
runOnClose(java.lang.Runnable runOnClose)
The runnable passed to this method must not be an anonymous or non-static inner class.<R,E extends java.lang.Exception>
RrunWithLock(CheckedFunction<Descriptor,R,E> task)
Execute provided task with sstable lock to avoid racing with index summary redistribution, SEE CASSANDRA-15861.Ref<SSTableReader>
selfRef()
void
setCrcCheckChance(double crcCheckChance)
Set the value of CRC check chance.void
setReplaced()
void
setup(boolean trackHotness)
protected java.util.List<java.lang.AutoCloseable>
setupInstance(boolean trackHotness)
void
setupOnline()
static void
shutdownBlocking(long timeout, java.util.concurrent.TimeUnit unit)
UnfilteredRowIterator
simpleIterator(FileDataInput file, DecoratedKey key, long dataPosition, boolean tombstoneOnly)
EncodingStats
stats()
double
tokenSpaceCoverage()
Ref<SSTableReader>
tryRef()
void
trySkipFileCacheBefore(DecoratedKey key)
protected <B extends SSTableReader.Builder<?,B>>
BunbuildTo(B builder, boolean sharedCopy)
The method sets fields specific to thisSSTableReader
and the parentSSTable
on the providedSSTableReader.Builder
.long
uncompressedLength()
Returns the length in bytes of the (uncompressed) data for this SSTable.void
unmarkSuspect()
void
validate()
Perform any validation needed for the reader upon creation before returning it from theSSTableReader.Builder
.-
Methods inherited from class org.apache.cassandra.io.sstable.SSTable
addComponents, copy, decorateKey, getAllFilePaths, getColumnFamilyName, getComponents, getKeyspaceName, getPartitioner, getStreamingComponents, hardlink, metadata, owner, registerComponents, rename, toString, tryComponentFromFilename, tryComponentFromFilename, tryDescriptorFromFile, unbuildTo, unregisterComponents, validateRepairedMetadata
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.db.rows.UnfilteredSource
partitionIterator, rowIterator, rowIterator
-
-
-
-
Field Detail
-
maxTimestampAscending
public static final java.util.Comparator<SSTableReader> maxTimestampAscending
-
maxTimestampDescending
public static final java.util.Comparator<SSTableReader> maxTimestampDescending
-
instanceId
public final SSTableReader.UniqueIdentifier instanceId
-
firstKeyComparator
public static final java.util.Comparator<SSTableReader> firstKeyComparator
-
firstKeyOrdering
public static final com.google.common.collect.Ordering<SSTableReader> firstKeyOrdering
-
lastKeyComparator
public static final java.util.Comparator<SSTableReader> lastKeyComparator
-
idComparator
public static final java.util.Comparator<SSTableReader> idComparator
-
idReverseComparator
public static final java.util.Comparator<SSTableReader> idReverseComparator
-
sizeComparator
public static final java.util.Comparator<SSTableReader> sizeComparator
-
maxDataAge
public final long maxDataAge
maxDataAge is a timestamp in local server time (e.g. Global.currentTimeMilli) which represents an upper bound to the newest piece of data stored in the sstable. In other words, this sstable does not contain items created later than maxDataAge.The field is not serialized to disk, so relying on it for more than what truncate does is not advised.
When a new sstable is flushed, maxDataAge is set to the time of creation. When a sstable is created from compaction, maxDataAge is set to max of all merged sstables.
The age is in milliseconds since epoc and is local to this host.
-
openReason
public final SSTableReader.OpenReason openReason
-
dfile
protected final FileHandle dfile
-
isSuspect
public final java.util.concurrent.atomic.AtomicBoolean isSuspect
-
sstableMetadata
protected volatile StatsMetadata sstableMetadata
-
header
public final SerializationHeader header
-
first
protected final DecoratedKey first
-
last
protected final DecoratedKey last
-
bounds
public final AbstractBounds<Token> bounds
-
-
Constructor Detail
-
SSTableReader
protected SSTableReader(SSTableReader.Builder<?,?> builder, SSTable.Owner owner)
-
-
Method Detail
-
getApproximateKeyCount
public static long getApproximateKeyCount(java.lang.Iterable<SSTableReader> sstables)
Calculate approximate key count. If cardinality estimator is available on all given sstables, then this method use them to estimate key count. If not, then this uses index summaries.- Parameters:
sstables
- SSTables to calculate key count- Returns:
- estimated key count
-
open
public static SSTableReader open(SSTable.Owner owner, Descriptor descriptor)
-
open
public static SSTableReader open(SSTable.Owner owner, Descriptor desc, TableMetadataRef metadata)
-
open
public static SSTableReader open(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata)
-
openNoValidation
public static SSTableReader openNoValidation(Descriptor descriptor, java.util.Set<Component> components, ColumnFamilyStore cfs)
-
openNoValidation
public static SSTableReader openNoValidation(SSTable.Owner owner, Descriptor descriptor, TableMetadataRef metadata)
-
openForBatch
public static SSTableReader openForBatch(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata)
Open SSTable reader to be used in batch mode(such as sstableloader).
-
open
public static SSTableReader open(SSTable.Owner owner, Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata, boolean validate, boolean isOffline)
Open an SSTable for reading- Parameters:
owner
- owning entitydescriptor
- SSTable to opencomponents
- Components included with this SSTablemetadata
- for this SSTables CFvalidate
- Check SSTable for corruption (limited)isOffline
- Whether we are opening this SSTable "offline", for example from an external tool or not for inclusion in queries (validations) This stops regenerating BF + Summaries and also disables tracking of hotness for the SSTable.- Returns:
SSTableReader
-
openAll
public static java.util.Collection<SSTableReader> openAll(SSTable.Owner owner, java.util.Set<java.util.Map.Entry<Descriptor,java.util.Set<Component>>> entries, TableMetadataRef metadata)
-
getFirst
public DecoratedKey getFirst()
-
getLast
public DecoratedKey getLast()
-
getBounds
public AbstractBounds<Token> getBounds()
-
maybeGetChecksumValidator
public DataIntegrityMetadata.ChecksumValidator maybeGetChecksumValidator() throws java.io.IOException
- Throws:
java.io.IOException
-
maybeGetDigestValidator
public DataIntegrityMetadata.FileDigestValidator maybeGetDigestValidator() throws java.io.IOException
- Throws:
java.io.IOException
-
getTotalBytes
public static long getTotalBytes(java.lang.Iterable<SSTableReader> sstables)
-
getTotalUncompressedBytes
public static long getTotalUncompressedBytes(java.lang.Iterable<SSTableReader> sstables)
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getFilename
public java.lang.String getFilename()
- Overrides:
getFilename
in classSSTable
-
setupOnline
public void setupOnline()
-
runWithLock
public <R,E extends java.lang.Exception> R runWithLock(CheckedFunction<Descriptor,R,E> task) throws E extends java.lang.Exception
Execute provided task with sstable lock to avoid racing with index summary redistribution, SEE CASSANDRA-15861.- Parameters:
task
- to be guarded by sstable lock- Throws:
E extends java.lang.Exception
-
setReplaced
public void setReplaced()
-
isReplaced
public boolean isReplaced()
-
runOnClose
public void runOnClose(java.lang.Runnable runOnClose)
The runnable passed to this method must not be an anonymous or non-static inner class. It can be a lambda or a method reference provided that it does not retain a reference chain to this reader.
-
unbuildTo
protected final <B extends SSTableReader.Builder<?,B>> B unbuildTo(B builder, boolean sharedCopy)
The method sets fields specific to thisSSTableReader
and the parentSSTable
on the providedSSTableReader.Builder
. The method is intended to be called from the overloadedunbuildTo
method in subclasses.- Parameters:
builder
- the builder on which the fields should be setsharedCopy
- whether theSharedCloseable
resources should be passed as shared copies or directly; note that the method will overwrite the fields representingSharedCloseable
only if they are not set in the builder yet (the relevant fields in the builder arenull
).- Returns:
- the same instance of builder as provided
-
cloneWithRestoredStart
public abstract SSTableReader cloneWithRestoredStart(DecoratedKey restoredStart)
-
cloneWithNewStart
public abstract SSTableReader cloneWithNewStart(DecoratedKey newStart)
-
getReadMeter
public RestorableMeter getReadMeter()
-
closeInternalComponent
protected void closeInternalComponent(java.lang.AutoCloseable closeable)
All the resources which should be released upon closing this sstable reader are registered with inSSTableReader.GlobalTidy
. This method lets close a provided resource explicitly any time and unregister it fromSSTableReader.GlobalTidy
so that it is not tried to be released twice.- Parameters:
closeable
- a resource to be closed
-
releaseInMemoryComponents
public abstract void releaseInMemoryComponents()
This method is expected to close the components which occupy memory but are not needed when we just want to stream the components (for example, when SSTable is opened with SSTableLoader). The method should callcloseInternalComponent(AutoCloseable)
for each such component. Leaving the implementation empty is valid given there are not such resources to release.
-
validate
public void validate()
Perform any validation needed for the reader upon creation before returning it from theSSTableReader.Builder
.
-
getCompressionMetadata
public CompressionMetadata getCompressionMetadata()
Returns the compression metadata for this sstable. Note that the compression metdata is a resource and should not be closed by the caller. TODO do not return a closeable resource or return a shared copy- Throws:
java.lang.IllegalStateException
- if the sstable is not compressed
-
getCompressionMetadataOffHeapSize
public long getCompressionMetadataOffHeapSize()
Returns the amount of memory in bytes used off heap by the compression meta-data.- Returns:
- the amount of memory in bytes used off heap by the compression meta-data
-
estimatedKeys
public abstract long estimatedKeys()
Calculates an estimate of the number of keys in the sstable represented by this reader.
-
estimatedKeysForRanges
public abstract long estimatedKeysForRanges(java.util.Collection<Range<Token>> ranges)
Calculates an estimate of the number of keys for the given ranges in the sstable represented by this reader.
-
isEstimationInformative
public abstract boolean isEstimationInformative()
Returns whether methods likeestimatedKeys()
orestimatedKeysForRanges(Collection)
can return sensible estimations.
-
getKeySamples
public abstract java.lang.Iterable<DecoratedKey> getKeySamples(Range<Token> range)
Returns sample keys for the provided token range.
-
getPositionsForRanges
public java.util.List<SSTableReader.PartitionPositionBounds> getPositionsForRanges(java.util.Collection<Range<Token>> ranges)
Determine the minimal set of sections that can be extracted from this SSTable to cover the given ranges.- Returns:
- A sorted list of (offset,end) pairs that cover the given ranges in the datafile for this SSTable.
-
getPosition
public final long getPosition(PartitionPosition key, SSTableReader.Operator op)
Retrieves the position while updating the key cache and the stats.- Parameters:
key
- The key to apply as the rhs to the given Operator. A 'fake' key is allowed to allow key selection by token bounds but only if op != * EQop
- The Operator defining matching keys: the nearest key to the target matching the operator wins.
-
getPosition
public final long getPosition(PartitionPosition key, SSTableReader.Operator op, SSTableReadsListener listener)
-
getPosition
public final long getPosition(PartitionPosition key, SSTableReader.Operator op, boolean updateStats)
-
getPosition
protected long getPosition(PartitionPosition key, SSTableReader.Operator op, boolean updateStats, SSTableReadsListener listener)
Retrieve a position in data file according to the provided key and operator.- Parameters:
key
- The key to apply as the rhs to the given Operator. A 'fake' key is allowed to allow key selection by token bounds but only if op != * EQop
- The Operator defining matching keys: the nearest key to the target matching the operator wins.updateStats
- true if updating stats and cachelistener
- a listener used to handle internal events- Returns:
- The index entry corresponding to the key, or null if the key is not present
-
getRowIndexEntry
protected abstract AbstractRowIndexEntry getRowIndexEntry(PartitionPosition key, SSTableReader.Operator op, boolean updateStats, SSTableReadsListener listener)
Retrieve an index entry for the partition found according to the provided key and operator.- Parameters:
key
- The key to apply as the rhs to the given Operator. A 'fake' key is allowed to allow key selection by token bounds but only if op != * EQop
- The Operator defining matching keys: the nearest key to the target matching the operator wins.updateStats
- true if updating stats and cachelistener
- a listener used to handle internal events- Returns:
- The index entry corresponding to the key, or null if the key is not present
-
simpleIterator
public UnfilteredRowIterator simpleIterator(FileDataInput file, DecoratedKey key, long dataPosition, boolean tombstoneOnly)
-
keyReader
public abstract KeyReader keyReader() throws java.io.IOException
Returns aKeyReader
over all keys in the sstable.- Throws:
java.io.IOException
-
keyIterator
public KeyIterator keyIterator() throws java.io.IOException
Returns aKeyIterator
over all keys in the sstable.- Throws:
java.io.IOException
-
firstKeyBeyond
public abstract DecoratedKey firstKeyBeyond(PartitionPosition token)
Finds and returns the first key beyond a given token in this SSTable or null if no such key exists.
-
uncompressedLength
public long uncompressedLength()
Returns the length in bytes of the (uncompressed) data for this SSTable. For compressed files, this is not the same thing as the on disk size (seeonDiskLength()
).
-
tokenSpaceCoverage
public double tokenSpaceCoverage()
- Returns:
- the fraction of the token space for which this sstable has content. In the simplest case this is just the
size of the interval returned by
getBounds()
, but the sstable may contain "holes" when the locally-owned range is not contiguous (e.g. with vnodes). As this is affected by the local ranges which can change, the token space fraction is calculated at the time of writing the sstable and stored with its metadata. For older sstables that do not contain this metadata field, this method returns NaN.
-
onDiskLength
public long onDiskLength()
The length in bytes of the on disk size for this SSTable. For compressed files, this is not the same thing as the data length (seeuncompressedLength()
).
-
getCrcCheckChance
public double getCrcCheckChance()
-
setCrcCheckChance
public void setCrcCheckChance(double crcCheckChance)
Set the value of CRC check chance. The argument supplied is obtained from the property of the owning CFS. Called when either the SSTR is initialized, or the CFS's property is updated via JMX
-
markObsolete
public void markObsolete(java.lang.Runnable tidier)
Mark the sstable as obsolete, i.e., compacted into newer sstables.When calling this function, the caller must ensure that the SSTableReader is not referenced anywhere except for threads holding a reference.
Calling it multiple times is usually buggy.
-
isMarkedCompacted
public boolean isMarkedCompacted()
-
markSuspect
public void markSuspect()
-
unmarkSuspect
public void unmarkSuspect()
-
isMarkedSuspect
public boolean isMarkedSuspect()
-
getScanner
public ISSTableScanner getScanner(Range<Token> range)
Direct I/O SSTableScanner over a defined range of tokens.- Parameters:
range
- the range of keys to cover- Returns:
- A Scanner for seeking over the rows of the SSTable.
-
getScanner
public abstract ISSTableScanner getScanner()
Direct I/O SSTableScanner over the entirety of the sstable..- Returns:
- A Scanner over the full content of the SSTable.
-
getScanner
public abstract ISSTableScanner getScanner(java.util.Collection<Range<Token>> ranges)
Direct I/O SSTableScanner over a defined collection of ranges of tokens.- Parameters:
ranges
- the range of keys to cover- Returns:
- A Scanner for seeking over the rows of the SSTable.
-
getScanner
public abstract ISSTableScanner getScanner(java.util.Iterator<AbstractBounds<PartitionPosition>> rangeIterator)
Direct I/O SSTableScanner over an iterator of bounds.- Parameters:
rangeIterator
- the keys to cover- Returns:
- A Scanner for seeking over the rows of the SSTable.
-
getFileDataInput
public FileDataInput getFileDataInput(long position)
Create aFileDataInput
for the data file of the sstable represented by this reader. This method returns a newly opened resource which must be closed by the caller.- Parameters:
position
- the data input will be opened and seek to this position
-
newSince
public boolean newSince(long timestampMillis)
Tests if the sstable contains data newer than the given age param (in localhost currentMillis time). This works in conjunction with maxDataAge which is an upper bound on the data in the sstable represented by this reader.- Returns:
true
iff this sstable contains data that's newer than the given timestamp
-
createLinks
public void createLinks(java.lang.String snapshotDirectoryPath)
-
createLinks
public void createLinks(java.lang.String snapshotDirectoryPath, com.google.common.util.concurrent.RateLimiter rateLimiter)
-
createLinks
public static void createLinks(Descriptor descriptor, java.util.Set<Component> components, java.lang.String snapshotDirectoryPath)
-
createLinks
public static void createLinks(Descriptor descriptor, java.util.Set<Component> components, java.lang.String snapshotDirectoryPath, com.google.common.util.concurrent.RateLimiter limiter)
-
isRepaired
public boolean isRepaired()
-
keyAtPositionFromSecondaryIndex
public abstract DecoratedKey keyAtPositionFromSecondaryIndex(long keyPositionFromSecondaryIndex) throws java.io.IOException
Reads the key stored at the position saved in SASI.When SASI is created, it uses key locations retrieved from
KeyReader.keyPositionForSecondaryIndex()
. This method is to read the key stored at such position. It is up to the concrete SSTable format implementation what that position means and which file it refers. The only requirement is that it is consistent with whatKeyReader.keyPositionForSecondaryIndex()
returns.- Returns:
- key if found,
null
otherwise - Throws:
java.io.IOException
-
isPendingRepair
public boolean isPendingRepair()
-
getPendingRepair
public TimeUUID getPendingRepair()
-
getRepairedAt
public long getRepairedAt()
-
isTransient
public boolean isTransient()
-
getEstimatedPartitionSize
public EstimatedHistogram getEstimatedPartitionSize()
-
getEstimatedCellPerPartitionCount
public EstimatedHistogram getEstimatedCellPerPartitionCount()
-
getEstimatedDroppableTombstoneRatio
public double getEstimatedDroppableTombstoneRatio(long gcBefore)
-
getDroppableTombstonesBefore
public double getDroppableTombstonesBefore(long gcBefore)
-
getCompressionRatio
public double getCompressionRatio()
-
getMinTimestamp
public long getMinTimestamp()
Description copied from interface:UnfilteredSource
Minimum timestamp of all stored data- Specified by:
getMinTimestamp
in interfaceUnfilteredSource
-
getMaxTimestamp
public long getMaxTimestamp()
-
getMinLocalDeletionTime
public long getMinLocalDeletionTime()
Description copied from interface:UnfilteredSource
Minimum local deletion time in the memtable- Specified by:
getMinLocalDeletionTime
in interfaceUnfilteredSource
-
getMaxLocalDeletionTime
public long getMaxLocalDeletionTime()
-
mayHaveTombstones
public boolean mayHaveTombstones()
Whether the sstable may contain tombstones or if it is guaranteed to not contain any.Note that having that method return
false
guarantees the sstable has no tombstones whatsoever (so no cell tombstone, no range tombstone maker and no expiring columns), but having it returntrue
doesn't guarantee it contains any as it may simply have non-expired cells.
-
getMinTTL
public int getMinTTL()
-
getMaxTTL
public int getMaxTTL()
-
getTotalColumnsSet
public long getTotalColumnsSet()
-
getTotalRows
public long getTotalRows()
-
getAvgColumnSetPerRow
public int getAvgColumnSetPerRow()
-
getSSTableLevel
public int getSSTableLevel()
-
mutateLevelAndReload
public void mutateLevelAndReload(int newLevel) throws java.io.IOException
Mutate sstable level with a lock to avoid racing with entire-sstable-streaming and then reload sstable metadata- Throws:
java.io.IOException
-
mutateRepairedAndReload
public void mutateRepairedAndReload(long newRepairedAt, TimeUUID newPendingRepair, boolean isTransient) throws java.io.IOException
Mutate sstable repair metadata with a lock to avoid racing with entire-sstable-streaming and then reload sstable metadata- Throws:
java.io.IOException
-
reloadSSTableMetadata
public void reloadSSTableMetadata() throws java.io.IOException
Reloads the sstable metadata from disk.Called after level is changed on sstable, for example if the sstable is dropped to L0
Might be possible to remove in future versions
- Throws:
java.io.IOException
-
getSSTableMetadata
public StatsMetadata getSSTableMetadata()
-
openDataReader
public RandomAccessReader openDataReader(com.google.common.util.concurrent.RateLimiter limiter)
-
openDataReader
public RandomAccessReader openDataReader()
-
trySkipFileCacheBefore
public void trySkipFileCacheBefore(DecoratedKey key)
-
getDataChannel
public ChannelProxy getDataChannel()
-
getDataCreationTime
public long getDataCreationTime()
- Returns:
- last modified time for data component. 0 if given component does not exist or IO error occurs.
-
incrementReadCount
public void incrementReadCount()
Increment the total read count and read rate for this SSTable. This should not be incremented for non-query reads, like compaction.
-
stats
public EncodingStats stats()
-
tryRef
public Ref<SSTableReader> tryRef()
- Specified by:
tryRef
in interfaceRefCounted<SSTableReader>
- Returns:
- the a new Ref() to the managed object, incrementing its refcount, or null if it is already released
-
selfRef
public Ref<SSTableReader> selfRef()
- Specified by:
selfRef
in interfaceSelfRefCounted<SSTableReader>
-
ref
public Ref<SSTableReader> ref()
- Specified by:
ref
in interfaceRefCounted<SSTableReader>
-
setupInstance
protected java.util.List<java.lang.AutoCloseable> setupInstance(boolean trackHotness)
-
setup
public void setup(boolean trackHotness)
-
overrideReadMeter
public void overrideReadMeter(RestorableMeter readMeter)
-
addTo
public void addTo(Ref.IdentityCollection identities)
-
mayContainAssumingKeyIsInRange
public abstract boolean mayContainAssumingKeyIsInRange(DecoratedKey key)
The method verifies whether the sstable may contain the provided key. The method does approximation using Bloom filter if it is present and if it is not, performs accurate check in the index.
-
resetTidying
public static void resetTidying()
-
moveAndOpenSSTable
public static SSTableReader moveAndOpenSSTable(ColumnFamilyStore cfs, Descriptor oldDescriptor, Descriptor newDescriptor, java.util.Set<Component> components, boolean copyData)
Moves the sstable in oldDescriptor to a new place (with generation etc) in newDescriptor.All components given will be moved/renamed
-
shutdownBlocking
public static void shutdownBlocking(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
- Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException
-
bytesOnDisk
public long bytesOnDisk()
- Returns:
- the physical size on disk of all components for this SSTable in bytes
-
logicalBytesOnDisk
public long logicalBytesOnDisk()
- Returns:
- the total logical/uncompressed size in bytes of all components for this SSTable
-
maybePersistSSTableReadMeter
public void maybePersistSSTableReadMeter()
-
getVerifier
public abstract IVerifier getVerifier(ColumnFamilyStore cfs, OutputHandler outputHandler, boolean isOffline, IVerifier.Options options)
Returns a new verifier for this sstable. Note that the reader must match the provided cfs.
-
notifySelected
protected void notifySelected(SSTableReadsListener.SelectionReason reason, SSTableReadsListener localListener, SSTableReader.Operator op, boolean updateStats, AbstractRowIndexEntry entry)
A method to be called bygetPosition(PartitionPosition, Operator, boolean, SSTableReadsListener)
andgetRowIndexEntry(PartitionPosition, Operator, boolean, SSTableReadsListener)
methods when a searched key is found. It adds a trace message and notify the provided listener.
-
notifySkipped
protected void notifySkipped(SSTableReadsListener.SkippingReason reason, SSTableReadsListener localListener, SSTableReader.Operator op, boolean updateStats)
A method to be called bygetPosition(PartitionPosition, Operator, boolean, SSTableReadsListener)
andgetRowIndexEntry(PartitionPosition, Operator, boolean, SSTableReadsListener)
methods when a searched key is not found. It adds a trace message and notify the provided listener.
-
-