public void compact() {
long start = System.nanoTime();
log.info("TarMK compaction started");
SegmentWriter writer = new SegmentWriter(this, tracker);
Compactor compactor = new Compactor(writer);
SegmentNodeState before = getHead();
SegmentNodeState after = compactor.compact(EMPTY_NODE, before);
writer.flush();
while (!setHead(before, after)) {
// Some other concurrent changes have been made.
// Rebase (and compact) those changes on top of the
// compacted state before retrying to set the head.
SegmentNodeState head = getHead();
after = compactor.compact(before, head);
before = head;
writer.flush();
}
tracker.setCompactionMap(compactor.getCompactionMap());
// Drop the SegmentWriter caches and flush any existing state
// in an attempt to prevent new references to old pre-compacted