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

org.apache.cassandra.db.compaction

## Class CompactionStrategyManager

- java.lang.Object
- - org.apache.cassandra.db.compaction.CompactionStrategyManager

- All Implemented Interfaces:
    INotificationConsumer

      public class CompactionStrategyManager
      extends java.lang.Object
      implements INotificationConsumer

  Manages the compaction strategies. Currently has two instances of actual compaction strategies per data directory - one for repaired data and one for unrepaired data. This is done to be able to totally separate the different sets of sstables. Operations on this class are guarded by a `ReentrantReadWriteLock`. This lock performs mutual exclusion on reads and writes to the following variables: `this#repaired`, `this#unrepaired`, `this#isActive`, `this#params`, `this#currentBoundaries`. Whenever performing reads on these variables, the `this#readLock` should be acquired. Likewise, updates to these variables should be guarded by `this#writeLock`. Whenever the `DiskBoundaries` change, the compaction strategies must be reloaded, so in order to ensure the compaction strategy placement reflect most up-to-date disk boundaries, call `this#maybeReloadDiskBoundaries()` before acquiring the read lock to acess the strategies.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `CompactionLogger` | `compactionLogger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompactionStrategyManager(ColumnFamilyStore cfs)`
    `CompactionStrategyManager(ColumnFamilyStore cfs, java.util.function.Supplier<DiskBoundaries> boundariesSupplier, boolean partitionSSTablesByTokenRange)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected AbstractCompactionStrategy` | `compactionStrategyFor(SSTableReader sstable)`
    `protected int` | `compactionStrategyIndexFor(SSTableReader sstable)` Get the correct compaction strategy for the given sstable.
    `SSTableMultiWriter` | `createSSTableMultiWriter(Descriptor descriptor, long keyCount, long repairedAt, MetadataCollector collector, SerializationHeader header, java.util.Collection<Index> indexes, LifecycleTransaction txn)`
    `void` | `disable()`
    `void` | `enable()`
    `CompactionParams` | `getCompactionParams()`
    `protected AbstractCompactionStrategy` | `getCompactionStrategyFor(SSTableReader sstable)` return the compaction strategy for the given sstable returns differently based on the repaired status and which vnode the compaction strategy belongs to
    `AbstractCompactionTask` | `getCompactionTask(LifecycleTransaction txn, int gcBefore, long maxSSTableBytes)`
    `Directories` | `getDirectories()`
    `int` | `getEstimatedRemainingTasks()`
    `int` | `getLevelFanoutSize()`
    `java.util.Collection<AbstractCompactionTask>` | `getMaximalTasks(int gcBefore, boolean splitOutput)`
    `long` | `getMaxSSTableBytes()`
    `java.lang.String` | `getName()`
    `AbstractCompactionTask` | `getNextBackgroundTask(int gcBefore)` Return the next background task Returns a task for the compaction strategy that needs it the most (most estimated remaining tasks)
    `AbstractCompactionStrategy.ScannerList` | `getScanners(java.util.Collection<SSTableReader> sstables)`
    `AbstractCompactionStrategy.ScannerList` | `getScanners(java.util.Collection<SSTableReader> sstables, java.util.Collection<Range<Token>> ranges)` Create ISSTableScanners from the given sstables Delegates the call to the compaction strategies to allow LCS to create a scanner
    `int[]` | `getSSTableCountPerLevel()`
    `java.util.List<java.util.List<AbstractCompactionStrategy>>` | `getStrategies()`
    `java.util.List<java.lang.String>` | `getStrategyFolders(AbstractCompactionStrategy strategy)`
    `int` | `getUnleveledSSTables()`
    `AbstractCompactionTask` | `getUserDefinedTask(java.util.Collection<SSTableReader> sstables, int gcBefore)` Deprecated. use `getUserDefinedTasks(Collection, int)` instead.
    `java.util.List<AbstractCompactionTask>` | `getUserDefinedTasks(java.util.Collection<SSTableReader> sstables, int gcBefore)` Return a list of compaction tasks corresponding to the sstables requested.
    `java.util.List<AbstractCompactionTask>` | `getUserDefinedTasks(java.util.Collection<SSTableReader> sstables, int gcBefore, boolean validateForCompaction)`
    `java.util.Collection<java.util.Collection<SSTableReader>>` | `groupSSTablesForAntiCompaction(java.util.Collection<SSTableReader> sstablesToGroup)`
    `void` | `handleNotification(INotification notification, java.lang.Object sender)`
    `boolean` | `isActive()`
    `boolean` | `isEnabled()`
    `boolean` | `isRepaired(AbstractCompactionStrategy strategy)`
    `void` | `maybeReload(CFMetaData metadata)`
    `protected boolean` | `maybeReloadDiskBoundaries()` Checks if the disk boundaries changed and reloads the compaction strategies to reflect the most up-to-date disk boundaries.
    `boolean` | `onlyPurgeRepairedTombstones()`
    `void` | `pause()` pause compaction while we cancel all ongoing compactions Separate call from enable/disable to not have to save the enabled-state externally
    `void` | `replaceFlushed(Memtable memtable, java.util.Collection<SSTableReader> sstables)`
    `void` | `resume()`
    `void` | `setNewLocalCompactionStrategy(CompactionParams params)`
    `boolean` | `shouldBeEnabled()`
    `boolean` | `shouldDefragment()`
    `void` | `shutdown()`
    `boolean` | `supportsEarlyOpen()`

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

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

