org.apache.cassandra.db.compaction

## Class CompactionManager

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

- All Implemented Interfaces:
    CompactionManagerMBean

      public class CompactionManager
      extends java.lang.Object
      implements CompactionManagerMBean

  A singleton which manages a private executor of ongoing compactions. A readwrite lock controls whether compactions can proceed: an external consumer can completely stop compactions by acquiring the write half of the lock via getCompactionLock(). Scheduling for compaction is accomplished by swapping sstables to be compacted into a set via DataTracker. New scheduling attempts will ignore currently compacting sstables.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `CompactionManager.CompactionExecutorStatsCollector`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `GC_ALL`
    `static CompactionManager` | `instance`
    `static java.lang.ThreadLocal<java.lang.Boolean>` | `isCompactionManager`
    `static java.lang.String` | `MBEAN_OBJECT_NAME`
    `static int` | `NO_GC`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompactionManager()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `disableAutoCompaction()`
    `void` | `forceUserDefinedCompaction(java.lang.String ksname, java.lang.String dataFiles)` Triggers the compaction of user specified sstables.
    `int` | `getActiveCompactions()`
    `java.util.concurrent.locks.Lock` | `getCompactionLock()`
    `java.util.List<java.util.Map<java.lang.String,java.lang.String>>` | `getCompactions()` List of running compaction objects.
    `java.util.List<java.lang.String>` | `getCompactionSummary()` List of running compaction summary strings.
    `long` | `getCompletedTasks()`
    `int` | `getCoreCompactorThreads()` Returns core size of compaction thread pool
    `int` | `getCoreValidationThreads()` Returns core size of validation thread pool
    `int` | `getMaximumCompactorThreads()` Returns maximum size of compaction thread pool
    `int` | `getMaximumValidatorThreads()` Returns size of validator thread pool
    `int` | `getPendingTasks()`
    `com.google.common.util.concurrent.RateLimiter` | `getRateLimiter()` Gets compaction rate limiter.
    `long` | `getTotalBytesCompacted()`
    `long` | `getTotalCompactionsCompleted()`
    `static SSTableWriter` | `maybeCreateWriter(ColumnFamilyStore cfs, java.io.File compactionFileLocation, int expectedBloomFilterSize, SSTableWriter writer, java.util.Collection<SSTableReader> sstables)`
    `void` | `performCleanup(ColumnFamilyStore cfStore, CounterId.OneShotRenewer renewer)`
    `void` | `performMaximal(ColumnFamilyStore cfStore)`
    `void` | `performScrub(ColumnFamilyStore cfStore)`
    `void` | `performSSTableRewrite(ColumnFamilyStore cfStore, boolean excludeCurrentVersion)`
    `void` | `setCoreCompactorThreads(int number)` Allows user to resize maximum size of the compaction thread pool.
    `void` | `setCoreValidationThreads(int number)` Allows user to resize maximum size of the compaction thread pool.
    `void` | `setMaximumCompactorThreads(int number)` Allows user to resize maximum size of the compaction thread pool.
    `void` | `setMaximumValidatorThreads(int number)` Allows user to resize maximum size of the validator thread pool.
    `void` | `stopCompaction(java.lang.String type)` Stop all running compaction-like tasks having the provided `type`.
    `void` | `stopCompactionFor(java.util.Collection<CFMetaData> columnFamilies)` Try to stop all of the compactions for given ColumnFamilies.
    `java.util.List<java.util.concurrent.Future<?>>` | `submitBackground(ColumnFamilyStore cfs)` Call this whenever a compaction might be needed on the given columnfamily.
    `java.util.concurrent.Future<?>` | `submitCacheWrite(AutoSavingCache.Writer writer)`
    `java.util.concurrent.Future<?>` | `submitIndexBuild(SecondaryIndexBuilder builder)` Is not scheduled, because it is performing disjoint work from sstable compaction.
    `java.util.concurrent.Future<?>` | `submitMaximal(ColumnFamilyStore cfStore, int gcBefore)`
    `java.util.concurrent.Future<?>` | `submitTruncate(ColumnFamilyStore main, long truncatedAt)`
    `java.util.concurrent.Future<?>` | `submitUserDefined(ColumnFamilyStore cfs, java.util.Collection<Descriptor> dataFiles, int gcBefore)`
    `java.util.concurrent.Future<java.lang.Object>` | `submitValidation(ColumnFamilyStore cfStore, AntiEntropyService.Validator validator)` Does not mutate data, so is not scheduled.

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

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

