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);
}
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);
}
}
Aggregations