Partial compaction
Return the compacted node instead of a boolean from forceCompact
@@ -63,6 +63,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -848,7 +849,8 @@ public class FileStore extends AbstractFileStore {
Stopwatch forceWatch = Stopwatch.createStarted();
cycles++;
- success = forceCompact(writer, or(cancel, timeOut(forceTimeout, SECONDS)));
+ after = forceCompact(writer, or(cancel, timeOut(forceTimeout, SECONDS)));
+ success = after != null;
if (success) {
gcListener.info("TarMK GC #{}: compaction succeeded to force compact remaining commits " +
"after {} ({} ms).",
@@ -929,11 +931,11 @@ public class FileStore extends AbstractFileStore {
}
}
- private boolean forceCompact(@Nonnull final SegmentWriter writer,
+ @CheckForNull
+ private SegmentNodeState forceCompact(@Nonnull final SegmentWriter writer,
@Nonnull final Supplier<Boolean> cancel)
throws InterruptedException {
- return null != revisions.
- setHead(new Function<RecordId, RecordId>() {
+ RecordId compactedId = revisions.setHead(new Function<RecordId, RecordId>() {
@Nullable
@Override
public RecordId apply(RecordId base) {
@@ -955,6 +957,9 @@ public class FileStore extends AbstractFileStore {
}
},
timeout(gcOptions.getForceTimeout(), SECONDS));
+ return compactedId != null
+ ? segmentReader.readNode(compactedId)
+ : null;
}
synchronized void cleanup() throws IOException {
