org.apache.cassandra.io.sstable
Class SSTableReader

java.lang.Object
  extended by org.apache.cassandra.io.sstable.SSTable
      extended by org.apache.cassandra.io.sstable.SSTableReader

public class SSTableReader
extends SSTable

SSTableReaders are open()ed by Table.onStart; after that they are created by SSTableWriter.renameAndOpen. Do not re-call open() on existing SSTable files; use the references kept by ColumnFamilyStore post-start instead.


Nested Class Summary
static class SSTableReader.Operator
          TODO: Move someplace reusable
 
Field Summary
 long maxDataAge
          maxDataAge is a timestamp in local server time (e.g.
 
Fields inherited from class org.apache.cassandra.io.sstable.SSTable
COMPONENT_DATA, COMPONENT_DIGEST, COMPONENT_FILTER, COMPONENT_INDEX, COMPONENT_STATS, COMPONENT_SUMMARY, components, compression, descriptor, first, last, maxTimestampComparator, metadata, partitioner, sstableComparator, sstableOrdering, TEMPFILE_MARKER, TOMBSTONE_HISTOGRAM_BIN_SIZE
 
Method Summary
 boolean acquireReference()
           
static boolean acquireReferences(java.lang.Iterable<SSTableReader> sstables)
           
static java.util.Collection<SSTableReader> batchOpen(java.util.Set<java.util.Map.Entry<Descriptor,java.util.Set<Component>>> entries, CFMetaData metadata, IPartitioner partitioner)
           
 void cacheKey(DecoratedKey key, RowIndexEntry info)
           
 void createLinks(java.lang.String snapshotDirectoryPath)
           
 DecoratedKey decodeKey(java.nio.ByteBuffer bytes)
           
static DecoratedKey decodeKey(IPartitioner p, Descriptor d, java.nio.ByteBuffer bytes)
          Conditionally use the deprecated 'IPartitioner.convertFromDiskFormat' method.
 long estimatedKeys()
           
 long estimatedKeysForRanges(java.util.Collection<Range<Token>> ranges)
           
 void forceFilterFailures()
          For testing purposes only.
 java.util.Set<java.lang.Integer> getAncestors()
           
static long getApproximateKeyCount(java.lang.Iterable<SSTableReader> sstables)
           
 IFilter getBloomFilter()
           
 long getBloomFilterFalsePositiveCount()
           
 long getBloomFilterSerializedSize()
           
 long getBloomFilterTruePositiveCount()
           
 RowIndexEntry getCachedPosition(DecoratedKey key, boolean updateStats)
           
 CompressionMetadata getCompressionMetadata()
          Returns the compression metadata for this sstable.
 double getCompressionRatio()
           
 long getCreationTimeFor(Component component)
           
 ICompactionScanner getDirectScanner(Range<Token> range, com.google.common.util.concurrent.RateLimiter limiter)
          Direct I/O SSTableScanner over a defined range of tokens.
 SSTableScanner getDirectScanner(com.google.common.util.concurrent.RateLimiter limiter)
          Direct I/O SSTableScanner
 double getDroppableTombstonesBefore(int gcBefore)
           
 EstimatedHistogram getEstimatedColumnCount()
           
 double getEstimatedDroppableTombstoneRatio(int gcBefore)
           
 EstimatedHistogram getEstimatedRowSize()
           
 FileDataInput getFileDataInput(long position)
           
 long getIndexScanPosition(RowPosition key)
          get the position in the index file to start scanning to find the given key (at most indexInterval keys away)
 InstrumentingCache<KeyCacheKey,RowIndexEntry> getKeyCache()
           
 byte[][] getKeySamples()
           
 java.lang.Iterable<DecoratedKey> getKeySamples(Range<Token> range)
           
 long getMaxTimestamp()
           
 long getMinTimestamp()
           
 RowIndexEntry getPosition(RowPosition key, SSTableReader.Operator op)
          Get position updating key cache and stats.
 RowIndexEntry getPosition(RowPosition key, SSTableReader.Operator op, boolean updateCacheAndStats)
           
 java.util.List<Pair<java.lang.Long,java.lang.Long>> 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.
 long getRecentBloomFilterFalsePositiveCount()
           
 long getRecentBloomFilterTruePositiveCount()
           
 ReplayPosition getReplayPosition()
           
 SSTableScanner getScanner(QueryFilter filter)
           
 boolean isMarkedSuspect()
           
static boolean loadSummary(SSTableReader reader, SegmentedFile.Builder ibuilder, SegmentedFile.Builder dbuilder)
           
static void logOpenException(Descriptor descriptor, java.io.IOException e)
           
 boolean markCompacted()
          Mark the sstable as compacted.
 void markSuspect()
           
 boolean newSince(long age)
          Tests if the sstable contains data newer than the given age param (in localhost currentMilli time).
 long onDiskLength()
           
static SSTableReader open(Descriptor descriptor)
           
static SSTableReader open(Descriptor desc, CFMetaData metadata)
           
static SSTableReader open(Descriptor descriptor, java.util.Set<Component> components, CFMetaData metadata, IPartitioner partitioner)
           
 RandomAccessReader openDataReader(boolean skipIOCache)
           
 RandomAccessReader openDataReader(com.google.common.util.concurrent.RateLimiter limiter)
           
 RandomAccessReader openIndexReader(boolean skipIOCache)
           
static SSTableReader openNoValidation(Descriptor descriptor, java.util.Set<Component> components, CFMetaData metadata)
           
static long readRowSize(java.io.DataInput in, Descriptor d)
           
 void releaseReference()
           
static void releaseReferences(java.lang.Iterable<SSTableReader> sstables)
           
static void saveSummary(SSTableReader reader, SegmentedFile.Builder ibuilder, SegmentedFile.Builder dbuilder)
           
 void setTrackedBy(DataTracker tracker)
           
 long uncompressedLength()
           
 
Methods inherited from class org.apache.cassandra.io.sstable.SSTable
addComponents, appendTOC, bytesOnDisk, delete, getColumnFamilyName, getFilename, getIndexFilename, getMinimalKey, getTableName, getTotalBytes, readTOC, toString, tryComponentFromFilename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxDataAge

public final long maxDataAge
maxDataAge is a timestamp in local server time (e.g. System.currentTimeMilli) which represents an uppper 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 tables. The age is in milliseconds since epoc and is local to this host.

Method Detail

getApproximateKeyCount

public static long getApproximateKeyCount(java.lang.Iterable<SSTableReader> sstables)

open

public static SSTableReader open(Descriptor descriptor)
                          throws java.io.IOException
Throws:
java.io.IOException

open

public static SSTableReader open(Descriptor desc,
                                 CFMetaData metadata)
                          throws java.io.IOException
Throws:
java.io.IOException

openNoValidation

public static SSTableReader openNoValidation(Descriptor descriptor,
                                             java.util.Set<Component> components,
                                             CFMetaData metadata)
                                      throws java.io.IOException
Throws:
java.io.IOException

open

public static SSTableReader open(Descriptor descriptor,
                                 java.util.Set<Component> components,
                                 CFMetaData metadata,
                                 IPartitioner partitioner)
                          throws java.io.IOException
Throws:
java.io.IOException

logOpenException

public static void logOpenException(Descriptor descriptor,
                                    java.io.IOException e)

batchOpen

public static java.util.Collection<SSTableReader> batchOpen(java.util.Set<java.util.Map.Entry<Descriptor,java.util.Set<Component>>> entries,
                                                            CFMetaData metadata,
                                                            IPartitioner partitioner)

setTrackedBy

public void setTrackedBy(DataTracker tracker)

loadSummary

public static boolean loadSummary(SSTableReader reader,
                                  SegmentedFile.Builder ibuilder,
                                  SegmentedFile.Builder dbuilder)

saveSummary

public static void saveSummary(SSTableReader reader,
                               SegmentedFile.Builder ibuilder,
                               SegmentedFile.Builder dbuilder)

getIndexScanPosition

public long getIndexScanPosition(RowPosition key)
get the position in the index file to start scanning to find the given key (at most indexInterval keys away)


getCompressionMetadata

public CompressionMetadata getCompressionMetadata()
Returns the compression metadata for this sstable.

Throws:
java.lang.IllegalStateException - if the sstable is not compressed

forceFilterFailures

public void forceFilterFailures()
For testing purposes only.


getBloomFilter

public IFilter getBloomFilter()

getBloomFilterSerializedSize

public long getBloomFilterSerializedSize()

estimatedKeys

public long estimatedKeys()
Returns:
An estimate of the number of keys in this SSTable.

estimatedKeysForRanges

public long estimatedKeysForRanges(java.util.Collection<Range<Token>> ranges)
Parameters:
ranges -
Returns:
An estimate of the number of keys for given ranges in this SSTable.

getKeySamples

public byte[][] getKeySamples()
Returns:
Approximately 1/INDEX_INTERVALth of the keys in this SSTable.

getKeySamples

public java.lang.Iterable<DecoratedKey> getKeySamples(Range<Token> range)

getPositionsForRanges

public java.util.List<Pair<java.lang.Long,java.lang.Long>> 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.

cacheKey

public void cacheKey(DecoratedKey key,
                     RowIndexEntry info)

getCachedPosition

public RowIndexEntry getCachedPosition(DecoratedKey key,
                                       boolean updateStats)

getPosition

public RowIndexEntry getPosition(RowPosition key,
                                 SSTableReader.Operator op)
Get position updating key cache and stats.

See Also:
getPosition(org.apache.cassandra.db.RowPosition, org.apache.cassandra.io.sstable.SSTableReader.Operator, boolean)

getPosition

public RowIndexEntry getPosition(RowPosition key,
                                 SSTableReader.Operator op,
                                 boolean updateCacheAndStats)
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 != * EQ
op - The Operator defining matching keys: the nearest key to the target matching the operator wins.
updateCacheAndStats - true if updating stats and cache
Returns:
The index entry corresponding to the key, or null if the key is not present

uncompressedLength

public long uncompressedLength()
Returns:
The length in bytes of the data for this SSTable. For compressed files, this is not the same thing as the on disk size (see onDiskLength())

onDiskLength

public long onDiskLength()
Returns:
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 (see length())

acquireReference

public boolean acquireReference()

releaseReference

public void releaseReference()

markCompacted

public boolean markCompacted()
Mark the sstable as compacted. When calling this function, the caller must ensure that the SSTableReader is not referenced anywhere except for threads holding a reference.

Returns:
true if the this is the first time the file was marked compacted. With rare exceptions (see DataTracker.unmarkCompacted) calling this multiple times would be buggy.

markSuspect

public void markSuspect()

isMarkedSuspect

public boolean isMarkedSuspect()

getScanner

public SSTableScanner getScanner(QueryFilter filter)
Parameters:
filter - filter to use when reading the columns
Returns:
A Scanner for seeking over the rows of the SSTable.

getDirectScanner

public SSTableScanner getDirectScanner(com.google.common.util.concurrent.RateLimiter limiter)
Direct I/O SSTableScanner

Returns:
A Scanner for seeking over the rows of the SSTable.

getDirectScanner

public ICompactionScanner getDirectScanner(Range<Token> range,
                                           com.google.common.util.concurrent.RateLimiter limiter)
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.

getFileDataInput

public FileDataInput getFileDataInput(long position)

newSince

public boolean newSince(long age)
Tests if the sstable contains data newer than the given age param (in localhost currentMilli time). This works in conjunction with maxDataAge which is an upper bound on the create of data in this sstable.

Parameters:
age - The age to compare the maxDataAre of this sstable. Measured in millisec since epoc on this host
Returns:
True iff this sstable contains data that's newer than the given age parameter.

readRowSize

public static long readRowSize(java.io.DataInput in,
                               Descriptor d)
                        throws java.io.IOException
Throws:
java.io.IOException

createLinks

public void createLinks(java.lang.String snapshotDirectoryPath)

decodeKey

public static DecoratedKey decodeKey(IPartitioner p,
                                     Descriptor d,
                                     java.nio.ByteBuffer bytes)
Conditionally use the deprecated 'IPartitioner.convertFromDiskFormat' method.


decodeKey

public DecoratedKey decodeKey(java.nio.ByteBuffer bytes)

getBloomFilterFalsePositiveCount

public long getBloomFilterFalsePositiveCount()

getRecentBloomFilterFalsePositiveCount

public long getRecentBloomFilterFalsePositiveCount()

getBloomFilterTruePositiveCount

public long getBloomFilterTruePositiveCount()

getRecentBloomFilterTruePositiveCount

public long getRecentBloomFilterTruePositiveCount()

getKeyCache

public InstrumentingCache<KeyCacheKey,RowIndexEntry> getKeyCache()

getEstimatedRowSize

public EstimatedHistogram getEstimatedRowSize()

getEstimatedColumnCount

public EstimatedHistogram getEstimatedColumnCount()

getEstimatedDroppableTombstoneRatio

public double getEstimatedDroppableTombstoneRatio(int gcBefore)

getDroppableTombstonesBefore

public double getDroppableTombstonesBefore(int gcBefore)

getCompressionRatio

public double getCompressionRatio()

getReplayPosition

public ReplayPosition getReplayPosition()

getMinTimestamp

public long getMinTimestamp()

getMaxTimestamp

public long getMaxTimestamp()

getAncestors

public java.util.Set<java.lang.Integer> getAncestors()

openDataReader

public RandomAccessReader openDataReader(com.google.common.util.concurrent.RateLimiter limiter)

openDataReader

public RandomAccessReader openDataReader(boolean skipIOCache)

openIndexReader

public RandomAccessReader openIndexReader(boolean skipIOCache)

getCreationTimeFor

public long getCreationTimeFor(Component component)
Parameters:
component - component to get timestamp.
Returns:
last modified time for given component. 0 if given component does not exist or IO error occurs.

acquireReferences

public static boolean acquireReferences(java.lang.Iterable<SSTableReader> sstables)
Parameters:
sstables -
Returns:
true if all desired references were acquired. Otherwise, it will unreference any partial acquisition, and return false.

releaseReferences

public static void releaseReferences(java.lang.Iterable<SSTableReader> sstables)


Copyright © 2013 The Apache Software Foundation