Search in sources :

Example 1 with CopyOnReadDirectory

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

the class IndexCopier method wrapForRead.

public Directory wrapForRead(String indexPath, IndexDefinition definition, Directory remote, String dirName) throws IOException {
    Directory local = createLocalDirForIndexReader(indexPath, definition, dirName);
    checkIntegrity(indexPath, local, remote);
    return new CopyOnReadDirectory(this, remote, local, prefetchEnabled, indexPath, executor);
}
Also used : CopyOnReadDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory) IndexRootDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) CopyOnReadDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory) CopyOnWriteDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnWriteDirectory)

Example 2 with CopyOnReadDirectory

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

the class LucenePropertyIndexTest method createIndexCopier.

private IndexCopier createIndexCopier() {
    try {
        return new IndexCopier(executorService, temporaryFolder.getRoot()) {

            @Override
            public Directory wrapForRead(String indexPath, IndexDefinition definition, Directory remote, String dirName) throws IOException {
                Directory ret = super.wrapForRead(indexPath, definition, remote, dirName);
                corDir = getFSDirPath(ret);
                return ret;
            }

            @Override
            public Directory wrapForWrite(IndexDefinition definition, Directory remote, boolean reindexMode, String dirName) throws IOException {
                Directory ret = super.wrapForWrite(definition, remote, reindexMode, dirName);
                cowDir = getFSDirPath(ret);
                return ret;
            }

            private String getFSDirPath(Directory dir) {
                if (dir instanceof CopyOnReadDirectory) {
                    dir = ((CopyOnReadDirectory) dir).getLocal();
                }
                dir = unwrap(dir);
                if (dir instanceof FSDirectory) {
                    return ((FSDirectory) dir).getDirectory().getAbsolutePath();
                }
                return null;
            }

            private Directory unwrap(Directory dir) {
                if (dir instanceof FilterDirectory) {
                    return unwrap(((FilterDirectory) dir).getDelegate());
                }
                return dir;
            }
        };
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CopyOnReadDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) CopyOnReadDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) Directory(org.apache.lucene.store.Directory) FilterDirectory(org.apache.lucene.store.FilterDirectory)

Aggregations

CopyOnReadDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory)2 Directory (org.apache.lucene.store.Directory)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 FilterDirectory (org.apache.lucene.store.FilterDirectory)2 IOException (java.io.IOException)1 CopyOnWriteDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnWriteDirectory)1 IndexRootDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1