Search in sources :

Example 1 with VersionGCStats

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

the class RevisionsCommand method collectOnce.

private void collectOnce(VersionGarbageCollector gc, RevisionsOptions options, ExecutorService executor) throws IOException {
    long started = System.currentTimeMillis();
    System.out.println("starting gc collect");
    Future<VersionGCStats> f = executor.submit(new Callable<VersionGCStats>() {

        @Override
        public VersionGCStats call() throws Exception {
            return gc.gc(options.getOlderThan(), SECONDS);
        }
    });
    if (options.getTimeLimit() >= 0) {
        try {
            f.get(options.getTimeLimit(), SECONDS);
        } catch (TimeoutException e) {
            // cancel the gc
            gc.cancel();
        } catch (ExecutionException e) {
            // re-throw any other exception
            throw new IOException(e.getCause());
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    try {
        VersionGCStats stats = f.get();
        long ended = System.currentTimeMillis();
        System.out.printf(Locale.US, "%21s  %s%n", "Started:", fmtTimestamp(started));
        System.out.printf(Locale.US, "%21s  %s%n", "Ended:", fmtTimestamp(ended));
        System.out.printf(Locale.US, "%21s  %s%n", "Duration:", fmtDuration(ended - started));
        System.out.printf(Locale.US, "%21s  %s%n", "Stats:", stats.toString());
    } catch (InterruptedException e) {
        throw new IOException(e);
    } catch (ExecutionException e) {
        throw new IOException(e.getCause());
    }
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with VersionGCStats

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

the class VersionGCDeletionTest method deleteLargeNumber.

@Test
public void deleteLargeNumber() throws Exception {
    int noOfDocsToDelete = 10000;
    DocumentStore ts = new MemoryDocumentStore();
    store = new DocumentMK.Builder().clock(clock).setDocumentStore(new MemoryDocumentStore()).setAsyncDelay(0).getNodeStore();
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder xb = b1.child("x");
    for (int i = 0; i < noOfDocsToDelete; i++) {
        xb.child("a" + i).child("b" + i);
    }
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // hours
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    // Remove x/y
    NodeBuilder b2 = store.getRoot().builder();
    b2.child("x").remove();
    store.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    // 3. Check that deleted doc does get collected post maxAge
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge * 2) + delta);
    VersionGarbageCollector gc = store.getVersionGarbageCollector();
    gc.setOptions(gc.getOptions().withOverflowToDiskThreshold(100));
    VersionGCStats stats = gc.gc(maxAge * 2, HOURS);
    assertEquals(noOfDocsToDelete * 2 + 1, stats.deletedDocGCCount);
    assertEquals(noOfDocsToDelete, stats.deletedLeafDocGCCount);
    assertNull(ts.find(Collection.NODES, "1:/x"));
    for (int i = 0; i < noOfDocsToDelete; i++) {
        assertNull(ts.find(Collection.NODES, "2:/a" + i + "/b" + i));
        assertNull(ts.find(Collection.NODES, "1:/a" + i));
    }
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with VersionGCStats

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

the class VersionGCDeletionTest method gcWithPathsHavingNewLine.

@Test
public void gcWithPathsHavingNewLine() throws Exception {
    int noOfDocsToDelete = 200;
    DocumentStore ts = new MemoryDocumentStore();
    store = new DocumentMK.Builder().clock(clock).setDocumentStore(new MemoryDocumentStore()).setAsyncDelay(0).getNodeStore();
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder xb = b1.child("x");
    for (int i = 0; i < noOfDocsToDelete - 1; i++) {
        xb.child("a" + i).child("b" + i);
    }
    xb.child("a-1").child("b\r");
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // hours
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    // Remove x/y
    NodeBuilder b2 = store.getRoot().builder();
    b2.child("x").remove();
    store.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    // 3. Check that deleted doc does get collected post maxAge
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge * 2) + delta);
    VersionGarbageCollector gc = store.getVersionGarbageCollector();
    gc.setOptions(gc.getOptions().withOverflowToDiskThreshold(100));
    VersionGCStats stats = gc.gc(maxAge * 2, HOURS);
    assertEquals(noOfDocsToDelete * 2 + 1, stats.deletedDocGCCount);
    assertEquals(noOfDocsToDelete, stats.deletedLeafDocGCCount);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with VersionGCStats

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

the class VersionGCDeletionTest method leaveResurrectedNodesAlone.

@Test
public void leaveResurrectedNodesAlone() throws Exception {
    TestDocumentStore ts = new TestDocumentStore();
    store = new DocumentMK.Builder().clock(clock).setDocumentStore(ts).setAsyncDelay(0).getNodeStore();
    String id = Utils.getIdFromPath("/x");
    NodeBuilder b1 = store.getRoot().builder();
    b1.child("x");
    store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // Remove x
    NodeBuilder b2 = store.getRoot().builder();
    b2.child("x").remove();
    store.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    NodeDocument d2 = ts.find(Collection.NODES, id, 0);
    assertTrue(d2.wasDeletedOnce());
    // Re-add x
    NodeBuilder b3 = store.getRoot().builder();
    b3.child("x");
    store.merge(b3, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    NodeDocument d3 = ts.find(Collection.NODES, id, 0);
    assertTrue(d3.wasDeletedOnce());
    // hours
    long maxAge = 1;
    long delta = TimeUnit.MINUTES.toMillis(10);
    // 3. Check that resurrected doc does not get collected post maxAge
    clock.waitUntil(clock.getTime() + HOURS.toMillis(maxAge * 2) + delta);
    VersionGarbageCollector gc = store.getVersionGarbageCollector();
    VersionGCStats stats = gc.gc(maxAge * 2, HOURS);
    assertEquals(1, stats.updateResurrectedGCCount);
    NodeDocument d4 = ts.find(Collection.NODES, id, 0);
    assertNotNull(d4);
    assertFalse(d4.wasDeletedOnce());
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with VersionGCStats

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

the class VersionGCQueryTest method noQueryForFirstLevelPrevDocs.

@Test
public void noQueryForFirstLevelPrevDocs() throws Exception {
    // create some garbage
    NodeBuilder builder = ns.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        InputStream s = new RandomStream(10 * 1024, 42);
        PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
        builder.child("test").child("node-" + i).setProperty(p);
    }
    merge(builder);
    // overwrite with other binaries to force document splits
    builder = ns.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        InputStream s = new RandomStream(10 * 1024, 17);
        PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
        builder.child("test").child("node-" + i).setProperty(p);
    }
    merge(builder);
    ns.runBackgroundOperations();
    builder = ns.getRoot().builder();
    builder.child("test").remove();
    merge(builder);
    ns.runBackgroundOperations();
    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(11, stats.deletedDocGCCount);
    assertEquals(10, stats.splitDocGCCount);
    assertEquals(0, prevDocIds.size());
    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)

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