@Test public void testCompact() throws Exception { addTestContent("cp1", nodeStore, 42); String cp1 = nodeStore.checkpoint(DAYS.toMillis(1)); addTestContent("cp2", nodeStore, 42); String cp2 = nodeStore.checkpoint(DAYS.toMillis(1)); SegmentNodeState uncompacted1 = fileStore.getHead(); SegmentNodeState compacted1 = compactor.compact(EMPTY_NODE, uncompacted1, EMPTY_NODE, Canceller.newCanceller()); assertNotNull(compacted1); assertFalse(uncompacted1 == compacted1); checkGeneration(compacted1, compactedGeneration); assertSameStableId(uncompacted1, compacted1); assertSameStableId(getCheckpoint(uncompacted1, cp1), getCheckpoint(compacted1, cp1)); assertSameStableId(getCheckpoint(uncompacted1, cp2), getCheckpoint(compacted1, cp2)); assertSameRecord(getCheckpoint(compacted1, cp2), compacted1.getChildNode("root")); addTestContent("cp3", nodeStore, 42); String cp3 = nodeStore.checkpoint(DAYS.toMillis(1)); addTestContent("cp4", nodeStore, 42); String cp4 = nodeStore.checkpoint(DAYS.toMillis(1)); SegmentNodeState uncompacted2 = fileStore.getHead(); SegmentNodeState compacted2 = compactor.compact(uncompacted1, uncompacted2, compacted1, Canceller.newCanceller()); assertNotNull(compacted2); assertFalse(uncompacted2 == compacted2); checkGeneration(compacted2, compactedGeneration); assertTrue(fileStore.getRevisions().setHead(uncompacted2.getRecordId(), compacted2.getRecordId())); assertEquals(uncompacted2, compacted2); assertSameStableId(uncompacted2, compacted2); assertSameStableId(getCheckpoint(uncompacted2, cp1), getCheckpoint(compacted2, cp1)); assertSameStableId(getCheckpoint(uncompacted2, cp2), getCheckpoint(compacted2, cp2)); assertSameStableId(getCheckpoint(uncompacted2, cp3), getCheckpoint(compacted2, cp3)); assertSameStableId(getCheckpoint(uncompacted2, cp4), getCheckpoint(compacted2, cp4)); assertSameRecord(getCheckpoint(compacted1, cp1), getCheckpoint(compacted2, cp1)); assertSameRecord(getCheckpoint(compacted1, cp2), getCheckpoint(compacted2, cp2)); assertSameRecord(getCheckpoint(compacted2, cp4), compacted2.getChildNode("root")); }
@Override @Nullable public SegmentNodeState compact( @NotNull NodeState base, @NotNull NodeState uncompacted, @NotNull NodeState onto, Canceller canceller ) throws IOException { LinkedHashMap<String, NodeState> uncompactedRoots = collectRoots(uncompacted); LinkedHashMap<String, NodeState> compactedRoots = compact( getRoot(base), uncompactedRoots, getRoot(onto), canceller ); if (compactedRoots == null) { return null; } NodeBuilder builder = uncompacted.builder(); for (Entry<String, NodeState> compactedRoot : compactedRoots.entrySet()) { String path = compactedRoot.getKey(); NodeState state = compactedRoot.getValue(); NodeBuilder childBuilder = getChild(builder, getParentPath(path)); childBuilder.setChildNode(getName(path), state); } return nodeWriter.writeNode(builder.getNodeState(), getStableIdBytes(uncompacted)); }
CheckpointCompactor implements Compactor { @Override @Nullable public SegmentNodeState compact( @NotNull NodeState base, @NotNull NodeState uncompacted, @NotNull NodeState onto, Canceller canceller ) throws IOException { LinkedHashMap<String, NodeState> uncompactedRoots = collectRoots(uncompacted); LinkedHashMap<String, NodeState> compactedRoots = compact( getRoot(base), uncompactedRoots, getRoot(onto), canceller ); if (compactedRoots == null) { return null; } NodeBuilder builder = uncompacted.builder(); for (Entry<String, NodeState> compactedRoot : compactedRoots.entrySet()) { String path = compactedRoot.getKey(); NodeState state = compactedRoot.getValue(); NodeBuilder childBuilder = getChild(builder, getParentPath(path)); childBuilder.setChildNode(getName(path), state); } return nodeWriter.writeNode(builder.getNodeState(), getStableIdBytes(uncompacted)); } }
CheckpointCompactor implements Compactor { @Override @Nullable public SegmentNodeState compact( @NotNull NodeState base, @NotNull NodeState uncompacted, @NotNull NodeState onto, Canceller canceller ) throws IOException { LinkedHashMap<String, NodeState> uncompactedRoots = collectRoots(uncompacted); LinkedHashMap<String, NodeState> compactedRoots = compact( getRoot(base), uncompactedRoots, getRoot(onto), canceller ); if (compactedRoots == null) { return null; } NodeBuilder builder = uncompacted.builder(); for (Entry<String, NodeState> compactedRoot : compactedRoots.entrySet()) { String path = compactedRoot.getKey(); NodeState state = compactedRoot.getValue(); NodeBuilder childBuilder = getChild(builder, getParentPath(path)); childBuilder.setChildNode(getName(path), state); } return nodeWriter.writeNode(builder.getNodeState(), getStableIdBytes(uncompacted)); } CheckpointCompactor(
            @NotNull GCMonitor gcListener,
            @NotNull SegmentReader reader,
            @NotNull SegmentWriter writer,
            @Nullable BlobStore blobStore,
            @NotNull GCNodeWriteMonitor compactionMonitor); }
