Search in sources :

Example 26 with VersionGCStats

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

the class MongoBlobGCTest method setUp.

public DataStoreState setUp(boolean deleteDirect, int count) throws Exception {
    DocumentNodeStore s = mk.getNodeStore();
    NodeBuilder a = s.getRoot().builder();
    int number = count;
    int maxDeleted = 5;
    // track the number of the assets to be deleted
    List<Integer> processed = Lists.newArrayList();
    Random rand = new Random(47);
    for (int i = 0; i < maxDeleted; i++) {
        int n = rand.nextInt(number);
        if (!processed.contains(n)) {
            processed.add(n);
        }
    }
    DataStoreState state = new DataStoreState();
    for (int i = 0; i < number; i++) {
        Blob b = s.createBlob(randomStream(i, 16516));
        Iterator<String> idIter = ((GarbageCollectableBlobStore) s.getBlobStore()).resolveChunks(b.toString());
        while (idIter.hasNext()) {
            String chunk = idIter.next();
            state.blobsAdded.add(chunk);
            if (!processed.contains(i)) {
                state.blobsPresent.add(chunk);
            }
        }
        a.child("c" + i).setProperty("x", b);
        // Add a duplicated entry
        if (i == 0) {
            a.child("cdup").setProperty("x", b);
        }
    }
    s.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    if (deleteDirect) {
        for (int id : processed) {
            deleteFromMongo("c" + id);
        }
    } else {
        a = s.getRoot().builder();
        for (int id : processed) {
            a.child("c" + id).remove();
            s.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        }
        // hours
        long maxAge = 10;
        // 1. Go past GC age and check no GC done as nothing deleted
        clock.waitUntil(clock.getTime() + TimeUnit.MINUTES.toMillis(maxAge));
        VersionGarbageCollector vGC = s.getVersionGarbageCollector();
        VersionGCStats stats = vGC.gc(0, TimeUnit.MILLISECONDS);
        Assert.assertEquals(processed.size(), stats.deletedDocGCCount);
    }
    return state;
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Random(java.util.Random) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)

Example 27 with VersionGCStats

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

the class ResurrectNodeAfterRevisionGCTest method resurrectAfterGC.

@Test
public void resurrectAfterGC() throws Exception {
    NodeBuilder builder = ns1.getRoot().builder();
    builder.child("foo").child("bar");
    builder.child("baz");
    merge(ns1, builder);
    builder = ns1.getRoot().builder();
    builder.child("foo").child("bar").setProperty("p", 0);
    merge(ns1, builder);
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    assertTrue(ns2.getRoot().getChildNode("foo").exists());
    assertTrue(ns2.getRoot().getChildNode("foo").getChildNode("bar").exists());
    assertEquals(0, ns2.getRoot().getChildNode("foo").getChildNode("bar").getLong("p"));
    builder = ns1.getRoot().builder();
    // removing both will result in a commit root on 0:/
    builder.child("foo").remove();
    builder.child("baz").remove();
    merge(ns1, builder);
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    assertFalse(ns2.getRoot().getChildNode("foo").exists());
    NodeDocument doc = ds2.find(Collection.NODES, getIdFromPath("/foo/bar"));
    assertNotNull(doc);
    NodeState state = doc.getNodeAtRevision(ns2, ns2.getHeadRevision(), null);
    assertNull(state);
    c.waitUntil(c.getTime() + TimeUnit.MINUTES.toMillis(5));
    VersionGarbageCollector gc = ns1.getVersionGarbageCollector();
    VersionGCStats stats = gc.gc(1, TimeUnit.MINUTES);
    assertEquals(3, stats.deletedDocGCCount);
    builder = ns1.getRoot().builder();
    builder.child("foo").child("bar");
    merge(ns1, builder);
    builder = ns1.getRoot().builder();
    // setting 'x' puts the commit root on /foo
    builder.child("foo").setProperty("x", 0);
    builder.child("foo").child("bar").setProperty("p", 1);
    merge(ns1, builder);
    builder = ns1.getRoot().builder();
    builder.child("foo").child("bar").setProperty("p", 2);
    merge(ns1, builder);
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    assertTrue(ns2.getRoot().getChildNode("foo").exists());
    assertTrue(ns2.getRoot().getChildNode("foo").getChildNode("bar").exists());
    assertEquals(2, ns2.getRoot().getChildNode("foo").getChildNode("bar").getLong("p"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 28 with VersionGCStats

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

the class NodeDocumentTest method getAllChangesAfterGC2.

@Test
public void getAllChangesAfterGC2() throws Exception {
    int numChanges = 200;
    DocumentNodeStore ns = createTestStore(numChanges);
    NodeDocument root = getRootDocument(ns.getDocumentStore());
    // remove oldest previous doc
    NodeDocument toRemove = Iterators.getLast(root.getAllPreviousDocs());
    int numDeleted = new SplitDocumentCleanUp(ns.getDocumentStore(), new VersionGCStats(), Collections.singleton(toRemove)).disconnect().deleteSplitDocuments();
    assertEquals(1, numDeleted);
    numChanges -= Iterables.size(toRemove.getAllChanges());
    root = getRootDocument(ns.getDocumentStore());
    Revision previous = ns.newRevision();
    for (Revision r : root.getAllChanges()) {
        assertTrue(previous.compareRevisionTime(r) > 0);
        previous = r;
    }
    // numChanges + one revision when node was created
    assertEquals(numChanges + 1, Iterables.size(root.getAllChanges()));
    ns.dispose();
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) Test(org.junit.Test)

Example 29 with VersionGCStats

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

the class VersionGCStatsTest method addRun.

@Test
public void addRun() {
    VersionGCStats cumulative = new VersionGCStats();
    cumulative.addRun(stats);
    assertEquals(stats.active.elapsed(MICROSECONDS), cumulative.activeElapsed);
    assertEquals(stats.collectDeletedDocs.elapsed(MICROSECONDS), cumulative.collectDeletedDocsElapsed);
    assertEquals(stats.checkDeletedDocs.elapsed(MICROSECONDS), cumulative.checkDeletedDocsElapsed);
    assertEquals(stats.deleteDeletedDocs.elapsed(MICROSECONDS), cumulative.deleteDeletedDocsElapsed);
    assertEquals(stats.collectAndDeleteSplitDocs.elapsed(MICROSECONDS), cumulative.collectAndDeleteSplitDocsElapsed);
    assertEquals(stats.sortDocIds.elapsed(MICROSECONDS), cumulative.sortDocIdsElapsed);
    assertEquals(stats.updateResurrectedDocuments.elapsed(MICROSECONDS), cumulative.updateResurrectedDocumentsElapsed);
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) 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