public final class MinorCompactionManager extends Object implements CompactionManager
Compaction.MINOR compaction process.
Minor compaction works by rewriting individual segments to remove entries that don't have to be removed sequentially
from the log. The minor compaction manager is responsible for building a list of MinorCompactionTasks
to compact segments. In the case of minor compaction, each task is responsible for compacting a single segment.
However, in order to ensure segments are not compacted without cause, this compaction manager attempts to
prioritize segments for which compaction will result in greater disk space savings.
Segments are selected for minor compaction based on several factors:
entries in the segment that have been released
Given the number of entries that have been released from the segment, a percentage of entries reclaimed by
compacting the segment is calculated. Then, the percentage of entries that have been released is multiplied
by the number of times the segment has been compacted. If the result of this calculation is greater than
the configured Storage.compactionThreshold() then the segment is selected for compaction.
The final formula is as follows:
if ((segment.releaseCount() / (double) segment.count()) * segment.descriptor().version() > storage.compactionThreshold()) {
// Compact the segment
}
public List<CompactionTask> buildTasks(Storage storage, SegmentManager segments)
CompactionManager
The collection of compaction tasks will be run in parallel in a pool of
Storage.compactionThreads() background threads. Implementations should ensure that
individual tasks can be run in parallel by operating on different segments in the log.
buildTasks in interface CompactionManagerstorage - The storage configuration.segments - The segments for which to build compaction tasks.Copyright © 2013–2016. All rights reserved.