CheckpointCompactor implements Compactor { @Override @Nullable public SegmentNodeState compact( @NotNull NodeState base, @NotNull NodeState uncompacted, @NotNull NodeState onto, Canceller canceller ) throws IOException { LinkedHashMap<String, NodeState> uncompactedRoots = collectRoots(uncompacted); LinkedHashMap<String, NodeState> compactedRoots = compact( getRoot(base), uncompactedRoots, getRoot(onto), canceller ); if (compactedRoots == null) { return null; } NodeBuilder builder = uncompacted.builder(); for (Entry<String, NodeState> compactedRoot : compactedRoots.entrySet()) { String path = compactedRoot.getKey(); NodeState state = compactedRoot.getValue(); NodeBuilder childBuilder = getChild(builder, getParentPath(path)); childBuilder.setChildNode(getName(path), state); } return nodeWriter.writeNode(builder.getNodeState(), getStableIdBytes(uncompacted)); } CheckpointCompactor(
            @NotNull GCMonitor gcListener,
            @NotNull SegmentReader reader,
            @NotNull SegmentWriter writer,
            @Nullable BlobStore blobStore,
            @NotNull GCNodeWriteMonitor compactionMonitor); @Override @Nullable SegmentNodeState compact(
        @NotNull NodeState base,
        @NotNull NodeState uncompacted,
        @NotNull NodeState onto,
        Canceller canceller
    ); }
CheckpointCompactor implements Compactor { @Override @Nullable public SegmentNodeState compact( @NotNull NodeState base, @NotNull NodeState uncompacted, @NotNull NodeState onto, Canceller canceller ) throws IOException { LinkedHashMap<String, NodeState> uncompactedRoots = collectRoots(uncompacted); LinkedHashMap<String, NodeState> compactedRoots = compact( getRoot(base), uncompactedRoots, getRoot(onto), canceller ); if (compactedRoots == null) { return null; } NodeBuilder builder = uncompacted.builder(); for (Entry<String, NodeState> compactedRoot : compactedRoots.entrySet()) { String path = compactedRoot.getKey(); NodeState state = compactedRoot.getValue(); NodeBuilder childBuilder = getChild(builder, getParentPath(path)); childBuilder.setChildNode(getName(path), state); } return nodeWriter.writeNode(builder.getNodeState(), getStableIdBytes(uncompacted)); } CheckpointCompactor(
            @NotNull GCMonitor gcListener,
            @NotNull SegmentReader reader,
            @NotNull SegmentWriter writer,
            @Nullable BlobStore blobStore,
            @NotNull GCNodeWriteMonitor compactionMonitor); @Override @Nullable SegmentNodeState compact(
        @NotNull NodeState base,
        @NotNull NodeState uncompacted,
        @NotNull NodeState onto,
        Canceller canceller
    );  }