Search in sources :

Example 6 with VersionGCStats

use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats in project jackrabbit-oak by apache.

the class VersionGCQueryTest method queryDeepPreviousDocs.

@Test
public void queryDeepPreviousDocs() throws Exception {
    // create garbage until we have intermediate previous docs
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("test");
    merge(builder);
    String id = Utils.getIdFromPath("/test");
    while (!Iterables.any(store.find(Collection.NODES, id).getPreviousRanges().values(), INTERMEDIATE)) {
        InputStream s = new RandomStream(10 * 1024, 42);
        PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
        builder = ns.getRoot().builder();
        builder.child("test").setProperty(p);
        merge(builder);
        builder = ns.getRoot().builder();
        builder.child("test").remove();
        merge(builder);
        ns.runBackgroundOperations();
    }
    int numPrevDocs = Iterators.size(store.find(Collection.NODES, id).getAllPreviousDocs());
    assertEquals(1, Iterators.size(Utils.getRootDocument(store).getAllPreviousDocs()));
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
    VersionGarbageCollector gc = new VersionGarbageCollector(ns, new VersionGCSupport(store));
    prevDocIds.clear();
    VersionGCStats stats = gc.gc(30, TimeUnit.MINUTES);
    assertEquals(1, stats.deletedDocGCCount);
    // GC also cleans up the previous doc on root
    assertEquals(numPrevDocs + 1, stats.splitDocGCCount);
    // but only does find calls for previous docs of /test
    assertEquals(numPrevDocs, prevDocIds.size());
    // at the end only the root document remains
    assertEquals(1, Iterables.size(Utils.getAllDocuments(store)));
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) InputStream(java.io.InputStream) BinaryPropertyState(org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) BinaryPropertyState(org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 7 with VersionGCStats

use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats in project jackrabbit-oak by apache.

the class VersionGarbageCollectorIT method gcPrevWithMostRecentModification.

// OAK-1793
@Test
public void gcPrevWithMostRecentModification() throws Exception {
    // hrs
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    for (int i = 0; i < NUM_REVS_THRESHOLD + 1; i++) {
        NodeBuilder builder = store.getRoot().builder();
        builder.child("foo").setProperty("prop", "v" + i);
        builder.child("bar").setProperty("prop", "v" + i);
        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    store.runBackgroundOperations();
    // perform a change to make sure the sweep rev will be newer than
    // the split revs, otherwise revision GC won't remove the split doc
    clock.waitUntil(clock.getTime() + TimeUnit.SECONDS.toMillis(NodeDocument.MODIFIED_IN_SECS_RESOLUTION * 2));
    NodeBuilder builder = store.getRoot().builder();
    builder.child("qux");
    merge(store, builder);
    store.runBackgroundOperations();
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge) + delta);
    VersionGCStats stats = gc.gc(maxAge, HOURS);
    // one split doc each on: /foo, /bar and root document
    assertEquals(3, stats.splitDocGCCount);
    assertEquals(0, stats.deletedLeafDocGCCount);
    NodeDocument doc = getDoc("/foo");
    assertNotNull(doc);
    DocumentNodeState state = doc.getNodeAtRevision(store, store.getHeadRevision(), null);
    assertNotNull(state);
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 8 with VersionGCStats

use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats in project jackrabbit-oak by apache.

the class VersionGarbageCollectorIT method cacheConsistency.

// OAK-1779
@Test
public void cacheConsistency() throws Exception {
    // hrs
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    Set<String> names = Sets.newHashSet();
    NodeBuilder b1 = store.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        String name = "test-" + i;
        b1.child(name);
        names.add(name);
    }
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    for (ChildNodeEntry entry : store.getRoot().getChildNodeEntries()) {
        entry.getNodeState();
    }
    b1 = store.getRoot().builder();
    b1.getChildNode("test-7").remove();
    names.remove("test-7");
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge) + delta);
    VersionGCStats stats = gc.gc(maxAge, HOURS);
    assertEquals(1, stats.deletedDocGCCount);
    assertEquals(1, stats.deletedLeafDocGCCount);
    Set<String> children = Sets.newHashSet();
    for (ChildNodeEntry entry : store.getRoot().getChildNodeEntries()) {
        children.add(entry.getName());
    }
    assertEquals(names, children);
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 9 with VersionGCStats

