You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/05/24 11:09:16 UTC
svn commit: r1796041 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/
main/java/org/apache/jackrabbit/oak/plugins/index/progress/
test/java/org/apache/jackrabbit/oak/plugins/index/progress/
Author: chetanm
Date: Wed May 24 11:09:15 2017
New Revision: 1796041
URL: http://svn.apache.org/viewvc?rev=1796041&view=rev
Log:
OAK-5893 - Async index abort should work even during traversals without index updates
Refactored the progress tracking to a separate class IndexingProgressReporter
It uses new ProgressTrackingEditor to get notified for traversal and that
is passed back to underlying callback such that even in case of traversal
abort call can be detected early when traversal is happening in subtree which
is not having index updates
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java (with props)
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java (with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/NodeTraversalCallback.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1796041&r1=1796040&r2=1796041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java Wed May 24 11:09:15 2017
@@ -36,8 +36,6 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.spi.commit.EditorDiff.process;
import static org.apache.jackrabbit.oak.spi.commit.VisibleEditor.wrap;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,20 +44,16 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
-import com.google.common.base.Stopwatch;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback.PathSource;
+import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.commit.ProgressNotificationEditor;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -165,12 +159,13 @@ public class IndexUpdate implements Edit
if (!reindex.isEmpty()) {
log.info("Reindexing will be performed for following indexes: {}",
reindex.keySet());
- rootState.reindexedIndexes.addAll(reindex.keySet());
}
+ rootState.progressReporter.reindexingTraversalStart();
// no-op when reindex is empty
CommitFailedException exception = process(
- wrap(wrapProgress(compose(reindex.values()), "Reindexing")), MISSING_NODE, after);
+ wrap(wrapProgress(compose(reindex.values()))), MISSING_NODE, after);
+ rootState.progressReporter.reindexingTraversalEnd();
if (exception != null) {
throw exception;
}
@@ -185,11 +180,11 @@ public class IndexUpdate implements Edit
}
public List<String> getReindexStats(){
- return rootState.getReindexStats();
+ return rootState.progressReporter.getReindexStats();
}
public Set<String> getUpdatedIndexPaths(){
- return rootState.getUpdatedIndexPaths();
+ return rootState.progressReporter.getUpdatedIndexPaths();
}
public String getIndexingStats(){
@@ -241,7 +236,7 @@ public class IndexUpdate implements Edit
}
Editor editor = rootState.provider.getIndexEditor(type, definition, rootState.root,
- rootState.newCallback(indexPath, shouldReindex));
+ rootState.newCallback(indexPath, shouldReindex, getEstimatedCount(definition)));
if (editor == null) {
rootState.missingProvider.onMissingIndex(type, definition, indexPath);
} else if (shouldReindex) {
@@ -271,6 +266,11 @@ public class IndexUpdate implements Edit
}
}
+ private long getEstimatedCount(NodeBuilder indexDefinition) {
+ //TODO Implement the estimate
+ return -1;
+ }
+
static boolean isIncluded(String asyncRef, NodeBuilder definition) {
if (definition.hasProperty(ASYNC_PROPERTY_NAME)) {
PropertyState p = definition.getProperty(ASYNC_PROPERTY_NAME);
@@ -334,12 +334,7 @@ public class IndexUpdate implements Edit
}
if (parent == null){
- if (rootState.isReindexingPerformed()){
- log.info(rootState.getReport());
- log.info("Reindexing completed");
- } else if (log.isDebugEnabled() && rootState.somethingIndexed()){
- log.debug(rootState.getReport());
- }
+ rootState.progressReporter.logReport();
}
}
@@ -413,7 +408,7 @@ public class IndexUpdate implements Edit
}
protected Set<String> getReindexedDefinitions() {
- return reindex.keySet();
+ return rootState.progressReporter.getReindexedIndexPaths();
}
private void clearCorruptFlag(NodeBuilder definition, String indexPath) {
@@ -433,8 +428,8 @@ public class IndexUpdate implements Edit
return path + "/" + INDEX_DEFINITIONS_NAME + "/" + indexName;
}
- private static Editor wrapProgress(Editor editor, String message){
- return ProgressNotificationEditor.wrap(editor, log, message);
+ private Editor wrapProgress(Editor editor){
+ return rootState.progressReporter.wrapProgress(editor);
}
public static class MissingIndexProviderStrategy {
@@ -496,14 +491,8 @@ public class IndexUpdate implements Edit
final NodeState root;
final CommitInfo commitInfo;
private boolean ignoreReindexFlags = IGNORE_REINDEX_FLAGS;
- /**
- * Callback for the update events of the indexing job
- */
- final IndexUpdateCallback updateCallback;
- final NodeTraversalCallback traversalCallback;
- final Set<String> reindexedIndexes = Sets.newHashSet();
- final Map<String, CountingCallback> callbacks = Maps.newHashMap();
final CorruptIndexHandler corruptIndexHandler;
+ final IndexingProgressReporter progressReporter;
private int changedNodeCount;
private int changedPropertyCount;
private MissingIndexProviderStrategy missingProvider = new MissingIndexProviderStrategy();
@@ -514,71 +503,23 @@ public class IndexUpdate implements Edit
this.provider = checkNotNull(provider);
this.async = async;
this.root = checkNotNull(root);
- this.updateCallback = checkNotNull(updateCallback);
this.commitInfo = commitInfo;
this.corruptIndexHandler = corruptIndexHandler;
- this.traversalCallback = traversalCallback;
- }
-
- public IndexUpdateCallback newCallback(String indexPath, boolean reindex) {
- CountingCallback cb = new CountingCallback(indexPath, reindex);
- callbacks.put(cb.indexPath, cb);
- return cb;
+ this.progressReporter = new IndexingProgressReporter(updateCallback, traversalCallback);
}
- public String getReport() {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.println("Indexing report");
- for (CountingCallback cb : callbacks.values()) {
- if (!log.isDebugEnabled() && !cb.reindex) {
- continue;
- }
- if (cb.count > 0) {
- pw.printf(" - %s%n", cb);
- }
- }
- return sw.toString();
- }
-
- public List<String> getReindexStats(){
- List<String> stats = Lists.newArrayList();
- for (CountingCallback cb : callbacks.values()){
- if (cb.reindex) {
- stats.add(cb.toString());
- }
- }
- return stats;
- }
-
- public Set<String> getUpdatedIndexPaths(){
- Set<String> indexPaths = Sets.newHashSet();
- for (CountingCallback cb : callbacks.values()) {
- indexPaths.add(cb.getIndexPath());
- }
- return indexPaths;
- }
-
- public boolean somethingIndexed() {
- for (CountingCallback cb : callbacks.values()) {
- if (cb.count > 0){
- return true;
- }
- }
- return false;
+ public IndexUpdateCallback newCallback(String indexPath, boolean reindex, long estimatedCount) {
+ progressReporter.registerIndex(indexPath, reindex, estimatedCount);
+ return new ReportingCallback(indexPath, reindex);
}
public boolean isAsync(){
return async != null;
}
- public boolean isReindexingPerformed(){
- return !reindexedIndexes.isEmpty();
- }
-
public void nodeRead(PathSource pathSource) throws CommitFailedException {
changedNodeCount++;
- traversalCallback.traversedNode(pathSource);
+ progressReporter.traversedNode(pathSource);
}
public void propertyChanged(String name){
@@ -598,31 +539,18 @@ public class IndexUpdate implements Edit
this.ignoreReindexFlags = ignoreReindexFlags;
}
- private class CountingCallback implements ContextAwareCallback, IndexingContext {
+ private class ReportingCallback implements ContextAwareCallback, IndexingContext {
final String indexPath;
final boolean reindex;
- final Stopwatch watch = Stopwatch.createStarted();
- int count;
- public CountingCallback(String indexPath, boolean reindex) {
+ public ReportingCallback(String indexPath, boolean reindex) {
this.indexPath = indexPath;
this.reindex = reindex;
}
@Override
public void indexUpdate() throws CommitFailedException {
- count++;
- if (count % 10000 == 0){
- log.info("{} => Indexed {} nodes in {} ...", indexPath, count, watch);
- watch.reset().start();
- }
- updateCallback.indexUpdate();
- }
-
- @Override
- public String toString() {
- String reindexMarker = reindex ? "*" : "";
- return indexPath + reindexMarker + "(" + count + ")";
+ progressReporter.indexUpdate(indexPath);
}
//~------------------------------< ContextAwareCallback >
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java?rev=1796041&r1=1796040&r2=1796041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateCallback.java Wed May 24 11:09:15 2017
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
import org.apache.jackrabbit.oak.api.CommitFailedException;
public interface IndexUpdateCallback {
+ IndexUpdateCallback NOOP = () -> {};
/**
* Invoked by the {@link org.apache.jackrabbit.oak.plugins.index.IndexEditor} for every NodeState
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/NodeTraversalCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/NodeTraversalCallback.java?rev=1796041&r1=1796040&r2=1796041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/NodeTraversalCallback.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/NodeTraversalCallback.java Wed May 24 11:09:15 2017
@@ -34,12 +34,7 @@ public interface NodeTraversalCallback{
String getPath();
}
- NodeTraversalCallback NOOP = new NodeTraversalCallback() {
- @Override
- public void traversedNode(PathSource pathSource) throws CommitFailedException {
-
- }
- };
+ NodeTraversalCallback NOOP = pathSource -> {};
void traversedNode(PathSource pathSource) throws CommitFailedException;
}
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java?rev=1796041&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java Wed May 24 11:09:15 2017
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.index.progress;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdate;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
+import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IndexingProgressReporter implements NodeTraversalCallback {
+ private static final String REINDEX_MSG = "Reindexing";
+ private static final String INDEX_MSG = "Incremental indexing";
+
+ private final Logger log = LoggerFactory.getLogger(IndexUpdate.class);
+ private final IndexUpdateCallback updateCallback;
+ private final NodeTraversalCallback traversalCallback;
+ private final Map<String, IndexUpdateState> indexUpdateStates = new HashMap<>();
+ private long traversalCount;
+ private String messagePrefix = INDEX_MSG;
+
+ public IndexingProgressReporter(IndexUpdateCallback updateCallback,
+ NodeTraversalCallback traversalCallback) {
+ this.updateCallback = updateCallback;
+ this.traversalCallback = traversalCallback;
+ }
+
+ public Editor wrapProgress(Editor editor) {
+ return ProgressTrackingEditor.wrap(editor, this);
+ }
+
+ /**
+ * Invoked to indicate that reindexing phase has started in current
+ * indexing cycle
+ */
+ public void reindexingTraversalStart() {
+ messagePrefix = REINDEX_MSG;
+ }
+
+ /**
+ * Invoked to indicate that reindexing phase has ended in current
+ * indexing cycle
+ */
+ public void reindexingTraversalEnd() {
+ messagePrefix = INDEX_MSG;
+ }
+
+ public void traversedNode(PathSource pathSource) throws CommitFailedException {
+ traversalCount++;
+ if (++traversalCount % 10000 == 0) {
+ log.info("{} Traversed #{} {}", messagePrefix, traversalCount, pathSource.getPath());
+ }
+ traversalCallback.traversedNode(pathSource);
+ }
+
+ /**
+ * Registers the index for progress tracking
+ *
+ * @param indexPath path of index
+ * @param reindexing true if the index is being reindexed
+ * @param estimatedCount an estimate of count of number of entries in the index. If less
+ * than zero then it indicates that estimation cannot be done
+ */
+ public void registerIndex(String indexPath, boolean reindexing, long estimatedCount) {
+ indexUpdateStates.put(indexPath, new IndexUpdateState(indexPath, reindexing, estimatedCount));
+ }
+
+ /**
+ * Callback to indicate that index at give path has got an update
+ */
+ public void indexUpdate(String indexPath) throws CommitFailedException {
+ indexUpdateStates.get(indexPath).indexUpdate();
+ }
+
+ public void logReport(){
+ if (isReindexingPerformed()){
+ log.info(getReport());
+ log.info("Reindexing completed");
+ } else if (log.isDebugEnabled() && somethingIndexed()){
+ log.debug(getReport());
+ }
+ }
+
+ public List<String> getReindexStats() {
+ return indexUpdateStates.values().stream()
+ .filter(st -> st.reindex)
+ .map(Object::toString)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Returns true if any reindexing is performed in current indexing
+ * cycle
+ */
+ public boolean isReindexingPerformed() {
+ return indexUpdateStates.values().stream().anyMatch(st -> st.reindex);
+ }
+
+ /**
+ * Set of indexPaths which have been updated or accessed
+ * in this indexing cycle.
+ */
+ public Set<String> getUpdatedIndexPaths() {
+ return indexUpdateStates.keySet();
+ }
+
+ /**
+ * Set of indexPaths which have been reindexed
+ */
+ public Set<String> getReindexedIndexPaths() {
+ return indexUpdateStates.values().stream()
+ .filter(st -> st.reindex)
+ .map(st -> st.indexPath)
+ .collect(Collectors.toSet());
+ }
+
+ public boolean somethingIndexed() {
+ return indexUpdateStates.values().stream().anyMatch(st -> st.updateCount > 0);
+ }
+
+ private String getReport() {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ pw.println("Indexing report");
+ for (IndexUpdateState st : indexUpdateStates.values()) {
+ if (!log.isDebugEnabled() && !st.reindex) {
+ continue;
+ }
+ if (st.updateCount > 0) {
+ pw.printf(" - %s%n", st);
+ }
+ }
+ return sw.toString();
+ }
+
+ private class IndexUpdateState {
+ final String indexPath;
+ final boolean reindex;
+ final long estimatedCount;
+ final Stopwatch watch = Stopwatch.createStarted();
+ long updateCount;
+
+ public IndexUpdateState(String indexPath, boolean reindex, long estimatedCount) {
+ this.indexPath = indexPath;
+ this.reindex = reindex;
+ this.estimatedCount = estimatedCount;
+ }
+
+ public void indexUpdate() throws CommitFailedException {
+ updateCount++;
+ if (updateCount % 10000 == 0) {
+ log.info("{} => Indexed {} nodes in {} ...", indexPath, updateCount, watch);
+ watch.reset().start();
+ }
+ updateCallback.indexUpdate();
+ }
+
+ @Override
+ public String toString() {
+ String reindexMarker = reindex ? "*" : "";
+ return indexPath + reindexMarker + "(" + updateCount + ")";
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java?rev=1796041&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java Wed May 24 11:09:15 2017
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.index.progress;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * Editor to track traversal and notify the callback for each node traversed.
+ * The editor also ensures that path is lazily constructed
+ */
+class ProgressTrackingEditor implements Editor, NodeTraversalCallback.PathSource {
+ private final Editor editor;
+ private final NodeTraversalCallback traversalCallback;
+ private final ProgressTrackingEditor parent;
+ private final String name;
+
+ public ProgressTrackingEditor(Editor editor, String name, NodeTraversalCallback traversalCallback) {
+ this.editor = editor;
+ this.name = name;
+ this.traversalCallback = traversalCallback;
+ this.parent = null;
+ }
+
+ private ProgressTrackingEditor(Editor editor, String name, NodeTraversalCallback callback,
+ ProgressTrackingEditor parent) {
+ this.editor = editor;
+ this.name = name;
+ this.traversalCallback = callback;
+ this.parent = parent;
+ }
+
+ @CheckForNull
+ public static Editor wrap(@CheckForNull Editor editor, NodeTraversalCallback onProgress) {
+ if (editor != null && !(editor instanceof ProgressTrackingEditor)) {
+ return new ProgressTrackingEditor(editor, "/", onProgress);
+ }
+ return editor;
+ }
+
+ @Override
+ public void enter(NodeState before, NodeState after) throws CommitFailedException {
+ traversalCallback.traversedNode(this);
+ editor.enter(before, after);
+ }
+
+ @Override
+ public void leave(NodeState before, NodeState after) throws CommitFailedException {
+ editor.leave(before, after);
+ }
+
+ @Override
+ public void propertyAdded(PropertyState after) throws CommitFailedException {
+ editor.propertyAdded(after);
+ }
+
+ @Override
+ public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException {
+ editor.propertyChanged(before, after);
+ }
+
+ @Override
+ public void propertyDeleted(PropertyState before) throws CommitFailedException {
+ editor.propertyDeleted(before);
+ }
+
+ @Override
+ public Editor childNodeAdded(String name, NodeState after) throws CommitFailedException {
+ return createChildEditor(editor.childNodeAdded(name, after), name);
+ }
+
+ @Override
+ public Editor childNodeChanged(String name, NodeState before, NodeState after) throws CommitFailedException {
+ return createChildEditor(editor.childNodeChanged(name, before, after), name);
+ }
+
+ @Override
+ public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException {
+ return createChildEditor(editor.childNodeDeleted(name, before), name);
+ }
+
+ public String getPath() {
+ if (parent == null) {
+ return PathUtils.ROOT_PATH;
+ } else {
+ StringBuilder sb = new StringBuilder(128);
+ buildPath(sb);
+ return sb.toString();
+ }
+ }
+
+ private void buildPath(@Nonnull StringBuilder sb) {
+ if (parent != null) {
+ parent.buildPath(sb);
+ sb.append('/').append(name);
+ }
+ }
+
+ private ProgressTrackingEditor createChildEditor(Editor editor, String name) {
+ if (editor == null) {
+ return null;
+ } else {
+ return new ProgressTrackingEditor(editor, name, traversalCallback, this);
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/progress/ProgressTrackingEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java?rev=1796041&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java Wed May 24 11:09:15 2017
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.index.progress;
+
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
+import org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.hasItems;
+import static org.junit.Assert.*;
+
+public class IndexingProgressReporterTest {
+
+ private IndexingProgressReporter reporter = new IndexingProgressReporter(IndexUpdateCallback.NOOP,
+ NodeTraversalCallback.NOOP);
+
+ @Test
+ public void basicTest() throws Exception{
+ reporter.registerIndex("foo", false, -1);
+ assertFalse(reporter.isReindexingPerformed());
+
+ reporter.registerIndex("bar", true, -1);
+ assertTrue(reporter.isReindexingPerformed());
+
+ assertThat(reporter.getUpdatedIndexPaths(), hasItems("foo", "bar"));
+ assertThat(reporter.getReindexedIndexPaths(), hasItems("bar"));
+
+ assertFalse(reporter.somethingIndexed());
+
+ reporter.indexUpdate("foo");
+ assertTrue(reporter.somethingIndexed());
+ }
+
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/progress/IndexingProgressReporterTest.java
------------------------------------------------------------------------------
svn:eol-style = native