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

public abstract class SSTableWriter extends SSTable implements Transactional
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.
  • Field Details

  • Constructor Details

  • Method Details

    • txnProxy

      protected abstract SSTableWriter.TransactionalProxy txnProxy()
      The implementing method should return an instance of SSTableWriter.TransactionalProxy initialized with a list of all transactional resources included in this writer.
    • handleConstructionFailure

      protected void handleConstructionFailure(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 the SSTableWriter.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()
      Specified by:
      getFirst in class SSTable
    • getLast

      public DecoratedKey getLast()
      Specified by:
      getLast in class SSTable
    • getBounds

      public AbstractBounds<Token> getBounds()
      Specified by:
      getBounds in class SSTable
    • 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 as getOnDiskFilePointer() 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. See getFilePointer()
    • 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 (see mark()) 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(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 interface Transactional
    • onSSTableWriterSwitched

      public final void onSSTableWriterSwitched()
    • commit

      public final Throwable commit(Throwable accumulate)
      Specified by:
      commit in interface Transactional
    • abort

      public final Throwable abort(Throwable accumulate)
      Specified by:
      abort in interface Transactional
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Transactional
    • abort

      public final void abort()
    • finalizeMetadata

      protected Map<MetadataType,MetadataComponent> finalizeMetadata()
    • statsMetadata

      protected StatsMetadata statsMetadata()
    • releaseMetadataOverhead

      public void releaseMetadataOverhead()