- - ### Field Detail

    - #### MBEAN_OBJECT_NAME

          public static final java.lang.String MBEAN_OBJECT_NAME

      See Also:
        Constant Field Values

    - #### instance

          public static final CompactionManager instance

    - #### NO_GC

          public static final int NO_GC

      See Also:
        Constant Field Values

    - #### GC_ALL

          public static final int GC_ALL

      See Also:
        Constant Field Values

    - #### isCompactionManager

          public static final java.lang.ThreadLocal<java.lang.Boolean> isCompactionManager

  - ### Constructor Detail

    - #### CompactionManager

          public CompactionManager()

  - ### Method Detail

    - #### getRateLimiter

          public com.google.common.util.concurrent.RateLimiter getRateLimiter()

      Gets compaction rate limiter. When compaction_throughput_mb_per_sec is 0 or node is bootstrapping, this returns rate limiter with the rate of Double.MAX_VALUE bytes per second. Rate unit is bytes per sec.
      Returns:
        RateLimiter with rate limit set

    - #### getCompactionLock

          public java.util.concurrent.locks.Lock getCompactionLock()

      Returns:
        A lock, for which acquisition means no compactions can run.

    - #### submitBackground

          public java.util.List<java.util.concurrent.Future<?>> submitBackground(ColumnFamilyStore cfs)

      Call this whenever a compaction might be needed on the given columnfamily. It's okay to over-call (within reason) if a call is unnecessary, it will turn into a no-op in the bucketing/candidate-scan phase.

    - #### performScrub

          public void performScrub(ColumnFamilyStore cfStore)
                            throws java.lang.InterruptedException,
                                   java.util.concurrent.ExecutionException

      Throws:
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`

    - #### performSSTableRewrite

          public void performSSTableRewrite(ColumnFamilyStore cfStore,
                                   boolean excludeCurrentVersion)
                                     throws java.lang.InterruptedException,
                                            java.util.concurrent.ExecutionException

      Throws:
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`

    - #### performCleanup

          public void performCleanup(ColumnFamilyStore cfStore,
                            CounterId.OneShotRenewer renewer)
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException

      Throws:
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`

    - #### performMaximal

          public void performMaximal(ColumnFamilyStore cfStore)
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException

      Throws:
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`

    - #### submitMaximal

          public java.util.concurrent.Future<?> submitMaximal(ColumnFamilyStore cfStore,
                                                     int gcBefore)

    - #### forceUserDefinedCompaction

          public void forceUserDefinedCompaction(java.lang.String ksname,
                                        java.lang.String dataFiles)

      Description copied from interface: `CompactionManagerMBean`
      Triggers the compaction of user specified sstables.
      Specified by:
        `forceUserDefinedCompaction` in interface `CompactionManagerMBean`
      Parameters:
        `ksname` - the keyspace for the sstables to compact
        `dataFiles` - a comma separated list of sstable filename to compact

    - #### submitUserDefined

          public java.util.concurrent.Future<?> submitUserDefined(ColumnFamilyStore cfs,
                                                         java.util.Collection<Descriptor> dataFiles,
                                                         int gcBefore)

    - #### submitValidation

          public java.util.concurrent.Future<java.lang.Object> submitValidation(ColumnFamilyStore cfStore,
                                                                       AntiEntropyService.Validator validator)

      Does not mutate data, so is not scheduled.

    - #### disableAutoCompaction

          public void disableAutoCompaction()

    - #### maybeCreateWriter

          public static SSTableWriter maybeCreateWriter(ColumnFamilyStore cfs,
                                        java.io.File compactionFileLocation,
                                        int expectedBloomFilterSize,
                                        SSTableWriter writer,
                                        java.util.Collection<SSTableReader> sstables)

    - #### submitIndexBuild

          public java.util.concurrent.Future<?> submitIndexBuild(SecondaryIndexBuilder builder)

      Is not scheduled, because it is performing disjoint work from sstable compaction.

    - #### submitCacheWrite

          public java.util.concurrent.Future<?> submitCacheWrite(AutoSavingCache.Writer writer)

    - #### submitTruncate

          public java.util.concurrent.Future<?> submitTruncate(ColumnFamilyStore main,
                                                      long truncatedAt)

    - #### getActiveCompactions

          public int getActiveCompactions()

    - #### getCompactions

          public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getCompactions()

      Description copied from interface: `CompactionManagerMBean`
      List of running compaction objects.
      Specified by:
        `getCompactions` in interface `CompactionManagerMBean`

    - #### getCompactionSummary

          public java.util.List<java.lang.String> getCompactionSummary()

      Description copied from interface: `CompactionManagerMBean`
      List of running compaction summary strings.
      Specified by:
        `getCompactionSummary` in interface `CompactionManagerMBean`

    - #### getTotalBytesCompacted

          public long getTotalBytesCompacted()

      Specified by:
        `getTotalBytesCompacted` in interface `CompactionManagerMBean`
      Returns:
        total number of bytes compacted since server [re]start
      See Also:
        `CompactionMetrics.bytesCompacted`

    - #### getTotalCompactionsCompleted

          public long getTotalCompactionsCompleted()

      Specified by:
        `getTotalCompactionsCompleted` in interface `CompactionManagerMBean`
      Returns:
        total number of compactions since server [re]start
      See Also:
        `CompactionMetrics.totalCompactionsCompleted`

    - #### getPendingTasks

          public int getPendingTasks()

      Specified by:
        `getPendingTasks` in interface `CompactionManagerMBean`
      Returns:
        estimated number of compactions remaining to perform
      See Also:
        `CompactionMetrics.pendingTasks`

    - #### getCompletedTasks

          public long getCompletedTasks()

      Specified by:
        `getCompletedTasks` in interface `CompactionManagerMBean`
      Returns:
        number of completed compactions since server [re]start
      See Also:
        `CompactionMetrics.completedTasks`

    - #### stopCompaction

          public void stopCompaction(java.lang.String type)

      Description copied from interface: `CompactionManagerMBean`
      Stop all running compaction-like tasks having the provided `type`.
      Specified by:
        `stopCompaction` in interface `CompactionManagerMBean`
      Parameters:
        `type` - the type of compaction to stop. Can be one of: - COMPACTION - VALIDATION - CLEANUP - SCRUB - INDEX_BUILD

    - #### getCoreCompactorThreads

          public int getCoreCompactorThreads()

      Description copied from interface: `CompactionManagerMBean`
      Returns core size of compaction thread pool
      Specified by:
        `getCoreCompactorThreads` in interface `CompactionManagerMBean`

    - #### setCoreCompactorThreads

          public void setCoreCompactorThreads(int number)

      Description copied from interface: `CompactionManagerMBean`
      Allows user to resize maximum size of the compaction thread pool.
      Specified by:
        `setCoreCompactorThreads` in interface `CompactionManagerMBean`
      Parameters:
        `number` - New maximum of compaction threads

    - #### getMaximumCompactorThreads

          public int getMaximumCompactorThreads()

      Description copied from interface: `CompactionManagerMBean`
      Returns maximum size of compaction thread pool
      Specified by:
        `getMaximumCompactorThreads` in interface `CompactionManagerMBean`

    - #### setMaximumCompactorThreads

          public void setMaximumCompactorThreads(int number)

      Description copied from interface: `CompactionManagerMBean`
      Allows user to resize maximum size of the compaction thread pool.
      Specified by:
        `setMaximumCompactorThreads` in interface `CompactionManagerMBean`
      Parameters:
        `number` - New maximum of compaction threads

    - #### getCoreValidationThreads

          public int getCoreValidationThreads()

      Description copied from interface: `CompactionManagerMBean`
      Returns core size of validation thread pool
      Specified by:
        `getCoreValidationThreads` in interface `CompactionManagerMBean`

    - #### setCoreValidationThreads

          public void setCoreValidationThreads(int number)

      Description copied from interface: `CompactionManagerMBean`
      Allows user to resize maximum size of the compaction thread pool.
      Specified by:
        `setCoreValidationThreads` in interface `CompactionManagerMBean`
      Parameters:
        `number` - New maximum of compaction threads

    - #### getMaximumValidatorThreads

          public int getMaximumValidatorThreads()

      Description copied from interface: `CompactionManagerMBean`
      Returns size of validator thread pool
      Specified by:
        `getMaximumValidatorThreads` in interface `CompactionManagerMBean`

    - #### setMaximumValidatorThreads

          public void setMaximumValidatorThreads(int number)

      Description copied from interface: `CompactionManagerMBean`
      Allows user to resize maximum size of the validator thread pool.
      Specified by:
        `setMaximumValidatorThreads` in interface `CompactionManagerMBean`
      Parameters:
        `number` - New maximum of validator threads

    - #### stopCompactionFor

          public void stopCompactionFor(java.util.Collection<CFMetaData> columnFamilies)

      Try to stop all of the compactions for given ColumnFamilies. Note that this method does not wait indefinitely for all compactions to finish, maximum wait time is 30 secs.
      Parameters:
        `columnFamilies` - The ColumnFamilies to try to stop compaction upon.

Copyright © 2014 The Apache Software Foundation