Search in sources :

Example 6 with CommitContext

use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.

the class LocalIndexObserverTest method docsAddedToQueue.

@Test
public void docsAddedToQueue() throws Exception {
    CommitInfo info = newCommitInfo();
    CommitContext cc = (CommitContext) info.getInfo().get(CommitContext.NAME);
    LuceneDocumentHolder holder = new LuceneDocumentHolder(collectingQueue, 500);
    holder.add(false, LuceneDoc.forDelete("foo", "bar"));
    cc.set(LuceneDocumentHolder.NAME, holder);
    observer.contentChanged(EMPTY_NODE, info);
    assertEquals(1, collectingQueue.getQueuedDocs().size());
    assertNull(cc.get(LuceneDocumentHolder.NAME));
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test)

Example 7 with CommitContext

use of org.apache.jackrabbit.oak.spi.commit.CommitContext 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 8 with CommitContext

use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.

the class LocalIndexObserver method contentChanged.

@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
    if (info.isExternal()) {
        return;
    }
    CommitContext commitContext = (CommitContext) info.getInfo().get(CommitContext.NAME);
    //Commit done internally i.e. one not using Root/Tree API
    if (commitContext == null) {
        return;
    }
    LuceneDocumentHolder holder = (LuceneDocumentHolder) commitContext.get(LuceneDocumentHolder.NAME);
    //Nothing to be indexed
    if (holder == null) {
        return;
    }
    commitContext.remove(LuceneDocumentHolder.NAME);
    int droppedCount = 0;
    for (LuceneDoc doc : holder.getNRTIndexedDocs()) {
        if (!docQueue.add(doc)) {
            droppedCount++;
        }
    }
    //After nrt docs add all sync indexed docs
    //Doing it *after* ensures thar nrt index might catch
    //up by the time sync one are finished
    docQueue.addAllSynchronously(holder.getSyncIndexedDocs());
    if (droppedCount > 0) {
        //TODO Ensure that log do not flood
        log.warn("Dropped [{}] docs from indexing as queue is full", droppedCount);
    }
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext)

Example 9 with CommitContext

use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.

the class DocumentNodeStore method newCommitInfo.

private static CommitInfo newCommitInfo(@Nonnull ChangeSet changeSet, JournalPropertyHandler journalPropertyHandler) {
    CommitContext commitContext = new SimpleCommitContext();
    commitContext.set(COMMIT_CONTEXT_OBSERVATION_CHANGESET, changeSet);
    journalPropertyHandler.addTo(commitContext);
    Map<String, Object> info = ImmutableMap.<String, Object>of(CommitContext.NAME, commitContext);
    return new CommitInfo(CommitInfo.OAK_UNKNOWN, CommitInfo.OAK_UNKNOWN, info, true);
}
Also used : SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext)

Example 10 with CommitContext

use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.

the class JournalPropertyHandler method readFrom.

public void readFrom(CommitInfo info) {
    CommitContext commitContext = (CommitContext) info.getInfo().get(CommitContext.NAME);
    //that it may miss out on some data collection
    if (commitContext == null) {
        for (JournalPropertyBuilder<?> builder : builders.values()) {
            builder.addProperty(null);
        }
        return;
    }
    for (Map.Entry<String, JournalPropertyBuilder<JournalProperty>> e : builders.entrySet()) {
        JournalPropertyBuilder<JournalProperty> builder = e.getValue();
        builder.addProperty(getEntry(commitContext, e.getKey()));
    }
}
Also used : JournalPropertyBuilder(org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyBuilder) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) JournalProperty(org.apache.jackrabbit.oak.plugins.document.spi.JournalProperty) Map(java.util.Map)

Aggregations

CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)13 SimpleCommitContext (org.apache.jackrabbit.oak.core.SimpleCommitContext)7 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)6 Test (org.junit.Test)6 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 ChangeSet (org.apache.jackrabbit.oak.plugins.observation.ChangeSet)4 Map (java.util.Map)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 JournalProperty (org.apache.jackrabbit.oak.plugins.document.spi.JournalProperty)1 JournalPropertyBuilder (org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyBuilder)1 CommitInfoCollector (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdateTest.CommitInfoCollector)1 ContextAwareCallback (org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback)1 IndexingContext (org.apache.jackrabbit.oak.plugins.index.IndexingContext)1 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)1 LuceneDocumentMaker (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker)1 BlobDeletionCallback (org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback)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 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)1