Search in sources :

Example 1 with BlobDeletionCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.

the class ActiveDeletedBlobCollectorTest method simpleCase.

@Test
public void simpleCase() throws Exception {
    BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
    bdc.deleted("blobId", Collections.singleton("/a"));
    bdc.commitProgress(COMMIT_SUCCEDED);
    adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
    verifyBlobsDeleted("blobId");
}
Also used : BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) Test(org.junit.Test)

Example 2 with BlobDeletionCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.

the class LuceneIndexEditorProvider method getIndexEditor.

@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
    if (TYPE_LUCENE.equals(type)) {
        checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback);
        IndexingContext indexingContext = ((ContextAwareCallback) callback).getIndexingContext();
        BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback();
        indexingContext.registerIndexCommitCallback(blobDeletionCallback);
        indexWriterFactory = new DefaultIndexWriterFactory(mountInfoProvider, getDirectoryFactory(blobDeletionCallback));
        LuceneIndexWriterFactory writerFactory = indexWriterFactory;
        IndexDefinition indexDefinition = null;
        boolean asyncIndexing = true;
        if (!indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) {
            //incremental indexing
            if (indexingContext.isReindexing()) {
                return null;
            }
            CommitContext commitContext = getCommitContext(indexingContext);
            if (commitContext == null) {
                //Logically there should not be any commit without commit context. But
                //some initializer code does the commit with out it. So ignore such calls with
                //warning now
                //TODO Revisit use of warn level once all such cases are analyzed
                log.warn("No CommitContext found for commit", new Exception());
                return null;
            }
            //TODO Also check if index has been done once
            writerFactory = new LocalIndexWriterFactory(getDocumentHolder(commitContext), indexingContext.getIndexPath());
            //creating definition instance for each commit as this gets executed for each commit
            if (indexTracker != null) {
                indexDefinition = indexTracker.getIndexDefinition(indexingContext.getIndexPath());
                if (indexDefinition != null && !indexDefinition.hasMatchingNodeTypeReg(root)) {
                    log.debug("Detected change in NodeType registry for index {}. Would not use " + "existing index definition", indexDefinition.getIndexPath());
                    indexDefinition = null;
                }
            }
            //Pass on a read only builder to ensure that nothing gets written
            //at all to NodeStore for local indexing.
            //TODO [hybrid] This would cause issue with Facets as for faceted fields
            //some stuff gets written to NodeBuilder. That logic should be refactored
            //to be moved to LuceneIndexWriter
            definition = new ReadOnlyBuilder(definition.getNodeState());
            asyncIndexing = false;
        }
        LuceneIndexEditorContext context = new LuceneIndexEditorContext(root, definition, indexDefinition, callback, writerFactory, extractedTextCache, augmentorFactory, indexingContext, asyncIndexing);
        return new LuceneIndexEditor(context);
    }
    return null;
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) ContextAwareCallback(org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback) BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) IndexingContext(org.apache.jackrabbit.oak.plugins.index.IndexingContext) LocalIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)

Example 3 with BlobDeletionCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.

the class ActiveDeletedBlobCollectorTest method multiThreadedCommits.

@Test
public void multiThreadedCommits() throws Exception {
    clock = Clock.SIMPLE;
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    adbc = ActiveDeletedBlobCollectorFactory.newInstance(new File(blobCollectionRoot.getRoot(), "b"), executorService);
    int numThreads = 4;
    int numBlobsPerThread = 500;
    List<Thread> threads = new ArrayList<>(numThreads);
    final AtomicInteger threadIndex = new AtomicInteger(0);
    for (; threadIndex.get() < numThreads; threadIndex.incrementAndGet()) {
        threads.add(new Thread(new Runnable() {

            private int thisThreadNum = threadIndex.get();

            @Override
            public void run() {
                int blobCnt = 0;
                while (blobCnt < numBlobsPerThread) {
                    BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
                    for (; blobCnt < numBlobsPerThread; ) {
                        String id = "Thread" + thisThreadNum + "Blob" + blobCnt;
                        bdc.deleted(id, Collections.singleton(id));
                        blobCnt++;
                        if (Math.random() > 0.5) {
                            break;
                        }
                    }
                    bdc.commitProgress(COMMIT_SUCCEDED);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }));
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    // Push one more commit to flush out any remaining ones
    adbc.getBlobDeletionCallback().commitProgress(COMMIT_SUCCEDED);
    executorService.awaitTermination(100, TimeUnit.MILLISECONDS);
    List<String> deletedChunks = new ArrayList<>(numThreads * numBlobsPerThread * 2);
    for (int threadNum = 0; threadNum < numThreads; threadNum++) {
        for (int blobCnt = 0; blobCnt < numBlobsPerThread; blobCnt++) {
            String id = "Thread" + threadNum + "Blob" + blobCnt;
            Iterators.addAll(deletedChunks, blobStore.resolveChunks(id));
        }
    }
    adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
    assertThat(blobStore.deletedChunkIds, containsInAnyOrder(deletedChunks.toArray()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 4 with BlobDeletionCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.

the class ActiveDeletedBlobCollectorTest method blobTimestampMustBeBiggerThanFileTimestamp.

@Test
public void blobTimestampMustBeBiggerThanFileTimestamp() throws Exception {
    BlobDeletionCallback bdc1 = adbc.getBlobDeletionCallback();
    bdc1.deleted("blobId1", Collections.singleton("/a"));
    bdc1.commitProgress(COMMIT_SUCCEDED);
    BlobDeletionCallback bdc2 = adbc.getBlobDeletionCallback();
    bdc2.deleted("blobId2", Collections.singleton("/b"));
    BlobDeletionCallback bdc3 = adbc.getBlobDeletionCallback();
    bdc3.deleted("blobId3", Collections.singleton("/c"));
    bdc3.commitProgress(COMMIT_SUCCEDED);
    long time = clock.getTimeIncreasing();
    clock.waitUntil(clock.getTime() + TimeUnit.MINUTES.toMillis(1));
    bdc2.commitProgress(COMMIT_SUCCEDED);
    adbc.purgeBlobsDeleted(time, blobStore);
    //blobId2 is committed later
    verifyBlobsDeleted("blobId1", "blobId3");
}
Also used : BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) Test(org.junit.Test)

Example 5 with BlobDeletionCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.

the class ActiveDeletedBlobCollectorTest method noopDoesNothing.

@Test
public void noopDoesNothing() throws Exception {
    adbc = ActiveDeletedBlobCollectorFactory.NOOP;
    BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
    bdc.deleted("blobId", Collections.singleton("/a"));
    bdc.commitProgress(COMMIT_SUCCEDED);
    adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
    verifyBlobsDeleted();
}
Also used : BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) Test(org.junit.Test)

Aggregations

BlobDeletionCallback (org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback)7 Test (org.junit.Test)6 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 ContextAwareCallback (org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback)1 IndexingContext (org.apache.jackrabbit.oak.plugins.index.IndexingContext)1 LocalIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexWriterFactory)1 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)1 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)1 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)1 ReadOnlyBuilder (org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder)1