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

org.apache.cassandra.db.compaction

## Class LeveledCompactionStrategy

- java.lang.Object
- - org.apache.cassandra.db.compaction.AbstractCompactionStrategy
  - - org.apache.cassandra.db.compaction.LeveledCompactionStrategy

-     public class LeveledCompactionStrategy
      extends AbstractCompactionStrategy

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.cassandra.db.compaction.AbstractCompactionStrategy

      `AbstractCompactionStrategy.ScannerList`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_LEVEL_FANOUT_SIZE`

    - ### Fields inherited from class org.apache.cassandra.db.compaction.AbstractCompactionStrategy

      `cfs, COMPACTION_ENABLED, DEFAULT_LOG_ALL_OPTION, DEFAULT_TOMBSTONE_COMPACTION_INTERVAL, DEFAULT_TOMBSTONE_THRESHOLD, DEFAULT_UNCHECKED_TOMBSTONE_COMPACTION_OPTION, disableTombstoneCompactions, isActive, LOG_ALL_OPTION, logAll, ONLY_PURGE_REPAIRED_TOMBSTONES, options, TOMBSTONE_COMPACTION_INTERVAL_OPTION, TOMBSTONE_THRESHOLD_OPTION, tombstoneCompactionInterval, tombstoneThreshold, UNCHECKED_TOMBSTONE_COMPACTION_OPTION, uncheckedTombstoneCompaction`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LeveledCompactionStrategy(ColumnFamilyStore cfs, java.util.Map<java.lang.String,java.lang.String> options)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addSSTable(SSTableReader added)`
    `int[]` | `getAllLevelSize()`
    `AbstractCompactionTask` | `getCompactionTask(LifecycleTransaction txn, int gcBefore, long maxSSTableBytes)`
    `int` | `getEstimatedRemainingTasks()`
    `int` | `getLevelFanoutSize()`
    `int` | `getLevelSize(int i)`
    `java.util.Collection<AbstractCompactionTask>` | `getMaximalTask(int gcBefore, boolean splitOutput)`
    `long` | `getMaxSSTableBytes()`
    `AbstractCompactionTask` | `getNextBackgroundTask(int gcBefore)` the only difference between background and maximal in LCS is that maximal is still allowed (by explicit user request) even when compaction is disabled.
    `AbstractCompactionStrategy.ScannerList` | `getScanners(java.util.Collection<SSTableReader> sstables, java.util.Collection<Range<Token>> ranges)` Returns a list of KeyScanners given sstables and a range on which to scan.
    `AbstractCompactionTask` | `getUserDefinedTask(java.util.Collection<SSTableReader> sstables, int gcBefore)`
    `java.util.Collection<java.util.Collection<SSTableReader>>` | `groupSSTablesForAntiCompaction(java.util.Collection<SSTableReader> ssTablesToGroup)` Leveled compaction strategy has guarantees on the data contained within each level so we have to make sure we only create groups of SSTables with members from the same level.
    `void` | `removeSSTable(SSTableReader sstable)`
    `void` | `replaceSSTables(java.util.Collection<SSTableReader> removed, java.util.Collection<SSTableReader> added)`
    `void` | `startup()` Performs any extra initialization required
    `CompactionLogger.Strategy` | `strategyLogger()`
    `java.lang.String` | `toString()`
    `static java.util.Map<java.lang.String,java.lang.String>` | `validateOptions(java.util.Map<java.lang.String,java.lang.String> options)`

    - ### Methods inherited from class org.apache.cassandra.db.compaction.AbstractCompactionStrategy

      `addSSTables, createSSTableMultiWriter, disable, enable, filterSuspectSSTables, getDirectories, getMemtableReservedSize, getName, getScanners, getScanners, isAffectedByMeteredFlusher, pause, replaceFlushed, resume, shouldBeEnabled, shouldDefragment, shutdown, supportsEarlyOpen, worthDroppingTombstones`

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

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

