Class CompactionStrategy
- java.lang.Object
-
- org.apache.accumulo.tserver.compaction.CompactionStrategy
-
- Direct Known Subclasses:
ConfigurableCompactionStrategy
,DefaultCompactionStrategy
,EverythingCompactionStrategy
public abstract class CompactionStrategy extends Object
The interface for customizing major compactions.The tablet server has one thread to ask many tablets if they should compact. When the strategy returns true, then tablet is added to the queue of tablets waiting for a compaction thread. Once a thread is available, the
gatherInformation(MajorCompactionRequest)
method is called outside the tablets' lock. This gives the strategy the ability to read information that maybe expensive to fetch. Once the gatherInformation returns, the tablet lock is grabbed and the compactionPlan computed. This should *not* do expensive operations, especially not I/O. Note that the number of files may change between calls togatherInformation(MajorCompactionRequest)
andgetCompactionPlan(MajorCompactionRequest)
.Note: the strategy object used for the
shouldCompact(MajorCompactionRequest)
call is going to be different from the one used in the compaction thread.
-
-
Constructor Summary
Constructors Constructor Description CompactionStrategy()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
gatherInformation(MajorCompactionRequest request)
Called prior to obtaining the tablet lock, useful for examining metadata or indexes.abstract CompactionPlan
getCompactionPlan(MajorCompactionRequest request)
Get the plan for compacting a tablets files.void
init(Map<String,String> options)
The settings for the compaction strategy pulled from zookeeper.abstract boolean
shouldCompact(MajorCompactionRequest request)
Determine if this tablet is eligible for a major compaction.
-
-
-
Method Detail
-
init
public void init(Map<String,String> options)
The settings for the compaction strategy pulled from zookeeper. Thetable.compacations.major.strategy.opts
part of the setting will be removed.
-
shouldCompact
public abstract boolean shouldCompact(MajorCompactionRequest request) throws IOException
Determine if this tablet is eligible for a major compaction. It's ok if it later determines (throughgatherInformation(MajorCompactionRequest)
andgetCompactionPlan(MajorCompactionRequest)
) that it does not need to. Any state stored during shouldCompact will no longer exist whengatherInformation(MajorCompactionRequest)
andgetCompactionPlan(MajorCompactionRequest)
are called.Called while holding the tablet lock, so it should not be doing any blocking.
Since no blocking should be done in this method, then its unexpected that this method will throw IOException. However since its in the API, it can not be easily removed.
- Throws:
IOException
-
gatherInformation
public void gatherInformation(MajorCompactionRequest request) throws IOException
Called prior to obtaining the tablet lock, useful for examining metadata or indexes. State collected during this method will be available during the call thegetCompactionPlan(MajorCompactionRequest)
.- Parameters:
request
- basic details about the tablet- Throws:
IOException
-
getCompactionPlan
public abstract CompactionPlan getCompactionPlan(MajorCompactionRequest request) throws IOException
Get the plan for compacting a tablets files. Called while holding the tablet lock, so it should not be doing any blocking.Since no blocking should be done in this method, then its unexpected that this method will throw IOException. However since its in the API, it can not be easily removed.
- Parameters:
request
- basic details about the tablet- Returns:
- the plan for a major compaction, or null to cancel the compaction.
- Throws:
IOException
-
-