Class SSTableWriter
- java.lang.Object
-
- org.apache.cassandra.io.sstable.SSTable
-
- org.apache.cassandra.io.sstable.format.SSTableWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Transactional
- Direct Known Subclasses:
SortedTableWriter
public abstract class SSTableWriter extends SSTable implements Transactional
A root class for a writer implementation. A writer must be created by passing an implementation-specificSSTableWriter.Builder
, aLifecycleNewTracker
andSSTable.Owner
instances. Implementing classes should not extend that list and all the additional properties should be included in the builder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SSTableWriter.Builder<W extends SSTableWriter,B extends SSTableWriter.Builder<W,B>>
A builder of this sstable writer.static interface
SSTableWriter.SSTableSizeParameters
Parameters for calculating the expected size of an SSTable.protected class
SSTableWriter.TransactionalProxy
-
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.Transactional
Transactional.AbstractTransactional
-
-
Field Summary
Fields Modifier and Type Field Description protected DecoratedKey
first
protected SerializationHeader
header
protected boolean
isTransient
protected long
keyCount
protected DecoratedKey
last
protected LifecycleNewTracker
lifecycleNewTracker
protected long
maxDataAge
protected MetadataCollector
metadataCollector
protected MmappedRegionsCache
mmappedRegionsCache
protected java.util.List<SSTableFlushObserver>
observers
protected TimeUUID
pendingRepair
protected long
repairedAt
protected SSTableWriter.TransactionalProxy
txnProxy
-
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
SSTableWriter(SSTableWriter.Builder<?,?> builder, LifecycleNewTracker lifecycleNewTracker, SSTable.Owner owner)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
abort()
java.lang.Throwable
abort(java.lang.Throwable accumulate)
abstract AbstractRowIndexEntry
append(UnfilteredRowIterator iterator)
Appends partition data to this writer.void
close()
java.lang.Throwable
commit(java.lang.Throwable accumulate)
protected java.util.Map<MetadataType,MetadataComponent>
finalizeMetadata()
SSTableReader
finish(boolean openResult)
SSTableReader
finished()
Open the resultant SSTableReader once it has been fully written, and all related state is ready to be finalised including other sstables being written involved in the same operationAbstractBounds<Token>
getBounds()
long
getEstimatedOnDiskBytesWritten()
Returns the amount of data already written to disk that may not be accurate (for example, the position after the recently flushed chunk).abstract long
getFilePointer()
Returns a position in the uncompressed data - for uncompressed files it is the same asgetOnDiskFilePointer()
but for compressed files it returns a position in the data rather than a position in the file on disk.DecoratedKey
getFirst()
DecoratedKey
getLast()
abstract long
getOnDiskFilePointer()
Returns a position in the (compressed) data file on disk.protected void
handleConstructionFailure(java.lang.Throwable ex)
Constructors of subclasses, if they open any resources, should wrap that in a try-catch block and call this method in the 'catch' section after closing any resources opened in the constructor.abstract void
mark()
abstract void
openEarly(java.util.function.Consumer<SSTableReader> doWhenReady)
Open the resultant SSTableReader before it has been fully written.protected abstract SSTableReader
openFinal(SSTableReader.OpenReason openReason)
abstract SSTableReader
openFinalEarly()
Open the resultant SSTableReader once it has been fully written, but before the _set_ of tables that are being written together as one atomic operation are all readyvoid
prepareToCommit()
void
releaseMetadataOverhead()
abstract void
resetAndTruncate()
Reset the data file to the marked position (seemark()
) and truncate the rest of the file.void
setMaxDataAge(long maxDataAge)
void
setOpenResult(boolean openResult)
void
setRepairedAt(long repairedAt)
SSTableWriter
setTokenSpaceCoverage(double rangeSpanned)
protected StatsMetadata
statsMetadata()
protected abstract SSTableWriter.TransactionalProxy
txnProxy()
The implementing method should return an instance ofSSTableWriter.TransactionalProxy
initialized with a list of all transactional resources included in this writer.-
Methods inherited from class org.apache.cassandra.io.sstable.SSTable
addComponents, copy, decorateKey, getAllFilePaths, getColumnFamilyName, getComponents, getFilename, getKeyspaceName, getPartitioner, getStreamingComponents, hardlink, metadata, owner, registerComponents, rename, toString, tryComponentFromFilename, tryComponentFromFilename, tryDescriptorFromFile, unbuildTo, unregisterComponents, validateRepairedMetadata
-
-
-
-
Field Detail
-
repairedAt
protected long repairedAt
-
pendingRepair
protected TimeUUID pendingRepair
-
isTransient
protected boolean isTransient
-
maxDataAge
protected long maxDataAge
-
keyCount
protected final long keyCount
-
metadataCollector
protected final MetadataCollector metadataCollector
-
header
protected final SerializationHeader header
-
observers
protected final java.util.List<SSTableFlushObserver> observers
-
mmappedRegionsCache
protected final MmappedRegionsCache mmappedRegionsCache
-
txnProxy
protected final SSTableWriter.TransactionalProxy txnProxy
-
lifecycleNewTracker
protected final LifecycleNewTracker lifecycleNewTracker
-
first
protected DecoratedKey first
-
last
protected DecoratedKey last
-
-
Constructor Detail
-
SSTableWriter
protected SSTableWriter(SSTableWriter.Builder<?,?> builder, LifecycleNewTracker lifecycleNewTracker, SSTable.Owner owner)
-
-
Method Detail
-
txnProxy
protected abstract SSTableWriter.TransactionalProxy txnProxy()
The implementing method should return an instance ofSSTableWriter.TransactionalProxy
initialized with a list of all transactional resources included in this writer.
-
handleConstructionFailure
protected void handleConstructionFailure(java.lang.Throwable ex)
Constructors of subclasses, if they open any resources, should wrap that in a try-catch block and call this method in the 'catch' section after closing any resources opened in the constructor. This method would remove the sstable from the transaction and delete the orphaned components, if any were created during the construction. The caught exception should be then rethrown so theSSTableWriter.Builder
can handle it and close any resources opened implicitly by the builder.See
SortedTableWriter(SortedTableWriter.Builder, LifecycleNewTracker, Owner)
as of CASSANDRA-18737.- Parameters:
ex
- the exception thrown during the construction
-
getFirst
public DecoratedKey getFirst()
-
getLast
public DecoratedKey getLast()
-
getBounds
public AbstractBounds<Token> getBounds()
-
mark
public abstract void mark()
-
append
public abstract AbstractRowIndexEntry append(UnfilteredRowIterator iterator)
Appends partition data to this writer.- Parameters:
iterator
- the partition to write- Returns:
- the created index entry if something was written, that is if
iterator
wasn't empty,null
otherwise. - Throws:
FSWriteError
- if writing to the dataFile fails
-
getFilePointer
public abstract long getFilePointer()
Returns a position in the uncompressed data - for uncompressed files it is the same asgetOnDiskFilePointer()
but for compressed files it returns a position in the data rather than a position in the file on disk.
-
getOnDiskFilePointer
public abstract long getOnDiskFilePointer()
Returns a position in the (compressed) data file on disk. SeegetFilePointer()
-
getEstimatedOnDiskBytesWritten
public long getEstimatedOnDiskBytesWritten()
Returns the amount of data already written to disk that may not be accurate (for example, the position after the recently flushed chunk).
-
resetAndTruncate
public abstract void resetAndTruncate()
Reset the data file to the marked position (seemark()
) and truncate the rest of the file.
-
setRepairedAt
public void setRepairedAt(long repairedAt)
-
setMaxDataAge
public void setMaxDataAge(long maxDataAge)
-
setTokenSpaceCoverage
public SSTableWriter setTokenSpaceCoverage(double rangeSpanned)
-
setOpenResult
public void setOpenResult(boolean openResult)
-
openEarly
public abstract void openEarly(java.util.function.Consumer<SSTableReader> doWhenReady)
Open the resultant SSTableReader before it has been fully written.The passed consumer will be called when the necessary data has been flushed to disk/cache. This may never happen (e.g. if the table was finished before the flushes materialized, or if this call returns false e.g. if a table was already prepared but hasn't reached readiness yet).
Uses callback instead of future because preparation and callback happen on the same thread.
-
openFinalEarly
public abstract SSTableReader openFinalEarly()
Open the resultant SSTableReader once it has been fully written, but before the _set_ of tables that are being written together as one atomic operation are all ready
-
openFinal
protected abstract SSTableReader openFinal(SSTableReader.OpenReason openReason)
-
finish
public SSTableReader finish(boolean openResult)
-
finished
public SSTableReader finished()
Open the resultant SSTableReader once it has been fully written, and all related state is ready to be finalised including other sstables being written involved in the same operation
-
prepareToCommit
public final void prepareToCommit()
- Specified by:
prepareToCommit
in interfaceTransactional
-
commit
public final java.lang.Throwable commit(java.lang.Throwable accumulate)
- Specified by:
commit
in interfaceTransactional
-
abort
public final java.lang.Throwable abort(java.lang.Throwable accumulate)
- Specified by:
abort
in interfaceTransactional
-
close
public final void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceTransactional
-
abort
public final void abort()
-
finalizeMetadata
protected java.util.Map<MetadataType,MetadataComponent> finalizeMetadata()
-
statsMetadata
protected StatsMetadata statsMetadata()
-
releaseMetadataOverhead
public void releaseMetadataOverhead()
-
-