use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats in project jackrabbit-oak by apache.

the class VersionGarbageCollectorIT method gcIntermediateDocs.

// OAK-1729
@Test
public void gcIntermediateDocs() throws Exception {
    // hrs
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    NodeBuilder b1 = store.getRoot().builder();
    // adding the test node will cause the commit root to be placed
    // on the root document, because the children flag is set on the
    // root document
    b1.child("test");
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue(getDoc("/test").getLocalRevisions().isEmpty());
    // setting the test property afterwards will use the new test document
    // as the commit root. this what we want for the test.
    b1 = store.getRoot().builder();
    b1.child("test").setProperty("test", "value");
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue(!getDoc("/test").getLocalRevisions().isEmpty());
    for (int i = 0; i < PREV_SPLIT_FACTOR; i++) {
        for (int j = 0; j < NUM_REVS_THRESHOLD; j++) {
            b1 = store.getRoot().builder();
            b1.child("test").setProperty("prop", i * NUM_REVS_THRESHOLD + j);
            store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        }
        store.runBackgroundOperations();
    }
    // trigger another split, now that we have 10 previous docs
    // this will create an intermediate previous doc
    store.addSplitCandidate(Utils.getIdFromPath("/test"));
    store.runBackgroundOperations();
    Map<Revision, Range> prevRanges = getDoc("/test").getPreviousRanges();
    boolean hasIntermediateDoc = false;
    for (Map.Entry<Revision, Range> entry : prevRanges.entrySet()) {
        if (entry.getValue().getHeight() > 0) {
            hasIntermediateDoc = true;
            break;
        }
    }
    assertTrue("Test data does not have intermediate previous docs", hasIntermediateDoc);
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge) + delta);
    VersionGCStats stats = gc.gc(maxAge, HOURS);
    assertEquals(10, stats.splitDocGCCount);
    assertEquals(0, stats.deletedLeafDocGCCount);
    DocumentNodeState test = getDoc("/test").getNodeAtRevision(store, store.getHeadRevision(), null);
    assertNotNull(test);
    assertTrue(test.hasProperty("test"));
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Map(java.util.Map) Test(org.junit.Test)

Example 10 with VersionGCStats

use of org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats in project jackrabbit-oak by apache.

the class VersionGarbageCollectorIT method cancelGCBeforeFirstPhase.

@Test
public void cancelGCBeforeFirstPhase() throws Exception {
    createTestNode("foo");
    NodeBuilder builder = store.getRoot().builder();
    builder.child("foo").child("bar");
    merge(store, builder);
    builder = store.getRoot().builder();
    builder.child("foo").remove();
    merge(store, builder);
    store.runBackgroundOperations();
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
    final AtomicReference<VersionGarbageCollector> gcRef = Atomics.newReference();
    VersionGCSupport gcSupport = new VersionGCSupport(store.getDocumentStore()) {

        @Override
        public Iterable<NodeDocument> getPossiblyDeletedDocs(long fromModified, long toModified) {
            // cancel as soon as it runs
            gcRef.get().cancel();
            return super.getPossiblyDeletedDocs(fromModified, toModified);
        }
    };
    gcRef.set(new VersionGarbageCollector(store, gcSupport));
    VersionGCStats stats = gcRef.get().gc(30, TimeUnit.MINUTES);
    assertTrue(stats.canceled);
    assertEquals(0, stats.deletedDocGCCount);
    assertEquals(0, stats.deletedLeafDocGCCount);
    assertEquals(0, stats.intermediateSplitDocGCCount);
    assertEquals(0, stats.splitDocGCCount);
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)29 Test (org.junit.Test)26 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)20 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)4 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 BinaryPropertyState (org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2 AbstractIterator (com.google.common.collect.AbstractIterator)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 Semaphore (java.util.concurrent.Semaphore)1 TimeoutException (java.util.concurrent.TimeoutException)1