Class AbstractCompactionStrategy
java.lang.Object
org.apache.cassandra.db.compaction.AbstractCompactionStrategy
- Direct Known Subclasses:
LeveledCompactionStrategy,SizeTieredCompactionStrategy,TimeWindowCompactionStrategy,UnifiedCompactionStrategy
Pluggable compaction strategy determines how SSTables get merged.
There are two main goals:
- perform background compaction constantly as needed; this typically makes a tradeoff between
i/o done by compaction, and merging done at read time.
- perform a full (maximum possible) compaction if requested by the user
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ColumnFamilyStoreprotected static final Stringprotected static final booleanprotected static final longprotected static final floatprotected static final booleanprotected booleanprotected booleanpause/resume/getNextBackgroundTask must synchronize.protected static final Stringprotected booleanstatic final Stringprotected static final Stringprotected static final Stringprotected longprotected floatprotected static final Stringprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCompactionStrategy(ColumnFamilyStore cfs, Map<String, String> options) -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddSSTable(SSTableReader added) Adds sstable, note that implementations must handle duplicate notifications here (added already being in the compaction strategy)voidaddSSTables(Iterable<SSTableReader> added) Adds sstables, note that implementations must handle duplicate notifications here (added already being in the compaction strategy)createSSTableMultiWriter(Descriptor descriptor, long keyCount, long repairedAt, TimeUUID pendingRepair, boolean isTransient, IntervalSet<CommitLogPosition> commitLogPositions, int sstableLevel, SerializationHeader header, Collection<Index.Group> indexGroups, LifecycleNewTracker lifecycleNewTracker) static List<SSTableReader>filterSuspectSSTables(Iterable<SSTableReader> originalCandidates) Filters SSTables that are to be excluded from the given collectiongetCompactionTask(LifecycleTransaction txn, long gcBefore, long maxSSTableBytes) abstract intabstract Collection<AbstractCompactionTask>getMaximalTask(long gcBefore, boolean splitOutput) abstract longgetName()abstract AbstractCompactionTaskgetNextBackgroundTask(long gcBefore) getScanners(Collection<SSTableReader> toCompact) getScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) Returns a list of KeyScanners given sstables and a range on which to scan.getScanners(Collection<SSTableReader> sstables, Range<Token> range) protected abstract Set<SSTableReader>Returns the sstables managed by this strategy instanceabstract AbstractCompactionTaskgetUserDefinedTask(Collection<SSTableReader> sstables, long gcBefore) groupSSTablesForAntiCompaction(Collection<SSTableReader> sstablesToGroup) Method for grouping similar SSTables together, This will be used by anti-compaction to determine which SSTables should be anitcompacted as a group.voidmetadataChanged(StatsMetadata oldMetadata, SSTableReader sstable) Called when the metadata has changed for an sstable - for example if the level changed Not called when repair status changes (which is also metadata), because this results in the sstable getting removed from the compaction strategy instance.voidpause()For internal, temporary suspension of background compactions so that we can do exceptional things like truncate or major compactionabstract voidremoveSSTable(SSTableReader sstable) Removes sstable from the strategy, implementations must be able to handle the sstable having already been removed.voidremoveSSTables(Iterable<SSTableReader> removed) Removes sstables from the strategy, implementations must be able to handle the sstables having already been removed.voidreplaceSSTables(Collection<SSTableReader> removed, Collection<SSTableReader> added) Replaces sstables in the compaction strategy Note that implementations must be able to handle duplicate notifications here (that removed are already gone and added have already been added)voidresume()For internal, temporary suspension of background compactions so that we can do exceptional things like truncate or major compactionvoidshutdown()Releases any resources if this strategy is shutdown (when the CFS is reloaded after a schema change).voidstartup()Performs any extra initialization requiredbooleanvalidateOptions(Map<String, String> options) protected booleanworthDroppingTombstones(SSTableReader sstable, long gcBefore) Check if given sstable is worth dropping tombstones at gcBefore.
-
Field Details
-
DEFAULT_TOMBSTONE_THRESHOLD
protected static final float DEFAULT_TOMBSTONE_THRESHOLD- See Also:
-
DEFAULT_TOMBSTONE_COMPACTION_INTERVAL
protected static final long DEFAULT_TOMBSTONE_COMPACTION_INTERVAL- See Also:
-
DEFAULT_UNCHECKED_TOMBSTONE_COMPACTION_OPTION
protected static final boolean DEFAULT_UNCHECKED_TOMBSTONE_COMPACTION_OPTION- See Also:
-
DEFAULT_LOG_ALL_OPTION
protected static final boolean DEFAULT_LOG_ALL_OPTION- See Also:
-
TOMBSTONE_THRESHOLD_OPTION
- See Also:
-
TOMBSTONE_COMPACTION_INTERVAL_OPTION
- See Also:
-
UNCHECKED_TOMBSTONE_COMPACTION_OPTION
- See Also:
-
LOG_ALL_OPTION
- See Also:
-
COMPACTION_ENABLED
- See Also:
-
ONLY_PURGE_REPAIRED_TOMBSTONES
- See Also:
-
options
-
cfs
-
tombstoneThreshold
protected float tombstoneThreshold -
tombstoneCompactionInterval
protected long tombstoneCompactionInterval -
uncheckedTombstoneCompaction
protected boolean uncheckedTombstoneCompaction -
disableTombstoneCompactions
protected boolean disableTombstoneCompactions -
logAll
protected boolean logAll -
isActive
protected boolean isActivepause/resume/getNextBackgroundTask must synchronize. This guarantees that after pause completes, no new tasks will be generated; or put another way, pause can't run until in-progress tasks are done being created. This allows runWithCompactionsDisabled to be confident that after pausing, once in-progress tasks abort, it's safe to proceed with truncate/cleanup/etc. See CASSANDRA-3430
-
-
Constructor Details
-
AbstractCompactionStrategy
-
-
Method Details
-
getDirectories
-
pause
public void pause()For internal, temporary suspension of background compactions so that we can do exceptional things like truncate or major compaction -
resume
public void resume()For internal, temporary suspension of background compactions so that we can do exceptional things like truncate or major compaction -
startup
public void startup()Performs any extra initialization required -
shutdown
public void shutdown()Releases any resources if this strategy is shutdown (when the CFS is reloaded after a schema change). -
getNextBackgroundTask
- 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 abstract Collection<AbstractCompactionTask> getMaximalTask(long gcBefore, boolean splitOutput) - 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 abstract AbstractCompactionTask getUserDefinedTask(Collection<SSTableReader> sstables, long gcBefore) - 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, long gcBefore, long maxSSTableBytes) -
getEstimatedRemainingTasks
public abstract int getEstimatedRemainingTasks()- Returns:
- the number of background tasks estimated to still be needed for this columnfamilystore
-
getMaxSSTableBytes
public abstract long getMaxSSTableBytes()- Returns:
- size in bytes of the largest sstables for this strategy
-
filterSuspectSSTables
Filters SSTables that are to be excluded from the given collection- Parameters:
originalCandidates- The collection to check for excluded SSTables- Returns:
- list of the SSTables with excluded ones filtered out
-
getScanners
public AbstractCompactionStrategy.ScannerList getScanners(Collection<SSTableReader> sstables, Range<Token> range) -
getScanners
public AbstractCompactionStrategy.ScannerList getScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) 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). -
getName
-
replaceSSTables
Replaces sstables in the compaction strategy Note that implementations must be able to handle duplicate notifications here (that removed are already gone and added have already been added) -
addSSTable
Adds sstable, note that implementations must handle duplicate notifications here (added already being in the compaction strategy) -
addSSTables
Adds sstables, note that implementations must handle duplicate notifications here (added already being in the compaction strategy) -
removeSSTable
Removes sstable from the strategy, implementations must be able to handle the sstable having already been removed. -
removeSSTables
Removes sstables from the strategy, implementations must be able to handle the sstables having already been removed. -
getSSTables
Returns the sstables managed by this strategy instance -
metadataChanged
Called when the metadata has changed for an sstable - for example if the level changed Not called when repair status changes (which is also metadata), because this results in the sstable getting removed from the compaction strategy instance. -
getScanners
-
worthDroppingTombstones
Check if given sstable is worth dropping tombstones at gcBefore. Check is skipped if tombstone_compaction_interval time does not elapse since sstable creation and returns false.- Parameters:
sstable- SSTable to checkgcBefore- time to drop tombstones- Returns:
- true if given sstable's tombstones are expected to be removed
-
validateOptions
public static Map<String,String> validateOptions(Map<String, String> options) throws ConfigurationException- Throws:
ConfigurationException
-
groupSSTablesForAntiCompaction
public Collection<Collection<SSTableReader>> groupSSTablesForAntiCompaction(Collection<SSTableReader> sstablesToGroup) Method for grouping similar SSTables together, This will be used by anti-compaction to determine which SSTables should be anitcompacted as a group. If a given compaction strategy creates sstables which cannot be merged due to some constraint it must override this method. -
strategyLogger
-
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) -
supportsEarlyOpen
public boolean supportsEarlyOpen()
-