Class CompactionStrategyManager
java.lang.Object
org.apache.cassandra.db.compaction.CompactionStrategyManager
- All Implemented Interfaces:
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.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCompactionStrategyManager(ColumnFamilyStore cfs, Supplier<DiskBoundaries> boundariesSupplier, boolean partitionSSTablesByTokenRange) -
Method Summary
Modifier and TypeMethodDescriptioncreateSSTableMultiWriter(Descriptor descriptor, long keyCount, long repairedAt, TimeUUID pendingRepair, boolean isTransient, IntervalSet<CommitLogPosition> commitLogPositions, int sstableLevel, SerializationHeader header, Collection<Index.Group> indexGroups, LifecycleNewTracker lifecycleNewTracker) voiddisable()voidenable()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 togetCompactionTask(LifecycleTransaction txn, long gcBefore, long maxSSTableBytes) intintgetEstimatedRemainingTasks(int additionalSSTables, long additionalBytes, boolean isIncremental) intgetMaximalTasks(long gcBefore, boolean splitOutput, OperationType operationType) longgetName()getNextBackgroundTask(long gcBefore) Return the next background task Returns a task for the compaction strategy that needs it the most (most estimated remaining tasks)long[]getScanners(Collection<SSTableReader> sstables) getScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) int[]int[]getStrategyFolders(AbstractCompactionStrategy strategy) intgetUserDefinedTasks(Collection<SSTableReader> sstables, long gcBefore) Return a list of compaction tasks corresponding to the sstables requested.groupSSTables(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 itgroupSSTablesForAntiCompaction(Collection<SSTableReader> sstablesToGroup) voidhandleNotification(INotification notification, Object sender) booleanhasDataForPendingRepair(TimeUUID sessionID) booleanhasPendingRepairSSTable(TimeUUID sessionID, SSTableReader sstable) booleanisActive()booleanbooleanbooleanisRepaired(AbstractCompactionStrategy strategy) maybeGetScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) Create ISSTableScanners from the given sstables Delegates the call to the compaction strategies to allow LCS to create a scannerprotected voidChecks if the disk boundaries changed and reloads the compaction strategies to reflect the most up-to-date disk boundaries.voidMaybe reload the compaction strategies.voidmutateRepaired(Collection<SSTableReader> sstables, long repairedAt, TimeUUID pendingRepair, boolean isTransient) Mutates sstable repairedAt times and notifies listeners of the change with the writeLock held.booleanvoidoverrideLocalParams(CompactionParams params) voidpause()pause compaction while we cancel all ongoing compactions Separate call from enable/disable to not have to save the enabled-state externallyreleaseRepairData(Collection<TimeUUID> sessions) voidresume()booleanvoidshutdown()boolean
-
Field Details
-
compactionLogger
-
TWCS_BUCKET_COUNT_MAX
public static int TWCS_BUCKET_COUNT_MAX
-
-
Constructor Details
-
CompactionStrategyManager
-
CompactionStrategyManager
public CompactionStrategyManager(ColumnFamilyStore cfs, Supplier<DiskBoundaries> boundariesSupplier, boolean partitionSSTablesByTokenRange)
-
-
Method Details
-
getNextBackgroundTask
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
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
-
hasPendingRepairSSTable
-
shutdown
public void shutdown() -
maybeReloadParamsFromSchema
Maybe reload the compaction strategies. Called after changing configuration. -
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.
TODO: improve this to reload after receiving a notification rather than trying to reload on every operation
-
getUnleveledSSTables
public int getUnleveledSSTables() -
getLevelFanoutSize
public int getLevelFanoutSize() -
getSSTableCountPerLevel
public int[] getSSTableCountPerLevel() -
getPerLevelSizeBytes
public long[] getPerLevelSizeBytes() -
isLeveledCompaction
public boolean isLeveledCompaction() -
getSSTableCountPerTWCSBucket
public int[] getSSTableCountPerTWCSBucket() -
groupSSTables
public List<AbstractStrategyHolder.GroupedSSTableContainer> groupSSTables(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 -
handleNotification
- Specified by:
handleNotificationin interfaceINotificationConsumer
-
enable
public void enable() -
disable
public void disable() -
maybeGetScanners
public AbstractCompactionStrategy.ScannerList maybeGetScanners(Collection<SSTableReader> sstables, 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(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) -
getScanners
-
groupSSTablesForAntiCompaction
public Collection<Collection<SSTableReader>> groupSSTablesForAntiCompaction(Collection<SSTableReader> sstablesToGroup) -
getMaxSSTableBytes
public long getMaxSSTableBytes() -
getCompactionTask
public AbstractCompactionTask getCompactionTask(LifecycleTransaction txn, long gcBefore, long maxSSTableBytes) -
getMaximalTasks
public CompactionTasks getMaximalTasks(long gcBefore, boolean splitOutput, OperationType operationType) -
getUserDefinedTasks
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 compactgcBefore- gc grace period, throw away tombstones older than this- Returns:
- a list of compaction tasks corresponding to the sstables requested
-
getEstimatedRemainingTasks
public int getEstimatedRemainingTasks() -
getEstimatedRemainingTasks
public int getEstimatedRemainingTasks(int additionalSSTables, long additionalBytes, boolean isIncremental) -
shouldBeEnabled
public boolean shouldBeEnabled() -
getName
-
getStrategies
-
overrideLocalParams
-
getCompactionParams
-
onlyPurgeRepairedTombstones
public boolean onlyPurgeRepairedTombstones() -
createSSTableMultiWriter
public SSTableMultiWriter createSSTableMultiWriter(Descriptor descriptor, long keyCount, long repairedAt, TimeUUID pendingRepair, boolean isTransient, IntervalSet<CommitLogPosition> commitLogPositions, int sstableLevel, SerializationHeader header, Collection<Index.Group> indexGroups, LifecycleNewTracker lifecycleNewTracker) -
isRepaired
-
getStrategyFolders
-
supportsEarlyOpen
public boolean supportsEarlyOpen() -
mutateRepaired
public void mutateRepaired(Collection<SSTableReader> sstables, long repairedAt, TimeUUID pendingRepair, boolean isTransient) throws 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:
IOException
-
releaseRepairData
-