- - ### Field Detail

    - #### compactionLogger

          public final CompactionLogger compactionLogger

  - ### Constructor Detail

    - #### CompactionStrategyManager

          public CompactionStrategyManager(ColumnFamilyStore cfs)

    - #### CompactionStrategyManager

          public CompactionStrategyManager(ColumnFamilyStore cfs,
                                           java.util.function.Supplier<DiskBoundaries> boundariesSupplier,
                                           boolean partitionSSTablesByTokenRange)

  - ### Method Detail

    - #### getNextBackgroundTask

          public AbstractCompactionTask getNextBackgroundTask(int gcBefore)

      Return the next background task Returns a task for the compaction strategy that needs it the most (most estimated remaining tasks)

    - #### isEnabled

          public boolean isEnabled()

    - #### isActive

          public boolean isActive()

    - #### resume

          public void resume()

    - #### pause

          public void pause()

      pause compaction while we cancel all ongoing compactions Separate call from enable/disable to not have to save the enabled-state externally

    - #### getCompactionStrategyFor

          protected AbstractCompactionStrategy getCompactionStrategyFor(SSTableReader sstable)

      return the compaction strategy for the given sstable returns differently based on the repaired status and which vnode the compaction strategy belongs to
      Parameters:
        `sstable` -
      Returns:

    - #### compactionStrategyFor

          protected AbstractCompactionStrategy compactionStrategyFor(SSTableReader sstable)

    - #### compactionStrategyIndexFor

          protected int compactionStrategyIndexFor(SSTableReader sstable)

      Get the correct compaction strategy for the given sstable. If the first token starts within a disk boundary, we will add it to that compaction strategy. In the case we are upgrading, the first compaction strategy will get most files - we do not care about which disk the sstable is on currently (unless we don't know the local tokens yet). Once we start compacting we will write out sstables in the correct locations and give them to the correct compaction strategy instance.
      Parameters:
        `sstable` -
      Returns:

    - #### shutdown

          public void shutdown()

    - #### maybeReload

          public void maybeReload(CFMetaData metadata)

    - #### maybeReloadDiskBoundaries

          protected boolean maybeReloadDiskBoundaries()

      Checks if the disk boundaries changed and reloads the compaction strategies to reflect the most up-to-date disk boundaries. This is typically called before acquiring the `this#readLock` to ensure the most up-to-date disk locations and boundaries are used. This should *never* be called inside by a thread holding the `this#readLock`, since it will potentially acquire the `this#writeLock` to update the compaction strategies what can cause a deadlock.

    - #### replaceFlushed

          public void replaceFlushed(Memtable memtable,
                                     java.util.Collection<SSTableReader> sstables)

    - #### getUnleveledSSTables

          public int getUnleveledSSTables()

    - #### getLevelFanoutSize

          public int getLevelFanoutSize()

    - #### getSSTableCountPerLevel

          public int[] getSSTableCountPerLevel()

    - #### shouldDefragment

          public boolean shouldDefragment()

    - #### getDirectories

          public Directories getDirectories()

    - #### handleNotification

          public void handleNotification(INotification notification,
                                         java.lang.Object sender)

      Specified by:
        `handleNotification` in interface `INotificationConsumer`

    - #### enable

          public void enable()

    - #### disable

          public void disable()

    - #### getScanners

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

      Create ISSTableScanners from the given sstables Delegates the call to the compaction strategies to allow LCS to create a scanner
      Parameters:
        `sstables` -
        `ranges` -
      Returns:

    - #### getScanners

          public AbstractCompactionStrategy.ScannerList getScanners(java.util.Collection<SSTableReader> sstables)

    - #### groupSSTablesForAntiCompaction

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

    - #### getMaxSSTableBytes

          public long getMaxSSTableBytes()

    - #### getCompactionTask

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

    - #### getMaximalTasks

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

    - #### getUserDefinedTasks

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

      Return a list of compaction tasks corresponding to the sstables requested. Split the sstables according to whether they are repaired or not, and by disk location. Return a task per disk location and repair status group.
      Parameters:
        `sstables` - the sstables to compact
        `gcBefore` - gc grace period, throw away tombstones older than this
      Returns:
        a list of compaction tasks corresponding to the sstables requested

    - #### getUserDefinedTasks

          public java.util.List<AbstractCompactionTask> getUserDefinedTasks(java.util.Collection<SSTableReader> sstables,
                                                                            int gcBefore,
                                                                            boolean validateForCompaction)

    - #### getUserDefinedTask

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

      Deprecated. use `getUserDefinedTasks(Collection, int)` instead.

    - #### getEstimatedRemainingTasks

          public int getEstimatedRemainingTasks()

    - #### shouldBeEnabled

          public boolean shouldBeEnabled()

    - #### getName

          public java.lang.String getName()

    - #### getStrategies

          public java.util.List<java.util.List<AbstractCompactionStrategy>> getStrategies()

    - #### setNewLocalCompactionStrategy

          public void setNewLocalCompactionStrategy(CompactionParams params)

    - #### getCompactionParams

          public CompactionParams getCompactionParams()

    - #### onlyPurgeRepairedTombstones

          public boolean onlyPurgeRepairedTombstones()

    - #### createSSTableMultiWriter

          public SSTableMultiWriter createSSTableMultiWriter(Descriptor descriptor,
                                                             long keyCount,
                                                             long repairedAt,
                                                             MetadataCollector collector,
                                                             SerializationHeader header,
                                                             java.util.Collection<Index> indexes,
                                                             LifecycleTransaction txn)

    - #### isRepaired

          public boolean isRepaired(AbstractCompactionStrategy strategy)

    - #### getStrategyFolders

          public java.util.List<java.lang.String> getStrategyFolders(AbstractCompactionStrategy strategy)

    - #### supportsEarlyOpen

          public boolean supportsEarlyOpen()

Copyright © 2018 The Apache Software Foundation