CompactionAwareWriter (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.db.compaction.writers

## Class CompactionAwareWriter

- java.lang.Object
- - org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional
  - - org.apache.cassandra.db.compaction.writers.CompactionAwareWriter

- All Implemented Interfaces:
    java.lang.AutoCloseable, Transactional
  Direct Known Subclasses:
    DefaultCompactionWriter, MajorLeveledCompactionWriter, MaxSSTableSizeWriter, SplittingSizeTieredCompactionWriter

      public abstract class CompactionAwareWriter
      extends Transactional.AbstractTransactional
      implements Transactional

  Class that abstracts away the actual writing of files to make it possible to use CompactionTask for more use cases.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional

      `Transactional.AbstractTransactional.State`

    - ### Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional

      `Transactional.AbstractTransactional`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ColumnFamilyStore` | `cfs`
    `protected Directories` | `directories`
    `protected long` | `estimatedTotalKeys`
    `protected static org.slf4j.Logger` | `logger`
    `protected long` | `maxAge`
    `protected long` | `minRepairedAt`
    `protected java.util.Set<SSTableReader>` | `nonExpiredSSTables`
    `protected SSTableRewriter` | `sstableWriter`
    `protected LifecycleTransaction` | `txn`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, java.util.Set<SSTableReader> nonExpiredSSTables, boolean keepOriginals)`
    `CompactionAwareWriter(ColumnFamilyStore cfs, Directories directories, LifecycleTransaction txn, java.util.Set<SSTableReader> nonExpiredSSTables, boolean offline, boolean keepOriginals)` Deprecated.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `append(UnfilteredRowIterator partition)` Writes a partition in an implementation specific way
    `protected java.lang.Throwable` | `doAbort(java.lang.Throwable accumulate)`
    `protected java.lang.Throwable` | `doCommit(java.lang.Throwable accumulate)`
    `protected java.lang.Throwable` | `doPostCleanup(java.lang.Throwable accumulate)` perform an exception-safe post-abort cleanup
    `protected void` | `doPrepare()` Do any preparatory work prior to commit.
    `long` | `estimatedKeys()` estimated number of keys we should write
    `java.util.Collection<SSTableReader>` | `finish()` we are done, return the finished sstables so that the caller can mark the old ones as compacted
    `Directories` | `getDirectories()` The directories we can write to
    `Directories.DataDirectory` | `getWriteDirectory(java.lang.Iterable<SSTableReader> sstables, long estimatedWriteSize)` Return a directory where we can expect expectedWriteSize to fit.
    `protected void` | `maybeSwitchWriter(DecoratedKey key)` Guaranteed to be called before the first call to realAppend.
    `protected abstract boolean` | `realAppend(UnfilteredRowIterator partition)`
    `CompactionAwareWriter` | `setRepairedAt(long repairedAt)`
    `protected abstract void` | `switchCompactionLocation(Directories.DataDirectory directory)` Implementations of this method should finish the current sstable writer and start writing to this directory.

    - ### Methods inherited from class org.apache.cassandra.utils.concurrent.Transactional.AbstractTransactional

      `abort, abort, close, commit, commit, doPreCleanup, permitRedundantTransitions, prepareToCommit, state`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.cassandra.utils.concurrent.Transactional

      `abort, close, commit, prepareToCommit`

- - ### Field Detail

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### cfs

          protected final ColumnFamilyStore cfs

    - #### directories

          protected final Directories directories

    - #### nonExpiredSSTables

          protected final java.util.Set<SSTableReader> nonExpiredSSTables

    - #### estimatedTotalKeys

          protected final long estimatedTotalKeys

    - #### maxAge

          protected final long maxAge

    - #### minRepairedAt

          protected final long minRepairedAt

    - #### sstableWriter

          protected final SSTableRewriter sstableWriter

    - #### txn

          protected final LifecycleTransaction txn

  - ### Constructor Detail

    - #### CompactionAwareWriter

          @Deprecated
          public CompactionAwareWriter(ColumnFamilyStore cfs,
                                                   Directories directories,
                                                   LifecycleTransaction txn,
                                                   java.util.Set<SSTableReader> nonExpiredSSTables,
                                                   boolean offline,
                                                   boolean keepOriginals)

      Deprecated.

    - #### CompactionAwareWriter

          public CompactionAwareWriter(ColumnFamilyStore cfs,
                                       Directories directories,
                                       LifecycleTransaction txn,
                                       java.util.Set<SSTableReader> nonExpiredSSTables,
                                       boolean keepOriginals)

  - ### Method Detail

    - #### doAbort

          protected java.lang.Throwable doAbort(java.lang.Throwable accumulate)

      Specified by:
        `doAbort` in class `Transactional.AbstractTransactional`

    - #### doCommit

          protected java.lang.Throwable doCommit(java.lang.Throwable accumulate)

      Specified by:
        `doCommit` in class `Transactional.AbstractTransactional`

    - #### doPrepare

          protected void doPrepare()

      Description copied from class: `Transactional.AbstractTransactional`
      Do any preparatory work prior to commit. This method should throw any exceptions that can be encountered during the finalization of the behaviour.
      Specified by:
        `doPrepare` in class `Transactional.AbstractTransactional`

    - #### finish

          public java.util.Collection<SSTableReader> finish()

      we are done, return the finished sstables so that the caller can mark the old ones as compacted
      Overrides:
        `finish` in class `Transactional.AbstractTransactional`
      Returns:
        all the written sstables sstables

    - #### estimatedKeys

          public long estimatedKeys()

      estimated number of keys we should write

    - #### append

          public final boolean append(UnfilteredRowIterator partition)

      Writes a partition in an implementation specific way
      Parameters:
        `partition` - the partition to append
      Returns:
        true if the partition was written, false otherwise

    - #### doPostCleanup

          protected java.lang.Throwable doPostCleanup(java.lang.Throwable accumulate)

      Description copied from class: `Transactional.AbstractTransactional`
      perform an exception-safe post-abort cleanup
      Overrides:
        `doPostCleanup` in class `Transactional.AbstractTransactional`

    - #### realAppend

          protected abstract boolean realAppend(UnfilteredRowIterator partition)

    - #### maybeSwitchWriter

          protected void maybeSwitchWriter(DecoratedKey key)

      Guaranteed to be called before the first call to realAppend.
      Parameters:
        `key` -

    - #### switchCompactionLocation

          protected abstract void switchCompactionLocation(Directories.DataDirectory directory)

      Implementations of this method should finish the current sstable writer and start writing to this directory. Called once before starting to append and then whenever we see a need to start writing to another directory.
      Parameters:
        `directory` -

    - #### getDirectories

          public Directories getDirectories()

      The directories we can write to

    - #### getWriteDirectory

          public Directories.DataDirectory getWriteDirectory(java.lang.Iterable<SSTableReader> sstables,
                                                             long estimatedWriteSize)

      Return a directory where we can expect expectedWriteSize to fit.
      Parameters:
        `sstables` - the sstables to compact
      Returns:

    - #### setRepairedAt

          public CompactionAwareWriter setRepairedAt(long repairedAt)

Copyright © 2018 The Apache Software Foundation