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());
}
}
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));
}
}
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);
}
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());
}
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)));
}
Aggregations