org.apache.cassandra.db.compaction
Class AbstractCompactionStrategy

java.lang.Object
  extended by org.apache.cassandra.db.compaction.AbstractCompactionStrategy
Direct Known Subclasses:
LeveledCompactionStrategy, SizeTieredCompactionStrategy

public abstract class AbstractCompactionStrategy
extends java.lang.Object

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


Field Summary
protected  ColumnFamilyStore cfs
           
protected static long DEFAULT_TOMBSTONE_COMPACTION_INTERVAL
           
protected static float DEFAULT_TOMBSTONE_THRESHOLD
           
 java.util.Map<java.lang.String,java.lang.String> options
           
protected static java.lang.String TOMBSTONE_COMPACTION_INTERVAL_OPTION
           
protected static java.lang.String TOMBSTONE_THRESHOLD_OPTION
           
protected  long tombstoneCompactionInterval
           
protected  float tombstoneThreshold
           
 
Constructor Summary
protected AbstractCompactionStrategy(ColumnFamilyStore cfs, java.util.Map<java.lang.String,java.lang.String> options)
           
 
Method Summary
static java.util.List<SSTableReader> filterSuspectSSTables(java.util.Collection<SSTableReader> originalCandidates)
          Filters SSTables that are to be blacklisted from the given collection
abstract  int getEstimatedRemainingTasks()
           
abstract  AbstractCompactionTask getMaximalTask(int gcBefore)
           
abstract  long getMaxSSTableSize()
           
abstract  AbstractCompactionTask getNextBackgroundTask(int gcBefore)
           
 java.util.List<ICompactionScanner> getScanners(java.util.Collection<SSTableReader> toCompact)
           
 java.util.List<ICompactionScanner> getScanners(java.util.Collection<SSTableReader> sstables, Range<Token> range)
          Returns a list of KeyScanners given sstables and a range on which to scan.
abstract  AbstractCompactionTask getUserDefinedTask(java.util.Collection<SSTableReader> sstables, int gcBefore)
           
 void shutdown()
          Releases any resources if this strategy is shutdown (when the CFS is reloaded after a schema change).
protected  boolean worthDroppingTombstones(SSTableReader sstable, int gcBefore)
          Check if given sstable is worth dropping tombstones at gcBefore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TOMBSTONE_THRESHOLD

protected static final float DEFAULT_TOMBSTONE_THRESHOLD
See Also:
Constant Field Values

DEFAULT_TOMBSTONE_COMPACTION_INTERVAL

protected static final long DEFAULT_TOMBSTONE_COMPACTION_INTERVAL
See Also:
Constant Field Values

TOMBSTONE_THRESHOLD_OPTION

protected static final java.lang.String TOMBSTONE_THRESHOLD_OPTION
See Also:
Constant Field Values

TOMBSTONE_COMPACTION_INTERVAL_OPTION

protected static final java.lang.String TOMBSTONE_COMPACTION_INTERVAL_OPTION
See Also:
Constant Field Values

options

public final java.util.Map<java.lang.String,java.lang.String> options

cfs

protected final ColumnFamilyStore cfs

tombstoneThreshold

protected final float tombstoneThreshold

tombstoneCompactionInterval

protected long tombstoneCompactionInterval
Constructor Detail

AbstractCompactionStrategy

protected AbstractCompactionStrategy(ColumnFamilyStore cfs,
                                     java.util.Map<java.lang.String,java.lang.String> options)
Method Detail

shutdown

public void shutdown()
Releases any resources if this strategy is shutdown (when the CFS is reloaded after a schema change). Default is to do nothing.


getNextBackgroundTask

public abstract AbstractCompactionTask getNextBackgroundTask(int gcBefore)
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 AbstractCompactionTask getMaximalTask(int gcBefore)
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.

getUserDefinedTask

public abstract AbstractCompactionTask getUserDefinedTask(java.util.Collection<SSTableReader> sstables,
                                                          int 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.)

getEstimatedRemainingTasks

public abstract int getEstimatedRemainingTasks()
Returns:
the number of background tasks estimated to still be needed for this columnfamilystore

getMaxSSTableSize

public abstract long getMaxSSTableSize()
Returns:
size in bytes of the largest sstables for this strategy

filterSuspectSSTables

public static java.util.List<SSTableReader> filterSuspectSSTables(java.util.Collection<SSTableReader> originalCandidates)
Filters SSTables that are to be blacklisted from the given collection

Parameters:
originalCandidates - The collection to check for blacklisted SSTables
Returns:
list of the SSTables with blacklisted ones filtered out

getScanners

public java.util.List<ICompactionScanner> getScanners(java.util.Collection<SSTableReader> sstables,
                                                      Range<Token> range)
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).


getScanners

public java.util.List<ICompactionScanner> getScanners(java.util.Collection<SSTableReader> toCompact)

worthDroppingTombstones

protected boolean worthDroppingTombstones(SSTableReader sstable,
                                          int gcBefore)
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 check
gcBefore - time to drop tombstones
Returns:
true if given sstable's tombstones are expected to be removed


Copyright © 2012 The Apache Software Foundation