- - ### Field Detail

    - #### DEFAULT_LEVEL_FANOUT_SIZE

          public static final int DEFAULT_LEVEL_FANOUT_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LeveledCompactionStrategy

          public LeveledCompactionStrategy(ColumnFamilyStore cfs,
                                           java.util.Map<java.lang.String,java.lang.String> options)

  - ### Method Detail

    - #### getLevelSize

          public int getLevelSize(int i)

    - #### getAllLevelSize

          public int[] getAllLevelSize()

    - #### startup

          public void startup()

      Description copied from class: `AbstractCompactionStrategy`
      Performs any extra initialization required
      Overrides:
        `startup` in class `AbstractCompactionStrategy`

    - #### getNextBackgroundTask

          public AbstractCompactionTask getNextBackgroundTask(int gcBefore)

      the only difference between background and maximal in LCS is that maximal is still allowed (by explicit user request) even when compaction is disabled.
      Specified by:
        `getNextBackgroundTask` in class `AbstractCompactionStrategy`
      Parameters:
        `gcBefore` - throw away tombstones older than this
      Returns:
        the next background/minor compaction task to run; null if nothing to do. Is responsible for marking its sstables as compaction-pending.

    - #### getMaximalTask

          public java.util.Collection<AbstractCompactionTask> getMaximalTask(int gcBefore,
                                                                             boolean splitOutput)

      Specified by:
        `getMaximalTask` in class `AbstractCompactionStrategy`
      Parameters:
        `gcBefore` - throw away tombstones older than this
      Returns:
        a compaction task that should be run to compact this columnfamilystore as much as possible. Null if nothing to do. Is responsible for marking its sstables as compaction-pending.

    - #### getUserDefinedTask

          public AbstractCompactionTask getUserDefinedTask(java.util.Collection<SSTableReader> sstables,
                                                           int gcBefore)

      Specified by:
        `getUserDefinedTask` in class `AbstractCompactionStrategy`
      Parameters:
        `sstables` - SSTables to compact. Must be marked as compacting.
        `gcBefore` - throw away tombstones older than this
      Returns:
        a compaction task corresponding to the requested sstables. Will not be null. (Will throw if user requests an invalid compaction.) Is responsible for marking its sstables as compaction-pending.

    - #### getCompactionTask

          public AbstractCompactionTask getCompactionTask(LifecycleTransaction txn,
                                                          int gcBefore,
                                                          long maxSSTableBytes)

      Overrides:
        `getCompactionTask` in class `AbstractCompactionStrategy`

    - #### groupSSTablesForAntiCompaction

          public java.util.Collection<java.util.Collection<SSTableReader>> groupSSTablesForAntiCompaction(java.util.Collection<SSTableReader> ssTablesToGroup)

      Leveled compaction strategy has guarantees on the data contained within each level so we have to make sure we only create groups of SSTables with members from the same level. This way we won't end up creating invalid sstables during anti-compaction.
      Overrides:
        `groupSSTablesForAntiCompaction` in class `AbstractCompactionStrategy`
      Parameters:
        `ssTablesToGroup` -
      Returns:
        Groups of sstables from the same level

    - #### getEstimatedRemainingTasks

          public int getEstimatedRemainingTasks()

      Specified by:
        `getEstimatedRemainingTasks` in class `AbstractCompactionStrategy`
      Returns:
        the number of background tasks estimated to still be needed for this columnfamilystore

    - #### getMaxSSTableBytes

          public long getMaxSSTableBytes()

      Specified by:
        `getMaxSSTableBytes` in class `AbstractCompactionStrategy`
      Returns:
        size in bytes of the largest sstables for this strategy

    - #### getLevelFanoutSize

          public int getLevelFanoutSize()

    - #### getScanners

          public AbstractCompactionStrategy.ScannerList getScanners(java.util.Collection<SSTableReader> sstables,
                                                                    java.util.Collection<Range<Token>> ranges)

      Description copied from class: `AbstractCompactionStrategy`
      Returns a list of KeyScanners given sstables and a range on which to scan. The default implementation simply grab one SSTableScanner per-sstable, but overriding this method allow for a more memory efficient solution if we know the sstable don't overlap (see LeveledCompactionStrategy for instance).
      Overrides:
        `getScanners` in class `AbstractCompactionStrategy`

    - #### replaceSSTables

          public void replaceSSTables(java.util.Collection<SSTableReader> removed,
                                      java.util.Collection<SSTableReader> added)

      Overrides:
        `replaceSSTables` in class `AbstractCompactionStrategy`

    - #### addSSTable

          public void addSSTable(SSTableReader added)

      Specified by:
        `addSSTable` in class `AbstractCompactionStrategy`

    - #### removeSSTable

          public void removeSSTable(SSTableReader sstable)

      Specified by:
        `removeSSTable` in class `AbstractCompactionStrategy`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### strategyLogger

          public CompactionLogger.Strategy strategyLogger()

      Overrides:
        `strategyLogger` in class `AbstractCompactionStrategy`

    - #### validateOptions

          public static java.util.Map<java.lang.String,java.lang.String> validateOptions(java.util.Map<java.lang.String,java.lang.String> options)
                                                                                  throws ConfigurationException

      Throws:
        `ConfigurationException`

Copyright © 2018 The Apache Software Foundation