use of org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory 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);
}
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory 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;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory in project jackrabbit-oak by apache.
the class LuceneIndexDumperTest method directoryDump.
@Test
public void directoryDump() throws Exception {
IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
long size = 0;
Directory dir = new OakDirectory(idx, ":data", defn, false);
createFile(dir, "foo.txt", "Test content");
size += DirectoryUtils.dirSize(dir);
Directory dir2 = new OakDirectory(idx, ":data2" + MultiplexersLucene.INDEX_DIR_SUFFIX, defn, false);
createFile(dir2, "foo.txt", "Test content");
size += DirectoryUtils.dirSize(dir2);
NodeBuilder builder = rootState.builder();
builder.setChildNode("fooIndex", idx.getNodeState());
NodeState indexState = builder.getNodeState();
File out = temporaryFolder.newFolder();
LuceneIndexDumper dumper = new LuceneIndexDumper(indexState, "/fooIndex", out);
dumper.dump();
File indexDir = dumper.getIndexDir();
assertNotNull(indexDir);
// 2 dir + 1 meta
assertEquals(3, indexDir.listFiles().length);
assertEquals(dumper.getSize(), size);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory in project jackrabbit-oak by apache.
the class IndexConsistencyCheckerTest method missingFile.
@Test
public void missingFile() throws Exception {
IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
Directory dir = new OakDirectory(idx, ":data", defn, false);
createIndex(dir, 10);
NodeBuilder builder = rootState.builder();
idx.getChildNode(":data").getChildNode("segments.gen").remove();
builder.setChildNode("fooIndex", idx.getNodeState());
NodeState indexState = builder.getNodeState();
IndexConsistencyChecker checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
Result result = checker.check(Level.FULL);
assertFalse(result.clean);
assertEquals(1, result.dirStatus.get(0).missingFiles.size());
assertNull(result.dirStatus.get(0).status);
dumpResult(result);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory in project jackrabbit-oak by apache.
the class IndexConsistencyCheckerTest method badFile.
@Test
public void badFile() throws Exception {
IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
Directory dir = new OakDirectory(idx, ":data", defn, false);
createIndex(dir, 10);
NodeBuilder builder = rootState.builder();
NodeBuilder file = idx.getChildNode(":data").getChildNode("_0.cfe");
List<Blob> blobs = Lists.newArrayList(file.getProperty("jcr:data").getValue(Type.BINARIES));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(blobs.get(0).getNewStream(), baos);
byte[] bytes = baos.toByteArray();
//Flip the 3rd bit to make it corrupt
bytes[0] = (byte) (bytes[0] ^ (1 << 3));
blobs.set(0, new ArrayBasedBlob(bytes));
file.setProperty("jcr:data", blobs, Type.BINARIES);
builder.setChildNode("fooIndex", idx.getNodeState());
NodeState indexState = builder.getNodeState();
IndexConsistencyChecker checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
Result result = checker.check(Level.FULL);
assertFalse(result.clean);
assertEquals(0, result.dirStatus.get(0).missingFiles.size());
assertFalse(result.dirStatus.get(0).status.clean);
}
Aggregations