public class Compactor extends Object implements AutoCloseable
Segments in a pool of background
threads.
The compactor is responsible for managing log compaction processes. Log Compaction processes
are run in a pool of background threads of the configured number of Storage.compactionThreads().
Compaction.MINOR and Compaction.MAJOR executions are scheduled according to the configured
Storage.minorCompactionInterval() and Storage.majorCompactionInterval() respectively.
Compaction can also be run synchronously via compact() or compact(Compaction).
When a Compaction is executed either synchronously or asynchronously, the compaction's associated
CompactionManager is called to build a list of CompactionTasks to run. Compaction tasks
are run in parallel in the compaction thread pool. However, the compactor will not allow multiple compaction
executions to run in parallel. If a compaction is attempted while another compaction is already running,
it will be ignored.
| Constructor and Description |
|---|
Compactor(Storage storage,
SegmentManager segments,
ScheduledExecutorService executor) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the log compactor.
|
CompletableFuture<Void> |
compact()
Compacts the log using the default
Compaction.MINOR compaction strategy. |
CompletableFuture<Void> |
compact(Compaction compaction)
Compacts the log using the given
Compaction. |
long |
compactIndex()
Returns a the index up to which the log can be compacted.
|
Compaction.Mode |
getDefaultCompactionMode()
Returns the default compaction mode.
|
long |
majorIndex()
Returns the maximum compaction index for major compaction.
|
Compactor |
majorIndex(long index)
Sets the maximum compaction index for major compaction.
|
long |
minorIndex()
Returns the maximum compaction index for minor compaction.
|
Compactor |
minorIndex(long index)
Sets the maximum compaction index for minor compaction.
|
long |
snapshotIndex()
Returns the maximum index up to which snapshotted commands can be removed during compaction.
|
Compactor |
snapshotIndex(long index)
Sets the snapshot index to indicate commands entries that can be removed during compaction.
|
Compactor |
withDefaultCompactionMode(Compaction.Mode mode)
Sets the default compaction mode.
|
public Compactor(Storage storage, SegmentManager segments, ScheduledExecutorService executor)
public Compactor withDefaultCompactionMode(Compaction.Mode mode)
mode - The default compaction mode.NullPointerException - if the compaction mode is nullIllegalArgumentException - if the compaction mode is Compaction.Mode.DEFAULTpublic Compaction.Mode getDefaultCompactionMode()
public Compactor minorIndex(long index)
index - The maximum compaction index for minor compaction.public long minorIndex()
public Compactor majorIndex(long index)
index - The maximum compaction index for major compaction.public long majorIndex()
public Compactor snapshotIndex(long index)
index - The maximum index up to which snapshotted commands can be removed.public long snapshotIndex()
public long compactIndex()
public CompletableFuture<Void> compact()
Compaction.MINOR compaction strategy.public CompletableFuture<Void> compact(Compaction compaction)
Compaction.
The provided CompactionManager will be queried for a list of CompactionTasks to run.
Tasks will be run in parallel in a pool of background threads, and the returned CompletableFuture
will be completed once those tasks have completed.
compaction - The compaction strategy.public void close()
When the compactor is closed, existing compaction tasks will be allowed to complete, future scheduled
compactions will be cancelled, and the underlying ScheduledExecutorService will be shut down.
close in interface AutoCloseableCopyright © 2013–2016. All rights reserved.