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 ng...@apache.org on 2022/03/23 09:36:44 UTC

[jackrabbit-oak] branch trunk updated: Ofsetting corrupt index counter value when index is fixed (#526)

This is an automated email from the ASF dual-hosted git repository.

ngupta pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 871ce1b  Ofsetting corrupt index counter value when index is fixed (#526)
871ce1b is described below

commit 871ce1bb28712c16ba75b57538fb49e14bc135a3
Author: nit0906 <ni...@gmail.com>
AuthorDate: Wed Mar 23 15:06:40 2022 +0530

    Ofsetting corrupt index counter value when index is fixed (#526)
---
 .../plugins/index/TrackingCorruptIndexHandler.java |  7 ++++-
 .../index/TrackingCorruptIndexHandlerTest.java     | 32 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
index d2a984a..565786e 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
@@ -94,7 +94,12 @@ public class TrackingCorruptIndexHandler implements CorruptIndexHandler {
             }
         }
         if (meter != null) {
-            meter.mark(indexes.size());
+            // 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());
         }
     }
 
diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandlerTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandlerTest.java
index fe07de3..880712f 100644
--- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandlerTest.java
+++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandlerTest.java
@@ -21,9 +21,16 @@ package org.apache.jackrabbit.oak.plugins.index;
 
 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();
+
+    @After
+    public void cleanup() {
+        scheduledExecutorService.shutdown();
+    }
 
     @Test
     public void basics() throws Exception{
@@ -52,6 +65,25 @@ public class TrackingCorruptIndexHandlerTest {
     }
 
     @Test
+    public void testCorruptCounter() {
+        MeterStats meter = new DefaultStatisticsProvider(scheduledExecutorService).
+                getMeter(TrackingCorruptIndexHandler.CORRUPT_INDEX_METER_NAME, StatsOptions.METRICS_ONLY);
+
+        handler.setMeterStats(meter);
+        handler.setClock(clock);
+        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<>();
+        set.add("/oak:index/foo");
+        handler.markWorkingIndexes(set);
+
+        assertEquals(1, meter.getCount());
+    }
+
+    @Test
     public void disbaled() throws Exception{
         handler.setClock(clock);
         handler.indexUpdateFailed("async", "/oak:index/foo", new Exception());