Search in sources :

Example 6 with ReadOnlyBuilder

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

the class OakDirectoryTest method skipSaveListingIfUnchanged.

@Test
public void skipSaveListingIfUnchanged() throws Exception {
    builder.setProperty(LuceneIndexConstants.SAVE_DIR_LISTING, true);
    Directory dir = createDir(builder, false, "/foo");
    Set<String> fileNames = newHashSet();
    for (int i = 0; i < 10; i++) {
        String fileName = "foo" + i;
        createFile(dir, fileName);
        fileNames.add(fileName);
    }
    dir.close();
    dir = createDir(new ReadOnlyBuilder(builder.getNodeState()), false, "/foo");
    Set<String> files = newHashSet(dir.listAll());
    dir.close();
    assertEquals(fileNames, files);
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 7 with ReadOnlyBuilder

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

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