Search in sources :

Example 6 with OakDirectory

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

the class MultiplexingIndexWriterTest method numDocs.

private int numDocs(Mount m) throws IOException {
    String indexDirName = indexDirName(m);
    Directory d = new OakDirectory(builder, indexDirName, defn, true);
    IndexReader r = DirectoryReader.open(d);
    return r.numDocs();
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory)

Example 7 with OakDirectory

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

the class IndexConsistencyCheckerTest method validIndexTest.

@Test
public void validIndexTest() throws Exception {
    IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
    Directory dir = new OakDirectory(idx, ":data", defn, false);
    createIndex(dir, 10);
    dir = new OakDirectory(idx, ":data2" + MultiplexersLucene.INDEX_DIR_SUFFIX, defn, false);
    createIndex(dir, 10);
    NodeBuilder builder = rootState.builder();
    builder.setChildNode("fooIndex", idx.getNodeState());
    NodeState indexState = builder.getNodeState();
    IndexConsistencyChecker checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
    Result result = checker.check(Level.BLOBS_ONLY);
    assertTrue(result.clean);
    checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
    result = checker.check(Level.FULL);
    assertTrue(result.clean);
    assertEquals(2, result.dirStatus.size());
    dumpResult(result);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory) Result(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result) Test(org.junit.Test)

Example 8 with OakDirectory

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

the class IndexConsistencyChecker method checkIndexDirectory.

private void checkIndexDirectory(DirectoryStatus dirStatus, NodeState idx, IndexDefinition defn, File workDir, String dirName, Closer closer) throws IOException {
    File idxDir = createWorkDir(workDir, dirName);
    Directory sourceDir = new OakDirectory(new ReadOnlyBuilder(idx), dirName, defn, true);
    Directory targetDir = FSDirectory.open(idxDir);
    closer.register(sourceDir);
    closer.register(targetDir);
    boolean clean = true;
    for (String file : sourceDir.listAll()) {
        log.debug("[{}][{}] Checking {}", indexPath, dirName, file);
        try {
            sourceDir.copy(targetDir, file, file, IOContext.DEFAULT);
        } catch (FileNotFoundException ignore) {
            dirStatus.missingFiles.add(file);
            clean = false;
            log.warn("[{}][{}] File {} missing", indexPath, dirName, file);
        }
        if (targetDir.fileLength(file) != sourceDir.fileLength(file)) {
            FileSizeStatus fileStatus = new FileSizeStatus(file, targetDir.fileLength(file), sourceDir.fileLength(file));
            dirStatus.filesWithSizeMismatch.add(fileStatus);
            clean = false;
            log.warn("[{}][{}] File size mismatch {}", indexPath, dirName, fileStatus);
        } else {
            dirStatus.size += sourceDir.fileLength(file);
            log.debug("[{}][{}] File {} is consistent", indexPath, dirName, file);
        }
    }
    if (clean) {
        log.debug("[{}][{}] Directory content found to be consistent. Proceeding to IndexCheck", indexPath, dirName);
        CheckIndex ci = new CheckIndex(targetDir);
        if (printStream != null) {
            ci.setInfoStream(printStream, verbose);
        } else if (log.isDebugEnabled()) {
            ci.setInfoStream(new LoggingPrintStream(log), log.isTraceEnabled());
        }
        dirStatus.status = ci.checkIndex();
        dirStatus.clean = dirStatus.status.clean;
        log.debug("[{}][{}] IndexCheck was successful. Proceeding to open DirectoryReader", indexPath, dirName);
    }
    if (dirStatus.clean) {
        DirectoryReader dirReader = DirectoryReader.open(targetDir);
        dirStatus.numDocs = dirReader.numDocs();
        log.debug("[{}][{}] DirectoryReader can be opened", indexPath, dirName);
        closer.register(dirReader);
    }
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) DirectoryReader(org.apache.lucene.index.DirectoryReader) FileNotFoundException(java.io.FileNotFoundException) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) File(java.io.File) CheckIndex(org.apache.lucene.index.CheckIndex) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 9 with OakDirectory

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

the class BufferedOakDirectory method reopenBuffered.

private void reopenBuffered() {
    // squeeze out child nodes marked as non existing
    // those are files that were created and later deleted again
    bufferedBuilder = squeeze(bufferedBuilder.getNodeState()).builder();
    buffered = new OakDirectory(bufferedBuilder, dataNodeName, definition, false, blobFactory, blobDeletionCallback);
}
Also used : OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory)

Aggregations

OakDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory)9 Directory (org.apache.lucene.store.Directory)8 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 File (java.io.File)4 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)4 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 Test (org.junit.Test)4 Result (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result)3 ReadOnlyBuilder (org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 CheckForNull (javax.annotation.CheckForNull)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)1 CheckIndex (org.apache.lucene.index.CheckIndex)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexReader (org.apache.lucene.index.IndexReader)1