use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.
the class LuceneIndexEditorProvider method getIndexEditor.
@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
if (TYPE_LUCENE.equals(type)) {
checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback);
IndexingContext indexingContext = ((ContextAwareCallback) callback).getIndexingContext();
BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback();
indexingContext.registerIndexCommitCallback(blobDeletionCallback);
LuceneIndexWriterFactory writerFactory = null;
IndexDefinition indexDefinition = null;
boolean asyncIndexing = true;
String indexPath = indexingContext.getIndexPath();
PropertyIndexUpdateCallback propertyUpdateCallback = null;
if (nrtIndexingEnabled() && !indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) {
// incremental indexing
if (indexingContext.isReindexing()) {
return null;
}
CommitContext commitContext = getCommitContext(indexingContext);
if (commitContext == null) {
// Logically there should not be any commit without commit context. But
// some initializer code does the commit with out it. So ignore such calls with
// warning now
// TODO Revisit use of warn level once all such cases are analyzed
log.warn("No CommitContext found for commit", new Exception());
return null;
}
// TODO Also check if index has been done once
writerFactory = new LocalIndexWriterFactory(getDocumentHolder(commitContext), indexPath);
// creating definition instance for each commit as this gets executed for each commit
if (indexTracker != null) {
indexDefinition = indexTracker.getIndexDefinition(indexPath);
if (indexDefinition != null && !indexDefinition.hasMatchingNodeTypeReg(root)) {
log.debug("Detected change in NodeType registry for index {}. Would not use " + "existing index definition", indexDefinition.getIndexPath());
indexDefinition = null;
}
}
if (indexDefinition == null) {
indexDefinition = IndexDefinition.newBuilder(root, definition.getNodeState(), indexPath).build();
}
if (indexDefinition.hasSyncPropertyDefinitions()) {
propertyUpdateCallback = new PropertyIndexUpdateCallback(indexPath, definition, root);
if (indexTracker != null) {
PropertyQuery query = new LuceneIndexPropertyQuery(indexTracker, indexPath);
propertyUpdateCallback.getUniquenessConstraintValidator().setSecondStore(query);
}
}
// Pass on a read only builder to ensure that nothing gets written
// at all to NodeStore for local indexing.
// TODO [hybrid] This would cause issue with Facets as for faceted fields
// some stuff gets written to NodeBuilder. That logic should be refactored
// to be moved to LuceneIndexWriter
definition = new ReadOnlyBuilder(definition.getNodeState());
asyncIndexing = false;
}
if (writerFactory == null) {
writerFactory = new DefaultIndexWriterFactory(mountInfoProvider, newDirectoryFactory(blobDeletionCallback), writerConfig);
}
LuceneIndexEditorContext context = new LuceneIndexEditorContext(root, definition, indexDefinition, callback, writerFactory, extractedTextCache, augmentorFactory, indexingContext, asyncIndexing);
context.setPropertyUpdateCallback(propertyUpdateCallback);
return new LuceneIndexEditor(context);
}
return null;
}
use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.
the class ExternalIndexObserver method excludes.
@Override
public boolean excludes(@Nonnull NodeState root, @Nonnull CommitInfo info) {
// Only interested in external changes
if (!info.isExternal()) {
return true;
}
CommitContext commitContext = (CommitContext) info.getInfo().get(CommitContext.NAME);
// Commit done internally i.e. one not using Root/Tree API
if (commitContext == null) {
return true;
}
IndexedPaths indexedPaths = (IndexedPaths) commitContext.get(LuceneDocumentHolder.NAME);
// Nothing to be indexed
if (indexedPaths == null) {
log.debug("IndexPaths not found. Journal support missing");
return true;
}
if (indexedPaths.isEmpty()) {
return true;
}
return false;
}
use of org.apache.jackrabbit.oak.spi.commit.CommitContext 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.spi.commit.CommitContext in project jackrabbit-oak by apache.
the class LocalIndexObserverTest method docsAddedToQueue.
@Test
public void docsAddedToQueue() throws Exception {
CommitInfo info = newCommitInfo();
CommitContext cc = (CommitContext) info.getInfo().get(CommitContext.NAME);
LuceneDocumentHolder holder = new LuceneDocumentHolder(collectingQueue, 500);
holder.add(false, LuceneDoc.forDelete("foo", "bar"));
cc.set(LuceneDocumentHolder.NAME, holder);
observer.contentChanged(EMPTY_NODE, info);
assertEquals(1, collectingQueue.getQueuedDocs().size());
assertNull(cc.get(LuceneDocumentHolder.NAME));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitContext in project jackrabbit-oak by apache.
the class ExternalChangesTest method changeSetForBranchCommit.
@Test
public void changeSetForBranchCommit() throws Exception {
final int NUM_NODES = DocumentMK.UPDATE_LIMIT / 2;
final int NUM_PROPS = 10;
Set<String> propNames = Sets.newHashSet();
NodeBuilder b1 = ns1.getRoot().builder();
for (int i = 0; i < NUM_NODES; i++) {
NodeBuilder c = b1.child("n" + i);
for (int j = 0; j < NUM_PROPS; j++) {
c.setProperty("q" + j, "value");
c.setProperty("p" + j, "value");
propNames.add("q" + j);
propNames.add("p" + j);
}
}
ns1.merge(b1, newCollectingHook(), newCommitInfo());
ns1.runBackgroundUpdateOperations();
c2.reset();
ns2.runBackgroundReadOperations();
CommitInfo ci = c2.getExternalChange();
CommitContext cc = (CommitContext) ci.getInfo().get(CommitContext.NAME);
assertNotNull(cc);
ChangeSet cs = (ChangeSet) cc.get(ChangeSet.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
assertNotNull(cs);
assertTrue(cs.getPropertyNames().containsAll(propNames));
}
Aggregations