Search in sources :

Example 1 with VersionGarbageCollector

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

the class RevisionsCommand method bootstrapVGC.

private VersionGarbageCollector bootstrapVGC(RevisionsOptions options, Closer closer) throws IOException {
    DocumentMK.Builder builder = createDocumentMKBuilder(options, closer);
    if (builder == null) {
        System.err.println("revisions mode only available for DocumentNodeStore");
        System.exit(1);
    }
    // create a VersionGCSupport while builder is read-write
    VersionGCSupport gcSupport = createVersionGCSupport(builder);
    // check for matching format version
    FormatVersion version = versionOf(gcSupport.getDocumentStore());
    if (!DocumentNodeStore.VERSION.equals(version)) {
        System.err.println("Incompatible versions. This oak-run is " + DocumentNodeStore.VERSION + ", while the store is " + version);
        System.exit(1);
    }
    // set it read-only before the DocumentNodeStore is created
    // this prevents the DocumentNodeStore from writing a new
    // clusterId to the clusterNodes and nodes collections
    builder.setReadOnlyMode();
    // create a version GC that operates on a read-only DocumentNodeStore
    // and a GC support with a writable DocumentStore
    VersionGarbageCollector gc = createVersionGC(builder.getNodeStore(), gcSupport);
    VersionGCOptions gcOptions = gc.getOptions();
    gcOptions = gcOptions.withDelayFactor(options.getDelay());
    if (options.runOnce()) {
        gcOptions = gcOptions.withMaxIterations(1);
    }
    if (options.getLimit() >= 0) {
        gcOptions = gcOptions.withCollectLimit(options.getLimit());
    }
    gc.setOptions(gcOptions);
    return gc;
}
Also used : DocumentNodeStoreHelper.createVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.createVersionGCSupport) VersionGCSupport(org.apache.jackrabbit.oak.plugins.document.VersionGCSupport) VersionGarbageCollector(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector) VersionGCOptions(org.apache.jackrabbit.oak.plugins.document.VersionGCOptions) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) FormatVersion(org.apache.jackrabbit.oak.plugins.document.FormatVersion)

Example 2 with VersionGarbageCollector

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

the class RevisionsCommand method reset.

private void reset(RevisionsOptions options, Closer closer) throws IOException {
    VersionGarbageCollector gc = bootstrapVGC(options, closer);
    System.out.println("resetting recommendations and statistics");
    gc.reset();
}
Also used : VersionGarbageCollector(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector)

Example 3 with VersionGarbageCollector

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

the class RevisionsCommand method collect.

private void collect(final RevisionsOptions options, Closer closer) throws IOException {
    VersionGarbageCollector gc = bootstrapVGC(options, closer);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    final Semaphore finished = new Semaphore(0);
    try {
        if (options.isContinuous()) {
            // collect until shutdown hook is called
            final AtomicBoolean running = new AtomicBoolean(true);
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                @Override
                public void run() {
                    System.out.println("Detected QUIT signal.");
                    System.out.println("Stopping Revision GC...");
                    running.set(false);
                    finished.acquireUninterruptibly();
                    System.out.println("Stopped Revision GC.");
                }
            }));
            while (running.get()) {
                long lastRun = System.currentTimeMillis();
                collectOnce(gc, options, executor);
                waitWhile(running, lastRun + 5000);
            }
        } else {
            collectOnce(gc, options, executor);
        }
    } finally {
        finished.release();
        executor.shutdownNow();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VersionGarbageCollector(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector) ExecutorService(java.util.concurrent.ExecutorService) Semaphore(java.util.concurrent.Semaphore)

Example 4 with VersionGarbageCollector

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

the class DataStoreTrackerGCTest method init.

public DataStoreState init(DocumentNodeStore s, int idStart) throws Exception {
    NodeBuilder a = s.getRoot().builder();
    int number = 10;
    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 = idStart; i < idStart + maxDeleted; i++) {
        int n = rand.nextInt(number);
        if (!processed.contains(idStart + n)) {
            processed.add(idStart + n);
        }
    }
    DataStoreState state = new DataStoreState();
    for (int i = idStart; i < idStart + 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 == idStart) {
            a.child("cdup").setProperty("x", b);
        }
    }
    s.merge(a, INSTANCE, EMPTY);
    a = s.getRoot().builder();
    for (int id : processed) {
        a.child("c" + id).remove();
        s.merge(a, INSTANCE, EMPTY);
    }
    // minutes
    long maxAge = 10;
    // 1. Go past GC age and check no GC done as nothing deleted
    clock.waitUntil(clock.getTime() + MINUTES.toMillis(maxAge));
    VersionGarbageCollector vGC = s.getVersionGarbageCollector();
    VersionGarbageCollector.VersionGCStats stats = vGC.gc(0, MILLISECONDS);
    return state;
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Random(java.util.Random) VersionGarbageCollector(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)

Example 5 with VersionGarbageCollector

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

the class DataStoreTrackerGCTest method addNodeSpecialChars.

private HashSet<String> addNodeSpecialChars(DocumentNodeStore ds) throws Exception {
    List<String> specialCharSets = Lists.newArrayList("q\\%22afdg\\%22", "a\nbcd", "a\n\rabcd", "012\\efg");
    HashSet<String> set = new HashSet<String>();
    NodeBuilder a = ds.getRoot().builder();
    int toBeDeleted = 0;
    for (int i = 0; i < specialCharSets.size(); i++) {
        Blob b = ds.createBlob(randomStream(i, 18432));
        NodeBuilder n = a.child("cspecial" + i);
        n.child(specialCharSets.get(i)).setProperty("x", b);
        Iterator<String> idIter = ((GarbageCollectableBlobStore) ds.getBlobStore()).resolveChunks(b.toString());
        List<String> ids = Lists.newArrayList(idIter);
        if (toBeDeleted != i) {
            set.addAll(ids);
        }
    }
    ds.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // Delete one node again
    a = ds.getRoot().builder();
    a.child("cspecial" + 0).remove();
    ds.merge(a, INSTANCE, EMPTY);
    // minutes
    long maxAge = 10;
    // 1. Go past GC age and check no GC done as nothing deleted
    clock.waitUntil(clock.getTime() + MINUTES.toMillis(maxAge));
    VersionGarbageCollector vGC = ds.getVersionGarbageCollector();
    VersionGarbageCollector.VersionGCStats stats = vGC.gc(0, MILLISECONDS);
    return set;
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) VersionGarbageCollector(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet)

Aggregations

VersionGarbageCollector (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector)6 Blob (org.apache.jackrabbit.oak.api.Blob)2 GarbageCollectableBlobStore (org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 DocumentNodeStoreHelper.createVersionGCSupport (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.createVersionGCSupport)1 FormatVersion (org.apache.jackrabbit.oak.plugins.document.FormatVersion)1 VersionGCOptions (org.apache.jackrabbit.oak.plugins.document.VersionGCOptions)1 VersionGCSupport (org.apache.jackrabbit.oak.plugins.document.VersionGCSupport)1 VersionGCInfo (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCInfo)1