Author: chetanm
Date: Thu May  4 06:49:26 2017
New Revision: 1793742

URL: http://svn.apache.org/viewvc?rev=1793742&view=rev
Log:
OAK-5558 - Consistency checker for Lucene indexes

Delete locally copied files in case index is found to be valid. In case
its not valid then files would be left in the provided directory

Modified:
    
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexConsistencyChecker.java

Modified: 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexConsistencyChecker.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexConsistencyChecker.java?rev=1793742&r1=1793741&r2=1793742&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexConsistencyChecker.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/IndexConsistencyChecker.java
 Thu May  4 06:49:26 2017
@@ -63,6 +63,7 @@ public class IndexConsistencyChecker {
     private final NodeState rootState;
     private final String indexPath;
     private final File workDirRoot;
+    private File workDir;
 
     public enum Level {
         /**
@@ -137,6 +138,16 @@ public class IndexConsistencyChecker {
         }
     }
 
+    /**
+     * Checks the index at given path for consistency
+     *
+     * @param rootState root state of repository
+     * @param indexPath path of index which needs to be checked
+     * @param workDirRoot directory which would be used for copying the index 
file locally to perform
+     *                    check. File would be created in a subdirectory. If 
the index is valid
+     *                    then the files would be removed otherwise whatever 
files have been copied
+     *                    would be left as is
+     */
     public IndexConsistencyChecker(NodeState rootState, String indexPath, File 
workDirRoot) {
         this.rootState = checkNotNull(rootState);
         this.indexPath = checkNotNull(indexPath);
@@ -158,17 +169,20 @@ public class IndexConsistencyChecker {
 
         if (result.clean){
             log.info("[] No problems were detected with this index. Time taken 
{}", indexPath, watch);
+            FileUtils.deleteQuietly(workDir);
         } else {
-            log.info("[] Problems detected with this index. Time taken {}", 
indexPath, watch);
+            log.warn("[] Problems detected with this index. Time taken {}", 
indexPath, watch);
+            if (workDir != null) {
+                log.warn("[] Index files are copied to {}", indexPath, 
workDir.getAbsolutePath());
+            }
         }
-
         return result;
     }
 
     private void checkIndex(Result result) throws IOException {
         NodeState idx = NodeStateUtils.getNode(rootState, indexPath);
         IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx, 
indexPath).build();
-        File workDir = createWorkDir(workDirRoot, 
PathUtils.getName(indexPath));
+        workDir = createWorkDir(workDirRoot, PathUtils.getName(indexPath));
 
         for (String dirName : idx.getChildNodeNames()){
             //TODO Check for SuggestionDirectory Pending


Reply via email to