use of org.apache.jackrabbit.oak.spi.commit.SubtreeEditor in project jackrabbit-oak by apache.
the class VersionEditorProvider method getRootEditor.
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) {
if (!builder.hasChildNode(JCR_SYSTEM)) {
return null;
}
NodeBuilder system = builder.child(JCR_SYSTEM);
if (!system.hasChildNode(JCR_VERSIONSTORAGE)) {
return null;
}
NodeBuilder versionStorage = system.child(JCR_VERSIONSTORAGE);
return new VisibleEditor(new CompositeEditor(new VersionEditor(versionStorage, builder, info), new SubtreeEditor(new VersionStorageEditor(versionStorage, builder), JCR_SYSTEM, JCR_VERSIONSTORAGE)));
}
use of org.apache.jackrabbit.oak.spi.commit.SubtreeEditor in project jackrabbit-oak by apache.
the class IndexTracker method diffAndUpdate.
private synchronized void diffAndUpdate(final NodeState root) {
Map<String, IndexNode> original = indices;
final Map<String, IndexNode> updates = newHashMap();
Set<String> indexPaths = Sets.newHashSet();
indexPaths.addAll(original.keySet());
indexPaths.addAll(badIndexTracker.getIndexPaths());
List<Editor> editors = newArrayListWithCapacity(indexPaths.size());
for (final String path : indexPaths) {
editors.add(new SubtreeEditor(new DefaultEditor() {
@Override
public void leave(NodeState before, NodeState after) {
try {
long start = PERF_LOGGER.start();
IndexNode index = IndexNode.open(path, root, after, readerFactory, nrtFactory);
PERF_LOGGER.end(start, -1, "[{}] Index found to be updated. Reopening the IndexNode", path);
// index can be null
updates.put(path, index);
} catch (IOException e) {
badIndexTracker.markBadPersistedIndex(path, e);
}
}
}, Iterables.toArray(PathUtils.elements(path), String.class)));
}
EditorDiff.process(CompositeEditor.compose(editors), this.root, root);
this.root = root;
if (!updates.isEmpty()) {
indices = ImmutableMap.<String, IndexNode>builder().putAll(filterKeys(original, not(in(updates.keySet())))).putAll(filterValues(updates, notNull())).build();
badIndexTracker.markGoodIndexes(updates.keySet());
//not a high concern
for (String path : updates.keySet()) {
IndexNode index = original.get(path);
try {
if (index != null) {
index.close();
}
} catch (IOException e) {
log.error("Failed to close Lucene index at " + path, e);
}
}
}
}
Aggregations