Search in sources :

Example 1 with ReadOnlyBuilder

use of org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder in project jackrabbit-oak by apache.

the class LuceneIndexDumper method copyContent.

private void copyContent(NodeState idx, IndexDefinition defn, File dir, String dirName, Closer closer) throws IOException {
    File idxDir = DirectoryUtils.createSubDir(dir, dirName);
    Directory sourceDir = new OakDirectory(new ReadOnlyBuilder(idx), dirName, defn, true);
    Directory targetDir = FSDirectory.open(idxDir);
    closer.register(sourceDir);
    closer.register(targetDir);
    for (String file : sourceDir.listAll()) {
        sourceDir.copy(targetDir, file, file, IOContext.DEFAULT);
        size += sourceDir.fileLength(file);
    }
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) File(java.io.File) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 2 with ReadOnlyBuilder

use of org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactory method createReader.

@CheckForNull
private LuceneIndexReader createReader(IndexDefinition definition, NodeState defnNodeState, String indexPath, String indexDataNodeName, String suggestDataNodeName) throws IOException {
    Directory directory = null;
    NodeState data = defnNodeState.getChildNode(indexDataNodeName);
    if (data.exists()) {
        directory = new OakDirectory(new ReadOnlyBuilder(defnNodeState), indexDataNodeName, definition, true);
        if (cloner != null) {
            directory = cloner.wrapForRead(indexPath, definition, directory, indexDataNodeName);
        }
    } else if (PERSISTENCE_FILE.equalsIgnoreCase(defnNodeState.getString(PERSISTENCE_NAME))) {
        String path = defnNodeState.getString(PERSISTENCE_PATH);
        if (path != null && new File(path).exists()) {
            directory = FSDirectory.open(new File(path));
        }
    }
    if (directory != null) {
        OakDirectory suggestDirectory = null;
        if (definition.isSuggestEnabled()) {
            suggestDirectory = new OakDirectory(new ReadOnlyBuilder(defnNodeState), suggestDataNodeName, definition, true);
        }
        try {
            LuceneIndexReader reader = new DefaultIndexReader(directory, suggestDirectory, definition.getAnalyzer());
            // closed in LuceneIndexReader.close()
            directory = null;
            return reader;
        } finally {
            if (directory != null) {
                directory.close();
            }
        }
    }
    return null;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) File(java.io.File) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) CheckForNull(javax.annotation.CheckForNull)

Example 3 with ReadOnlyBuilder

use of org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder 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 4 with ReadOnlyBuilder

use of org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder in project jackrabbit-oak by apache.

the class LuceneIndexInfoProvider method computeSize.

private void computeSize(NodeState idxState, LuceneIndexInfo info) throws IOException {
    IndexDefinition defn = IndexDefinition.newBuilder(nodeStore.getRoot(), idxState, info.indexPath).build();
    for (String dirName : idxState.getChildNodeNames()) {
        if (NodeStateUtils.isHidden(dirName) && MultiplexersLucene.isIndexDirName(dirName)) {
            Directory dir = new OakDirectory(new ReadOnlyBuilder(idxState), dirName, defn, true);
            try (DirectoryReader dirReader = DirectoryReader.open(dir)) {
                info.numEntries += dirReader.numDocs();
                info.size = DirectoryUtils.dirSize(dir);
            }
        }
    }
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) DirectoryReader(org.apache.lucene.index.DirectoryReader) Directory(org.apache.lucene.store.Directory)

Example 5 with ReadOnlyBuilder

use of org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder in project jackrabbit-oak by apache.

the class OakDirectoryTest method readOnlyDirectory.

@Test
public void readOnlyDirectory() throws Exception {
    Directory dir = new OakDirectory(new ReadOnlyBuilder(builder.getNodeState()), new IndexDefinition(root, builder.getNodeState(), "/foo"), true);
    assertEquals(0, dir.listAll().length);
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Aggregations

ReadOnlyBuilder (org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder)7 Directory (org.apache.lucene.store.Directory)6 File (java.io.File)3 OakDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 CheckForNull (javax.annotation.CheckForNull)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 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 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 CheckIndex (org.apache.lucene.index.CheckIndex)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1