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 fo...@apache.org on 2022/05/10 12:43:34 UTC

[jackrabbit-oak] branch trunk updated: OAK-9756 statistics for the IndexSanityChecker (#563)

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

fortino 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 c25e78d706 OAK-9756 statistics for the IndexSanityChecker (#563)
c25e78d706 is described below

commit c25e78d70615bbb8a6bf677055ba309c841ebd26
Author: Jörg Hoh <jo...@users.noreply.github.com>
AuthorDate: Tue May 10 14:43:29 2022 +0200

    OAK-9756 statistics for the IndexSanityChecker (#563)
    
    * OAK-9756 statistics for the IndexSanityChecker
    
    * minor adjustments, thanks @thomasmueller
    
    * Update oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityChecker.java
    
    Co-authored-by: Fabrizio Fortino <fa...@gmail.com>
    
    Co-authored-by: Fabrizio Fortino <fa...@gmail.com>
---
 .../oak/plugins/index/lucene/IndexCopier.java      |  3 +-
 .../index/lucene/directory/IndexSanityChecker.java | 62 ++++++++++++++++++++--
 .../lucene/directory/IndexSanityCheckerTest.java   |  8 +--
 3 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java
index 65cbc9b051..449ac476cb 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java
@@ -109,6 +109,7 @@ public class IndexCopier implements CopyOnReadStatsMBean, Closeable {
     private volatile boolean closed;
     private final IndexRootDirectory indexRootDirectory;
     private final Set<String> validatedIndexPaths = Sets.newConcurrentHashSet();
+    private final IndexSanityChecker.IndexSanityStatistics indexSanityStatistics = new IndexSanityChecker.IndexSanityStatistics();
 
     public IndexCopier(Executor executor, File indexRootDir) throws IOException {
         this(executor, indexRootDir, false);
@@ -233,7 +234,7 @@ public class IndexCopier implements CopyOnReadStatsMBean, Closeable {
         //Also at this time its required that state in local dir should exactly same as
         //one in remote dir
         synchronized (validatedIndexPaths){
-            new IndexSanityChecker(indexPath, local, remote).check();
+            new IndexSanityChecker(indexPath, local, remote).check(indexSanityStatistics);
             validatedIndexPaths.add(indexPath);
         }
     }
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityChecker.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityChecker.java
index 29d14148dd..896ff35c17 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityChecker.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityChecker.java
@@ -48,8 +48,9 @@ public class IndexSanityChecker {
         this.indexPath = indexPath;
     }
 
-    public boolean check() throws IOException {
+    public boolean check(IndexSanityStatistics stats) throws IOException {
         boolean allFine = true;
+        long start = System.currentTimeMillis();
         //TODO Add support for checksum based checks
         if (isThereASizeMismatch()){
             //In case of any mismatch just purge all local files
@@ -63,15 +64,18 @@ public class IndexSanityChecker {
                 }
             }
         }
+        stats.addDuration(System.currentTimeMillis() - start);
+        stats.addIndexSize(localDirSize);
 
         if (allFine) {
             log.info("Local index directory content found to be valid for index [{}]. " +
-                    "Stats Local: {} files ({}), Remote: {} files ({})", indexPath,
+                    "Stats Local: {} files ({}), Remote: {} files ({}), accumulated statistics on checking index sanity: {}", indexPath,
                     localFileCount, IOUtils.humanReadableByteCount(localDirSize),
-                    remoteFileCount, IOUtils.humanReadableByteCount(remoteDirSize));
+                    remoteFileCount, IOUtils.humanReadableByteCount(remoteDirSize),
+                    stats.toString());
         } else {
             log.warn("Local index directory content were not found to be in sync with remote for index [{}]. " +
-                    "Local directory content has been purged and would be synced again from remote", indexPath);
+                    "Local directory content has been purged and would be synced again from remote.", indexPath);
         }
         return allFine;
     }
@@ -118,4 +122,54 @@ public class IndexSanityChecker {
             dir.deleteFile(fileName);
         }
     }
+    
+    
+    /**
+     * Accumulated statistics across multiple invocations of the IndexSanityChecker
+     *
+     */
+    public static class IndexSanityStatistics {
+        
+        long totalDurationInMs;
+        long totalIndexSize;
+        
+        /**
+         * Record the time spend to check the sanity of indexes
+         * @param milis the time in miliseconds
+         */
+        public void addDuration(long milis) {
+            totalDurationInMs += milis;
+        }
+        
+        /**
+         * Return the accumulated time for checking the sanity of indexes
+         * @return the total duration in miliseconds
+         */
+        public long getAccumulatedDuration() {
+            return totalDurationInMs;
+        }
+        
+        /**
+         * Record the size of an index considered
+         * @param bytes
+         */
+        public void addIndexSize (long bytes) {
+            totalIndexSize += bytes;
+        }
+        
+        /**
+         * Return the accumulated index size 
+         * @return index size in bytes
+         */
+        public long getAccumulatedIndexSize() {
+            return totalIndexSize;
+        }
+        
+        @Override
+        public String toString() {
+            return String.format("[duration: %d ms, "
+                    + "checked index size: %d bytes (%s)]", totalDurationInMs,
+                    totalIndexSize, IOUtils.humanReadableByteCount(totalIndexSize));
+        }
+    }
 }
diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityCheckerTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityCheckerTest.java
index e21e7a10b9..accf4b3b54 100644
--- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityCheckerTest.java
+++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexSanityCheckerTest.java
@@ -36,13 +36,15 @@ public class IndexSanityCheckerTest {
 
     private Directory local = new RAMDirectory();
     private Directory remote = new RAMDirectory();
+    
+    private IndexSanityChecker.IndexSanityStatistics stats = new IndexSanityChecker.IndexSanityStatistics();
 
     @Test
     public void validDirs() throws Exception{
         byte[] t1 = writeFile(local, "t1", 100);
         writeFile(remote, "t1", t1);
 
-        assertTrue(new IndexSanityChecker("/foo", local, remote).check());
+        assertTrue(new IndexSanityChecker("/foo", local, remote).check(stats));
 
         assertTrue(local.fileExists("t1"));
         assertTrue(remote.fileExists("t1"));
@@ -59,7 +61,7 @@ public class IndexSanityCheckerTest {
         byte[] t3R = writeFile(remote, "t3", 140);
         writeFile(local, "t3", t3R);
 
-        assertFalse(new IndexSanityChecker("/foo", local, remote).check());
+        assertFalse(new IndexSanityChecker("/foo", local, remote).check(stats));
 
         assertTrue(remote.fileExists("t3"));
 
@@ -74,7 +76,7 @@ public class IndexSanityCheckerTest {
         byte[] t3R = writeFile(remote, "t3", 140);
         writeFile(local, "t3", t3R);
 
-        new IndexSanityChecker("/foo", local, remote).check();
+        new IndexSanityChecker("/foo", local, remote).check(stats);
 
         //t1 exist in local but not in remote
         //it must be removed