Class CompactionStrategyManager

  • All Implemented Interfaces:
    INotificationConsumer

    public class CompactionStrategyManager
    extends java.lang.Object
    implements INotificationConsumer
    Manages the compaction strategies. SSTables are isolated from each other based on their incremental repair status (repaired, unrepaired, or pending repair) and directory (determined by their starting token). This class handles the routing between AbstractStrategyHolder instances based on repair status, and the AbstractStrategyHolder instances have separate compaction strategies for each directory, which it routes sstables to. Note that PendingRepairHolder also divides sstables on their pending repair id. Operations on this class are guarded by a ReentrantReadWriteLock. This lock performs mutual exclusion on reads and writes to the following variables: {@link this#repaired}, {@link this#unrepaired}, {@link this#isActive}, {@link this#params}, {@link this#currentBoundaries}. Whenever performing reads on these variables, the {@link this#readLock} should be acquired. Likewise, updates to these variables should be guarded by {@link 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 {@link this#maybeReloadDiskBoundaries()} before acquiring the read lock to acess the strategies.
    • 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

        public 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:
      • hasDataForPendingRepair

        public boolean hasDataForPendingRepair​(java.util.UUID sessionID)
      • shutdown

        public void shutdown()
      • maybeReload

        public void maybeReload​(TableMetadata metadata)
      • maybeReloadDiskBoundaries

        protected void 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 {@link 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 {@link this#readLock}, since it will potentially acquire the {@link this#writeLock} to update the compaction strategies what can cause a deadlock.
      • getUnleveledSSTables

        public int getUnleveledSSTables()
      • getLevelFanoutSize

        public int getLevelFanoutSize()
      • getSSTableCountPerLevel

        public int[] getSSTableCountPerLevel()
      • groupSSTables

        public java.util.List<AbstractStrategyHolder.GroupedSSTableContainer> groupSSTables​(java.lang.Iterable<SSTableReader> sstables)
        Split sstables into a list of grouped sstable containers, the list index an sstable lives in matches the list index of the holder that's responsible for it
      • enable

        public void enable()
      • disable

        public void disable()
      • maybeGetScanners

        public AbstractCompactionStrategy.ScannerList maybeGetScanners​(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:
      • groupSSTablesForAntiCompaction

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

        public long getMaxSSTableBytes()
      • getMaximalTasks

        public CompactionTasks getMaximalTasks​(int gcBefore,
                                               boolean splitOutput)
      • getUserDefinedTasks

        public CompactionTasks 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
      • getEstimatedRemainingTasks

        public int getEstimatedRemainingTasks()
      • shouldBeEnabled

        public boolean shouldBeEnabled()
      • getName

        public java.lang.String getName()
      • setNewLocalCompactionStrategy

        public void setNewLocalCompactionStrategy​(CompactionParams params)
      • onlyPurgeRepairedTombstones

        public boolean onlyPurgeRepairedTombstones()
      • supportsEarlyOpen

        public boolean supportsEarlyOpen()
      • mutateRepaired

        public void mutateRepaired​(java.util.Collection<SSTableReader> sstables,
                                   long repairedAt,
                                   java.util.UUID pendingRepair,
                                   boolean isTransient)
                            throws java.io.IOException
        Mutates sstable repairedAt times and notifies listeners of the change with the writeLock held. Prevents races with other processes between when the metadata is changed and when sstables are moved between strategies.
        Throws:
        java.io.IOException
      • releaseRepairData

        public CleanupSummary releaseRepairData​(java.util.Collection<java.util.UUID> sessions)