Class Compactor
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.Compactor
-
- Direct Known Subclasses:
CheckpointCompactor,ClassicCompactor,LegacyCheckpointCompactor
public abstract class Compactor extends Object
A compactor compacts the differences between twoNodeStates (beforeandafter) on top of a thirdNodeState(onto).The compaction can be done in two ways:
- Compacting down, where the differences between
beforeandafterare compacted on top of theafterstate. This is useful, because it allows for partial compactions. I.e. compactions that are "soft-cancelled" before the full compaction process completes.During "down compaction", parts of the tree are compacted and the respective node states are substituted with their compacted counterparts. This results in an {@link #equals(Object)| equal} node state at any moment in the process, which means that if the compaction is cancelled, a valid, albeit only partially compacted state can be returned.
After a partially completed "down compaction", the segments referenced by the root record can be of different generations. However, the stable identifier of the compacted records remain unchanged.
- Compacting up, where the differences between
beforeandafterare compacted on top ofbefore. This is useful to create a newNodeStatethat contains the changes fromafterbut is based onbefore, often on an empty node-state."Up compaction" results in a fully compacted state, but it can only be "hard-canceller", i.e. either the full compaction is done, or nothing at all (
nullis returned if cancelled).Generally, "up compaction" is more thorough than "down compaction", because the entire content tree is rewritten. Furthermore, it guarantees that after compaction all reachable segments are of the same, new generation.
The compaction process can be cancelled through a
Canceller. If cancellation is requested, the compaction will either abort completely or, in case of compacting down, return a partially compacted state.
-
-
Constructor Summary
Constructors Constructor Description Compactor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract @Nullable CompactedNodeStatecompact(@NotNull NodeState before, @NotNull NodeState after, @NotNull NodeState onto, @NotNull Canceller canceller)compact the differences betweenafterandbeforeon top ofonto.@Nullable CompactedNodeStatecompactDown(@NotNull NodeState state, @NotNull Canceller hardCanceller, @NotNull Canceller softCanceller)Convenience method to runcompactDown(NodeState, NodeState, Canceller, Canceller), where thebeforestate is the empty node state.abstract @Nullable CompactedNodeStatecompactDown(@NotNull NodeState before, @NotNull NodeState after, @NotNull Canceller hardCanceller, @NotNull Canceller softCanceller)compact the differences betweenafterandbeforeon top ofafter.@Nullable CompactedNodeStatecompactUp(@NotNull NodeState state, @NotNull Canceller canceller)Convenience method to runcompactUp(NodeState, NodeState, Canceller), where thebeforestate is the empty node state.@Nullable CompactedNodeStatecompactUp(@NotNull NodeState before, @NotNull NodeState after, @NotNull Canceller canceller)compact the differences betweenafterandbeforeon top ofbefore.
-
-
-
Method Detail
-
compactDown
@Nullable public final @Nullable CompactedNodeState compactDown(@NotNull @NotNull NodeState state, @NotNull @NotNull Canceller hardCanceller, @NotNull @NotNull Canceller softCanceller) throws IOException
Convenience method to runcompactDown(NodeState, NodeState, Canceller, Canceller), where thebeforestate is the empty node state.- Parameters:
state- the (after) node state to compacthardCanceller- the trigger for hard cancellation, will abandon compaction if cancelledsoftCanceller- the trigger for soft cancellation, will return partially compacted state if cancelled- Returns:
- the fully or partially compacted node state, or
nullif hard-cancelled - Throws:
IOException- will throw exception if any errors occur during compaction
-
compactDown
@Nullable public abstract @Nullable CompactedNodeState compactDown(@NotNull @NotNull NodeState before, @NotNull @NotNull NodeState after, @NotNull @NotNull Canceller hardCanceller, @NotNull @NotNull Canceller softCanceller) throws IOException
compact the differences betweenafterandbeforeon top ofafter.- Parameters:
before- the node state to diff against fromafterafter- the node state diffed againstbeforehardCanceller- the trigger for hard cancellation, will abandon compaction if cancelledsoftCanceller- the trigger for soft cancellation, will return partially compacted state if cancelled- Returns:
- the compacted node state or
nullif hard-cancelled - Throws:
IOException- will throw exception if any errors occur during compaction
-
compactUp
@Nullable public final @Nullable CompactedNodeState compactUp(@NotNull @NotNull NodeState state, @NotNull @NotNull Canceller canceller) throws IOException
Convenience method to runcompactUp(NodeState, NodeState, Canceller), where thebeforestate is the empty node state.- Parameters:
state- the (after) node state to compactcanceller- the trigger for hard cancellation, will abandon compaction if cancelled- Returns:
- the fully compacted node state, or
nullif hard-cancelled - Throws:
IOException- will throw exception if any errors occur during compaction
-
compactUp
@Nullable public final @Nullable CompactedNodeState compactUp(@NotNull @NotNull NodeState before, @NotNull @NotNull NodeState after, @NotNull @NotNull Canceller canceller) throws IOException
compact the differences betweenafterandbeforeon top ofbefore.- Throws:
IOException
-
compact
@Nullable public abstract @Nullable CompactedNodeState compact(@NotNull @NotNull NodeState before, @NotNull @NotNull NodeState after, @NotNull @NotNull NodeState onto, @NotNull @NotNull Canceller canceller) throws IOException
compact the differences betweenafterandbeforeon top ofonto.- Parameters:
before- the node state to diff against fromafterafter- the node state diffed againstbeforeonto- the node state to compact to apply the diff tocanceller- the trigger for hard cancellation, will abandon compaction if cancelled- Returns:
- the compacted node state or
nullif hard-cancelled - Throws:
IOException- will throw exception if any errors occur during compaction
-
-