Author: frm
Date: Fri Feb  2 10:03:32 2018
New Revision: 1822934

URL: http://svn.apache.org/viewvc?rev=1822934&view=rev
Log:
OAK-7174 - Let the check command properly propagate errors

The check command should always return with a non-zero return code in case of
error. Moreover, error messages and stack traces should always be printed on
the standard error.

Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java?rev=1822934&r1=1822933&r2=1822934&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
 Fri Feb  2 10:03:32 2018
@@ -30,6 +30,7 @@ import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 import org.apache.jackrabbit.oak.run.commons.Command;
+import org.apache.jackrabbit.oak.segment.tool.Check;
 
 class CheckCommand implements Command {
 
@@ -78,9 +79,21 @@ class CheckCommand implements Command {
         }
         
         boolean checkHead = !options.has(cp) || options.has(head);
-        
-        SegmentTarUtils.check(dir, journalFileName, debugLevel, 
options.has(bin), checkHead, checkpoints, filterPaths, 
-                options.has(ioStatistics), out, err);
+
+        int statusCode = Check.builder()
+            .withPath(dir)
+            .withJournal(journalFileName)
+            .withDebugInterval(debugLevel)
+            .withCheckBinaries(options.has(bin))
+            .withCheckHead(checkHead)
+            .withCheckpoints(checkpoints)
+            .withFilterPaths(filterPaths)
+            .withIOStatistics(options.has(ioStatistics))
+            .withOutWriter(out)
+            .withErrWriter(err)
+            .build()
+            .run();
+        System.exit(statusCode);
     }
 
     private void printUsage(OptionParser parser, PrintWriter err, String... 
messages) throws IOException {

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java?rev=1822934&r1=1822933&r2=1822934&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
 Fri Feb  2 10:03:32 2018
@@ -23,10 +23,8 @@ import static org.apache.jackrabbit.oak.
 
 import java.io.File;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 
 import com.google.common.io.Closer;
 import org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever;
@@ -38,7 +36,6 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
 import org.apache.jackrabbit.oak.segment.tool.Backup;
-import org.apache.jackrabbit.oak.segment.tool.Check;
 import org.apache.jackrabbit.oak.segment.tool.DebugSegments;
 import org.apache.jackrabbit.oak.segment.tool.DebugStore;
 import org.apache.jackrabbit.oak.segment.tool.DebugTars;
@@ -154,23 +151,6 @@ final class SegmentTarUtils {
                 .build()
                 .run();
     }
-
-    static void check(File dir, String journalFileName, long debugLevel, 
boolean checkBinaries, boolean checkHead, Set<String> checkpoints, 
-            Set<String> filterPaths, boolean ioStatistics, PrintWriter 
outWriter, PrintWriter errWriter) {
-        Check.builder()
-                .withPath(dir)
-                .withJournal(journalFileName)
-                .withDebugInterval(debugLevel)
-                .withCheckBinaries(checkBinaries)
-                .withCheckHead(checkHead)
-                .withCheckpoints(checkpoints)
-                .withFilterPaths(filterPaths)
-                .withIOStatistics(ioStatistics)
-                .withOutWriter(outWriter)
-                .withErrWriter(errWriter)
-                .build()
-                .run();
-    }
 
     static void diff(File store, File out, boolean listOnly, String interval, 
boolean incremental, String path, boolean ignoreSNFEs) throws IOException {
         if (listOnly) {

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java?rev=1822934&r1=1822933&r2=1822934&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java
 Fri Feb  2 10:03:32 2018
@@ -29,7 +29,7 @@ import org.apache.jackrabbit.oak.segment
 /**
  * Perform a consistency check on an existing segment store.
  */
-public class Check implements Runnable {
+public class Check {
 
     /**
      * Create a builder for the {@link Check} command.
@@ -197,7 +197,7 @@ public class Check implements Runnable {
          *
          * @return an instance of {@link Runnable}.
          */
-        public Runnable build() {
+        public Check build() {
             checkNotNull(path);
             checkNotNull(journal);
             return new Check(this);
@@ -238,13 +238,24 @@ public class Check implements Runnable {
         this.errWriter = builder.errWriter;
     }
 
-    @Override
-    public void run() {
+    public int run() {
         try {
-            ConsistencyChecker.checkConsistency(path, journal, debugInterval, 
checkBinaries, checkHead, checkpoints, filterPaths, 
-                    ioStatistics, outWriter, errWriter);
+            ConsistencyChecker.checkConsistency(
+                path,
+                journal,
+                debugInterval,
+                checkBinaries,
+                checkHead,
+                checkpoints,
+                filterPaths,
+                ioStatistics,
+                outWriter,
+                errWriter
+            );
+            return 0;
         } catch (Exception e) {
-            e.printStackTrace();
+            e.printStackTrace(errWriter);
+            return 1;
         }
     }
 


Reply via email to