Search in sources :

Example 1 with DefaultEditor

use of org.apache.jackrabbit.oak.spi.commit.DefaultEditor 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);
            }
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) LuceneIndexHelper.isLuceneIndexNode(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.isLuceneIndexNode) IOException(java.io.IOException) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) DefaultEditor(org.apache.jackrabbit.oak.spi.commit.DefaultEditor) CompositeEditor(org.apache.jackrabbit.oak.spi.commit.CompositeEditor) SubtreeEditor(org.apache.jackrabbit.oak.spi.commit.SubtreeEditor) SubtreeEditor(org.apache.jackrabbit.oak.spi.commit.SubtreeEditor) DefaultEditor(org.apache.jackrabbit.oak.spi.commit.DefaultEditor)

Aggregations

IOException (java.io.IOException)1 LuceneIndexHelper.isLuceneIndexNode (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.isLuceneIndexNode)1 CompositeEditor (org.apache.jackrabbit.oak.spi.commit.CompositeEditor)1 DefaultEditor (org.apache.jackrabbit.oak.spi.commit.DefaultEditor)1 Editor (org.apache.jackrabbit.oak.spi.commit.Editor)1 SubtreeEditor (org.apache.jackrabbit.oak.spi.commit.SubtreeEditor)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1