Search in sources :

Example 1 with ReferenceCollector

use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.

the class SegmentFactory method hasExternalBlobReferences.

@Override
public boolean hasExternalBlobReferences() throws IOException {
    Builder builder = FileStore.builder(new File(dir, "segmentstore"));
    builder.withMaxFileSize(256);
    builder.withMemoryMapping(false);
    FileStore fs;
    try {
        fs = builder.buildReadOnly();
    } catch (InvalidFileStoreVersionException e) {
        throw new IOException(e);
    }
    try {
        fs.getTracker().collectBlobReferences(new ReferenceCollector() {

            @Override
            public void addReference(String reference, @Nullable String nodeId) {
                // see java.nio.file.FileVisitor
                throw new ExternalBlobFound();
            }
        });
        return false;
    } catch (ExternalBlobFound e) {
        return true;
    } finally {
        fs.close();
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.plugins.segment.file.FileStore) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException) Builder(org.apache.jackrabbit.oak.plugins.segment.file.FileStore.Builder) IOException(java.io.IOException) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) File(java.io.File)

Example 2 with ReferenceCollector

use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.

the class DataStoreCheckCommand method retrieveBlobReferences.

private static void retrieveBlobReferences(GarbageCollectableBlobStore blobStore, BlobReferenceRetriever marker, File marked) throws IOException {
    final BufferedWriter writer = Files.newWriter(marked, Charsets.UTF_8);
    final AtomicInteger count = new AtomicInteger();
    boolean threw = true;
    try {
        final Joiner delimJoiner = Joiner.on(DELIM).skipNulls();
        final GarbageCollectableBlobStore finalBlobStore = blobStore;
        System.out.println("Starting dump of blob references");
        Stopwatch watch = createStarted();
        marker.collectReferences(new ReferenceCollector() {

            @Override
            public void addReference(String blobId, String nodeId) {
                try {
                    Iterator<String> idIter = finalBlobStore.resolveChunks(blobId);
                    while (idIter.hasNext()) {
                        String id = delimJoiner.join(idIter.next(), nodeId);
                        count.getAndIncrement();
                        writeAsLine(writer, id, true);
                    }
                } catch (Exception e) {
                    throw new RuntimeException("Error in retrieving references", e);
                }
            }
        });
        writer.flush();
        sort(marked, new Comparator<String>() {

            @Override
            public int compare(String s1, String s2) {
                return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]);
            }
        });
        System.out.println(count.get() + " blob references found");
        System.out.println("Finished in " + watch.elapsed(TimeUnit.SECONDS) + " seconds");
        threw = false;
    } finally {
        close(writer, threw);
    }
}
Also used : Joiner(com.google.common.base.Joiner) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) Iterator(java.util.Iterator) FileLineDifferenceIterator(org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector)

Example 3 with ReferenceCollector

use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.

the class ExternalBlobIT method testNullBlobId.

@Test
public void testNullBlobId() throws Exception {
    FileDataStore fds = createFileDataStore();
    DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
    nodeStore = getNodeStore(dbs);
    NodeBuilder nb = nodeStore.getRoot().builder();
    NodeBuilder cb = nb.child("hello");
    cb.setProperty("blob1", createBlob(Segment.MEDIUM_LIMIT - 1));
    int noOfBlobs = 4000;
    for (int i = 0; i < noOfBlobs; i++) {
        cb.setProperty("blob" + i, createBlob(Segment.MEDIUM_LIMIT + 1));
    }
    cb.setProperty("anotherBlob2", createBlob(Segment.MEDIUM_LIMIT + 1));
    cb.setProperty("anotherBlob3", createBlob(Segment.MEDIUM_LIMIT + 1));
    nodeStore.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final List<String> refrences = Lists.newArrayList();
    store.collectBlobReferences(new ReferenceCollector() {

        @Override
        public void addReference(String reference, String nodeId) {
            assertNotNull(reference);
            refrences.add(reference);
        }
    });
    assertEquals(noOfBlobs + 2, refrences.size());
}
Also used : ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 4 with ReferenceCollector

use of org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector in project jackrabbit-oak by apache.

the class CompactionAndCleanupIT method randomAccessFileConcurrentReadAndLength.

@Test
public void randomAccessFileConcurrentReadAndLength() throws Exception {
    final FileStore fileStore = fileStoreBuilder(getFileStoreFolder()).withGCOptions(defaultGCOptions().setRetainedGenerations(2)).withMaxFileSize(1).withMemoryMapping(false).build();
    final SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    ExecutorService executorService = newFixedThreadPool(300);
    final AtomicInteger counter = new AtomicInteger();
    final ReferenceCollector dummyCollector = new ReferenceCollector() {

        @Override
        public void addReference(String reference, String nodeId) {
        // do nothing
        }
    };
    try {
        Callable<Void> concurrentWriteTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                NodeBuilder builder = nodeStore.getRoot().builder();
                builder.setProperty("blob-" + counter.getAndIncrement(), createBlob(nodeStore, 25 * 25));
                nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
                fileStore.flush();
                return null;
            }
        };
        Callable<Void> concurrentCleanupTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                fileStore.cleanup();
                return null;
            }
        };
        Callable<Void> concurrentReferenceCollector = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                fileStore.collectBlobReferences(dummyCollector);
                return null;
            }
        };
        List<Future<?>> results = newArrayList();
        for (int i = 0; i < 100; i++) {
            results.add(executorService.submit(concurrentWriteTask));
            results.add(executorService.submit(concurrentCleanupTask));
            results.add(executorService.submit(concurrentReferenceCollector));
        }
        for (Future<?> result : results) {
            assertNull(result.get());
        }
    } finally {
        new ExecutorCloser(executorService).close();
        fileStore.close();
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Callable(java.util.concurrent.Callable) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Aggregations

ReferenceCollector (org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector)4 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Test (org.junit.Test)2 Joiner (com.google.common.base.Joiner)1 Stopwatch (com.google.common.base.Stopwatch)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 Iterator (java.util.Iterator)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)1 FileLineDifferenceIterator (org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator)1 ExecutorCloser (org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser)1 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)1 FileStore (org.apache.jackrabbit.oak.plugins.segment.file.FileStore)1 Builder (org.apache.jackrabbit.oak.plugins.segment.file.FileStore.Builder)1