(Re-)Indexing: estimate progress / ETA
Configure MetricEstimator in async indexer
@@ -49,6 +49,7 @@ import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData;
+import com.codahale.metrics.MetricRegistry;
import com.google.common.collect.Lists;
import org.apache.jackrabbit.api.stats.TimeSeries;
import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -64,7 +65,9 @@ import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
import org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy;
import org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler.CorruptIndexInfo;
+import org.apache.jackrabbit.oak.plugins.index.progress.MetricRateEstimator;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider;
import org.apache.jackrabbit.oak.spi.commit.CommitContext;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -199,6 +202,8 @@ public class AsyncIndexUpdate implements Runnable, Closeable {
private TrackingCorruptIndexHandler corruptIndexHandler = new TrackingCorruptIndexHandler();
+ private final StatisticsProvider statisticsProvider;
+
public AsyncIndexUpdate(@Nonnull String name, @Nonnull NodeStore store,
@Nonnull IndexEditorProvider provider, boolean switchOnSync) {
this(name, store, provider, StatisticsProvider.NOOP, switchOnSync);
@@ -212,6 +217,7 @@ public class AsyncIndexUpdate implements Runnable, Closeable {
this.provider = checkNotNull(provider);
this.switchOnSync = switchOnSync;
this.leaseTimeOut = DEFAULT_ASYNC_TIMEOUT;
+ this.statisticsProvider = statsProvider;
this.indexStats = new AsyncIndexStats(name, statsProvider);
}
@@ -715,6 +721,7 @@ public class AsyncIndexUpdate implements Runnable, Closeable {
indexUpdate =
new IndexUpdate(provider, name, after, builder, callback, callback, info, corruptIndexHandler)
.withMissingProviderStrategy(missingStrategy);
+ configureRateEstimator(indexUpdate);
CommitFailedException exception =
EditorDiff.process(VisibleEditor.wrap(indexUpdate), before, after);
if (exception != null) {
@@ -784,6 +791,14 @@ public class AsyncIndexUpdate implements Runnable, Closeable {
return updatePostRunStatus;
}
+ private void configureRateEstimator(IndexUpdate indexUpdate) {
+ //As metrics is an optional library guard the access with the check
+ if (statisticsProvider.getClass().getSimpleName().equals("MetricStatisticsProvider")){
+ MetricRegistry registry = ((MetricStatisticsProvider) statisticsProvider).getRegistry();
+ indexUpdate.setTraversalRateEstimator(new MetricRateEstimator(name, registry));
+ }
+ }
+
static String leasify(String name) {
return name + "-lease";
}
