use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class ExternalIndexObserver method contentChanged.
@Override
public void contentChanged(@Nonnull NodeState after, @Nonnull CommitInfo info) {
//Only interested in external changes
if (excludes(after, info)) {
return;
}
CommitContext commitContext = (CommitContext) info.getInfo().get(CommitContext.NAME);
IndexedPaths indexedPaths = (IndexedPaths) commitContext.get(LuceneDocumentHolder.NAME);
commitContext.remove(LuceneDocumentHolder.NAME);
log.trace("Received indexed paths {}", indexedPaths);
int droppedCount = 0;
int indexedCount = 0;
TimerStats.Context ctx = timer.time();
Set<String> indexPaths = Sets.newHashSet();
for (IndexedPathInfo indexData : indexedPaths) {
String path = indexData.getPath();
NodeState indexedNode = null;
for (String indexPath : indexData.getIndexPaths()) {
IndexDefinition defn = indexTracker.getIndexDefinition(indexPath);
//but not used locally
if (defn == null) {
continue;
}
//Lazily initialize indexedNode
if (indexedNode == null) {
indexedNode = NodeStateUtils.getNode(after, path);
}
if (!indexedNode.exists()) {
continue;
}
IndexDefinition.IndexingRule indexingRule = defn.getApplicableIndexingRule(indexedNode);
if (indexingRule == null) {
log.debug("No indexingRule found for path {} for index {}", path, indexPath);
continue;
}
indexPaths.add(indexPath);
try {
Document doc = new LuceneDocumentMaker(defn, indexingRule, path).makeDocument(indexedNode);
if (doc != null) {
if (indexingQueue.add(LuceneDoc.forUpdate(indexPath, path, doc))) {
indexedCount++;
} else {
droppedCount++;
}
}
} catch (Exception e) {
log.warn("Ignoring making LuceneDocument for path {} for index {} due to exception", path, indexPath, e);
}
}
}
if (droppedCount > 0) {
log.warn("Dropped [{}] docs from indexing as queue is full", droppedCount);
}
added.mark(indexedCount);
ctx.stop();
log.debug("Added {} documents for {} indexes from external changes", indexedCount, indexPaths.size());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition 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.IndexDefinition 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.IndexDefinition 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);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class DefaultIndexWriterTest method indexUpdated.
@Test
public void indexUpdated() throws Exception {
IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
DefaultIndexWriter writer = new DefaultIndexWriter(defn, builder, new DefaultDirectoryFactory(null, null), INDEX_DATA_CHILD_NAME, SUGGEST_DATA_CHILD_NAME, false);
Document document = new Document();
document.add(newPathField("/a/b"));
writer.updateDocument("/a/b", document);
assertTrue(writer.close(0));
}
Aggregations