Package org.apache.cassandra.io.sstable
Class SSTable
- java.lang.Object
-
- org.apache.cassandra.io.sstable.SSTable
-
- Direct Known Subclasses:
BigTableZeroCopyWriter,SSTableReader,SSTableWriter
public abstract class SSTable extends java.lang.ObjectThis class is built on top of the SequenceFile. It stores data on disk in sorted fashion. However the sorting is upto the application. This class expects keys to be handed to it in sorted order. A separate index file is maintained as well, containing the SSTable keys and the offset into the SSTable at which they are found. Every 1/indexInterval key is read into memory when the SSTable is opened. Finally, a bloom filter file is also kept for the keys in each SSTable.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<Component>componentsbooleancompressionDescriptordescriptorDecoratedKeyfirstDecoratedKeylastprotected TableMetadataRefmetadataprotected DiskOptimizationStrategyoptimizationStrategystatic intTOMBSTONE_HISTOGRAM_BIN_SIZEstatic intTOMBSTONE_HISTOGRAM_SPOOL_SIZEstatic intTOMBSTONE_HISTOGRAM_TTL_ROUND_SECONDS
-
Constructor Summary
Constructors Modifier Constructor Description protectedSSTable(Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata, DiskOptimizationStrategy optimizationStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddComponents(java.util.Collection<Component> newComponents)Registers new custom components.protected static voidappendTOC(Descriptor descriptor, java.util.Collection<Component> components)Appends new component names to the TOC component.longbytesOnDisk()static java.util.Set<Component>componentsFor(Descriptor desc)Discovers existing components for the descriptor.DecoratedKeydecorateKey(java.nio.ByteBuffer key)static booleandelete(Descriptor desc, java.util.Set<Component> components)We use a ReferenceQueue to manage deleting files that have been compacted and for which no more SSTable references exist.static java.util.Set<Component>discoverComponentsFor(Descriptor desc)static longestimateRowsFromIndex(RandomAccessReader ifile, Descriptor descriptor)java.util.List<java.lang.String>getAllFilePaths()AbstractBounds<Token>getBounds()java.lang.StringgetColumnFamilyName()java.util.Set<Component>getComponents()java.lang.StringgetFilename()java.lang.StringgetIndexFilename()java.lang.StringgetKeyspaceName()static DecoratedKeygetMinimalKey(DecoratedKey key)If the given @param key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.IPartitionergetPartitioner()TableMetadatametadata()protected static java.util.Set<Component>readTOC(Descriptor descriptor)Reads the list of components from the TOC component.protected static java.util.Set<Component>readTOC(Descriptor descriptor, boolean skipMissing)Reads the list of components from the TOC component.java.lang.StringtoString()static Pair<Descriptor,Component>tryComponentFromFilename(File file)Parse a sstable filename into both aDescriptorandComponentobject.static DescriptortryDescriptorFromFilename(File file)Parse a sstable filename into aDescriptorobject.static voidvalidateRepairedMetadata(long repairedAt, TimeUUID pendingRepair, boolean isTransient)
-
-
-
Field Detail
-
TOMBSTONE_HISTOGRAM_BIN_SIZE
public static final int TOMBSTONE_HISTOGRAM_BIN_SIZE
- See Also:
- Constant Field Values
-
TOMBSTONE_HISTOGRAM_SPOOL_SIZE
public static final int TOMBSTONE_HISTOGRAM_SPOOL_SIZE
- See Also:
- Constant Field Values
-
TOMBSTONE_HISTOGRAM_TTL_ROUND_SECONDS
public static final int TOMBSTONE_HISTOGRAM_TTL_ROUND_SECONDS
-
descriptor
public final Descriptor descriptor
-
components
protected final java.util.Set<Component> components
-
compression
public final boolean compression
-
first
public DecoratedKey first
-
last
public DecoratedKey last
-
optimizationStrategy
protected final DiskOptimizationStrategy optimizationStrategy
-
metadata
protected final TableMetadataRef metadata
-
-
Constructor Detail
-
SSTable
protected SSTable(Descriptor descriptor, java.util.Set<Component> components, TableMetadataRef metadata, DiskOptimizationStrategy optimizationStrategy)
-
-
Method Detail
-
getComponents
public java.util.Set<Component> getComponents()
-
delete
public static boolean delete(Descriptor desc, java.util.Set<Component> components)
We use a ReferenceQueue to manage deleting files that have been compacted and for which no more SSTable references exist. But this is not guaranteed to run for each such file because of the semantics of the JVM gc. So, we write a marker to `compactedFilename` when a file is compacted; if such a marker exists on startup, the file should be removed. This method will also remove SSTables that are marked as temporary.- Returns:
- true if the file was deleted
-
metadata
public TableMetadata metadata()
-
getPartitioner
public IPartitioner getPartitioner()
-
decorateKey
public DecoratedKey decorateKey(java.nio.ByteBuffer key)
-
getMinimalKey
public static DecoratedKey getMinimalKey(DecoratedKey key)
If the given @param key occupies only part of a larger buffer, allocate a new buffer that is only as large as necessary.
-
getFilename
public java.lang.String getFilename()
-
getIndexFilename
public java.lang.String getIndexFilename()
-
getColumnFamilyName
public java.lang.String getColumnFamilyName()
-
getKeyspaceName
public java.lang.String getKeyspaceName()
-
getAllFilePaths
public java.util.List<java.lang.String> getAllFilePaths()
-
tryComponentFromFilename
public static Pair<Descriptor,Component> tryComponentFromFilename(File file)
Parse a sstable filename into both aDescriptorandComponentobject.- Parameters:
file- the filename to parse.- Returns:
- a pair of the
DescriptorandComponentcorresponding tofileif it corresponds to a valid and supported sstable filename,nullotherwise. Note that components of an unknown type will be returned as CUSTOM ones.
-
tryDescriptorFromFilename
public static Descriptor tryDescriptorFromFilename(File file)
Parse a sstable filename into aDescriptorobject.Note that this method ignores the component part of the filename; if this is not what you want, use
tryComponentFromFilename(org.apache.cassandra.io.util.File)instead.- Parameters:
file- the filename to parse.- Returns:
- the
Descriptorcorresponding tofileif it corresponds to a valid and supported sstable filename,nullotherwise.
-
componentsFor
public static java.util.Set<Component> componentsFor(Descriptor desc)
Discovers existing components for the descriptor. Slow: only intended for use outside the critical path.
-
discoverComponentsFor
public static java.util.Set<Component> discoverComponentsFor(Descriptor desc)
-
estimateRowsFromIndex
public static long estimateRowsFromIndex(RandomAccessReader ifile, Descriptor descriptor) throws java.io.IOException
- Returns:
- An estimate of the number of keys contained in the given index file.
- Throws:
java.io.IOException
-
bytesOnDisk
public long bytesOnDisk()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
readTOC
protected static java.util.Set<Component> readTOC(Descriptor descriptor) throws java.io.IOException
Reads the list of components from the TOC component.- Returns:
- set of components found in the TOC
- Throws:
java.io.IOException
-
readTOC
protected static java.util.Set<Component> readTOC(Descriptor descriptor, boolean skipMissing) throws java.io.IOException
Reads the list of components from the TOC component.- Parameters:
skipMissing- , skip adding the component to the returned set if the corresponding file is missing.- Returns:
- set of components found in the TOC
- Throws:
java.io.IOException
-
appendTOC
protected static void appendTOC(Descriptor descriptor, java.util.Collection<Component> components)
Appends new component names to the TOC component.
-
addComponents
public void addComponents(java.util.Collection<Component> newComponents)
Registers new custom components. Used by custom compaction strategies. Adding a component for the second time is a no-op. Don't remove this - this method is a part of the public API, intended for use by custom compaction strategies.- Parameters:
newComponents- collection of components to be added
-
getBounds
public AbstractBounds<Token> getBounds()
-
validateRepairedMetadata
public static void validateRepairedMetadata(long repairedAt, TimeUUID pendingRepair, boolean isTransient)
-
-