Class SSTableWriter
java.lang.Object
org.apache.cassandra.io.sstable.SSTable
org.apache.cassandra.io.sstable.format.SSTableWriter
- All Implemented Interfaces:
AutoCloseable,Transactional
- Direct Known Subclasses:
SortedTableWriter
A root class for a writer implementation. A writer must be created by passing an implementation-specific
SSTableWriter.Builder, a LifecycleNewTracker and SSTable.Owner instances. Implementing classes should
not extend that list and all the additional properties should be included in the builder.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSSTableWriter.Builder<W extends SSTableWriter,B extends SSTableWriter.Builder<W, B>> A builder of this sstable writer.static interfaceParameters for calculating the expected size of an SSTable.protected classNested classes/interfaces inherited from class org.apache.cassandra.io.sstable.SSTable
SSTable.OwnerNested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional
Transactional.AbstractTransactional -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DecoratedKeyprotected final SerializationHeaderprotected booleanprotected final longprotected DecoratedKeyprotected final LifecycleNewTrackerprotected longprotected final MetadataCollectorprotected final MmappedRegionsCacheprotected final List<SSTableFlushObserver>protected TimeUUIDprotected longprotected final SSTableWriter.TransactionalProxyFields 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
ConstructorsModifierConstructorDescriptionprotectedSSTableWriter(SSTableWriter.Builder<?, ?> builder, LifecycleNewTracker lifecycleNewTracker, SSTable.Owner owner) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidabort()final Throwableabstract AbstractRowIndexEntryappend(UnfilteredRowIterator iterator) Appends partition data to this writer.final voidclose()final Throwableprotected Map<MetadataType,MetadataComponent> finish(boolean openResult) 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 operationlongReturns the amount of data already written to disk that may not be accurate (for example, the position after the recently flushed chunk).abstract longReturns 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.getFirst()getLast()abstract longReturns a position in the (compressed) data file on disk.protected voidConstructors 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 voidmark()final voidabstract voidopenEarly(Consumer<SSTableReader> doWhenReady) Open the resultant SSTableReader before it has been fully written.protected abstract SSTableReaderopenFinal(SSTableReader.OpenReason openReason) abstract SSTableReaderOpen 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 readyfinal voidvoidabstract voidReset the data file to the marked position (seemark()) and truncate the rest of the file.voidsetMaxDataAge(long maxDataAge) voidsetOpenResult(boolean openResult) voidsetRepairedAt(long repairedAt) setTokenSpaceCoverage(double rangeSpanned) protected StatsMetadataprotected abstract SSTableWriter.TransactionalProxytxnProxy()The implementing method should return an instance ofSSTableWriter.TransactionalProxyinitialized 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, getId, getKeyspaceName, getPartitioner, getStreamingComponents, hardlink, metadata, owner, registerComponents, rename, toString, tryComponentFromFilename, tryComponentFromFilename, tryDescriptorFromFile, unbuildTo, unregisterComponents, validateRepairedMetadata
-
Field Details
-
repairedAt
protected long repairedAt -
pendingRepair
-
isTransient
protected boolean isTransient -
maxDataAge
protected long maxDataAge -
keyCount
protected final long keyCount -
metadataCollector
-
header
-
observers
-
mmappedRegionsCache
-
txnProxy
-
lifecycleNewTracker
-
first
-
last
-
-
Constructor Details
-
SSTableWriter
protected SSTableWriter(SSTableWriter.Builder<?, ?> builder, LifecycleNewTracker lifecycleNewTracker, SSTable.Owner owner)
-
-
Method Details
-
txnProxy
The implementing method should return an instance ofSSTableWriter.TransactionalProxyinitialized with a list of all transactional resources included in this writer. -
handleConstructionFailure
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.Buildercan 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
-
getLast
-
getBounds
-
mark
public abstract void mark() -
append
Appends partition data to this writer.- Parameters:
iterator- the partition to write- Returns:
- the created index entry if something was written, that is if
iteratorwasn't empty,nullotherwise. - 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
-
setOpenResult
public void setOpenResult(boolean openResult) -
openEarly
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
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
-
finish
-
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:
prepareToCommitin interfaceTransactional
-
onSSTableWriterSwitched
public final void onSSTableWriterSwitched() -
commit
- Specified by:
commitin interfaceTransactional
-
abort
- Specified by:
abortin interfaceTransactional
-
close
public final void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransactional
-
abort
public final void abort() -
finalizeMetadata
-
statsMetadata
-
releaseMetadataOverhead
public void releaseMetadataOverhead()
-