Skip to content
Browse files
Ofsetting corrupt index counter value when index is fixed (#526)
  • Loading branch information
nit0906 committed Mar 23, 2022
1 parent 64a916b commit 871ce1bb28712c16ba75b57538fb49e14bc135a3
Showing 2 changed files with 38 additions and 1 deletion.
@@ -94,7 +94,12 @@ public void markWorkingIndexes(Set<String> updatedIndexPaths) {
if (meter != null) {
// indexes.size() gives us the number of remaining corrupt indices.
// meter.mark(indexes.size()) increments the current meter count by indexes.size(). We don't want that here.
// We actually want to set the the meter count to indexes.size(), the api doesn't seem to support that.
// So we instead add indexes.size() - meter.getCount() , which will always be <= 0. So this effectively will reduce the meter count
// by number of indexes fixed in this call.
meter.mark(indexes.size() - meter.getCount());

@@ -21,9 +21,16 @@

import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.oak.stats.Clock;
import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
import org.apache.jackrabbit.oak.stats.MeterStats;
import org.apache.jackrabbit.oak.stats.StatsOptions;
import org.junit.After;
import org.junit.Test;

import static org.junit.Assert.*;
@@ -32,6 +39,12 @@ public class TrackingCorruptIndexHandlerTest {

private TrackingCorruptIndexHandler handler = new TrackingCorruptIndexHandler();
private Clock clock = new Clock.Virtual();
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

public void cleanup() {

public void basics() throws Exception{
@@ -51,6 +64,25 @@ public void basics() throws Exception{

public void testCorruptCounter() {
MeterStats meter = new DefaultStatisticsProvider(scheduledExecutorService).
getMeter(TrackingCorruptIndexHandler.CORRUPT_INDEX_METER_NAME, StatsOptions.METRICS_ONLY);

handler.indexUpdateFailed("async", "/oak:index/foo", new Exception());
assertEquals(1, meter.getCount());
handler.indexUpdateFailed("async", "/oak:index/bar", new Exception());
assertEquals(2, meter.getCount());

HashSet<String> set = new HashSet<>();

assertEquals(1, meter.getCount());

public void disbaled() throws Exception{

0 comments on commit 871ce1b

Please sign in to comment.