Author: mduerig
Date: Tue Jun 27 09:31:04 2017
New Revision: 1800041
URL: http://svn.apache.org/viewvc?rev=1800041&view=rev
Log:
OAK-5790: Chronologically rebase checkpoints on top of each other during
compaction
Javadoc and inline comments
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/OnlineCompactor.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/OnlineCompactor.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/OnlineCompactor.java?rev=1800041&r1=1800040&r2=1800041&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/OnlineCompactor.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/OnlineCompactor.java
Tue Jun 27 09:31:04 2017
@@ -46,6 +46,14 @@ import org.apache.jackrabbit.oak.spi.sta
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Instances of this class can be used to compact a node state. I.e. to create
a clone
+ * of a given node state without value sharing except for binaries. Binaries
that are
+ * stored in a list of bulk segments will still value share the bulk segments
(but not
+ * the list records).
+ * A node can either be compacted on its own or alternatively the difference
between
+ * two nodes can be compacted on top of an already compacted node.
+ */
public class OnlineCompactor {
private static final Logger log =
LoggerFactory.getLogger(OnlineCompactor.class);
@@ -61,6 +69,13 @@ public class OnlineCompactor {
@Nonnull
private final Supplier<Boolean> cancel;
+ /**
+ * Create a new instance based on the passed arguments.
+ * @param reader segment reader used to read from the segments
+ * @param writer segment writer used to serialise to segments
+ * @param blobStore the blob store or {@code null} if none
+ * @param cancel a flag that can be used to cancel the compaction
process
+ */
public OnlineCompactor(
@Nonnull SegmentReader reader,
@Nonnull SegmentWriter writer,
@@ -72,11 +87,25 @@ public class OnlineCompactor {
this.cancel = checkNotNull(cancel);
}
+ /**
+ * Compact a given {@code state}
+ * @param state the node state to compact
+ * @return the compacted node state or {@code null} if cancelled.
+ * @throws IOException
+ */
@CheckForNull
public SegmentNodeState compact(@Nonnull NodeState state) throws
IOException {
return compact(EMPTY_NODE, state, EMPTY_NODE);
}
+ /**
+ * compact the differences between {@code after} and {@code before} on top
of {@code ont}.
+ * @param before the node state to diff against from {@code after}
+ * @param after the node state diffed against {@code before}
+ * @param onto the node state compacted onto
+ * @return the compacted node state or {@code null} if cancelled.
+ * @throws IOException
+ */
@CheckForNull
public SegmentNodeState compact(
@Nonnull NodeState before,
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1800041&r1=1800040&r2=1800041&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Tue Jun 27 09:31:04 2017
@@ -785,6 +785,17 @@ public class FileStore extends AbstractF
}
}
+ /**
+ * Compact {@code uncompacted} on top of an optional {@code base}.
+ * @param base the base state to compact onto or {@code null}
for an empty state.
+ * @param uncompacted the uncompacted state to compact
+ * @param compactor the compactor for creating the new generation
of the
+ * uncompacted state.
+ * @param writer the segment writer used by {@code compactor}
for writing to the
+ * new generation.
+ * @return compacted clone of {@code uncompacted} or null if
cancelled.
+ * @throws IOException
+ */
@CheckForNull
private SegmentNodeState compact(
@Nullable SegmentNodeState base,
@@ -792,13 +803,19 @@ public class FileStore extends AbstractF
@Nonnull OnlineCompactor compactor,
@Nonnull SegmentWriter writer)
throws IOException {
+ // Collect a chronologically ordered list of roots for the base
and the uncompacted
+ // state. This list consists of all checkpoints followed by the
root.
LinkedHashMap<String, NodeState> baseRoots = collectRoots(base);
LinkedHashMap<String, NodeState> uncompactedRoots =
collectRoots(uncompacted);
+
+ // Compact the list of uncompacted roots to a list of compacted
roots.
LinkedHashMap<String, NodeState> compactedRoots =
compact(baseRoots, uncompactedRoots, compactor);
if (compactedRoots == null) {
return null;
}
+ // Build a compacted super root by replacing the uncompacted roots
with
+ // the compacted ones in the original node.
SegmentNodeBuilder builder = uncompacted.builder();
for (Entry<String, NodeState> compactedRoot :
compactedRoots.entrySet()) {
String path = compactedRoot.getKey();
@@ -806,10 +823,16 @@ public class FileStore extends AbstractF
NodeBuilder childBuilder = getChild(builder,
getParentPath(path));
childBuilder.setChildNode(getName(path), state);
}
+
+ // Use the segment writer of the *new generation* to persist the
compacted super root.
RecordId nodeId = writer.writeNode(builder.getNodeState(),
uncompacted.getStableIdBytes());
return new SegmentNodeState(segmentReader, segmentWriter,
getBlobStore(), nodeId);
}
+ /**
+ * Compact a list of uncompacted roots on top of base roots of the
same key or
+ * an empty node if none.
+ */
@CheckForNull
private LinkedHashMap<String, NodeState> compact(
@Nonnull LinkedHashMap<String, NodeState> baseRoots,
@@ -838,6 +861,11 @@ public class FileStore extends AbstractF
return compactedRoots;
}
+ /**
+ * Collect a chronologically ordered list of roots for the base and
the uncompacted
+ * state from a {@code superRoot} . This list consists of all
checkpoints followed by
+ * the root.
+ */
@Nonnull
private LinkedHashMap<String, NodeState> collectRoots(@Nullable
SegmentNodeState superRoot) {
LinkedHashMap<String, NodeState> roots = newLinkedHashMap();