Author: frm Date: Mon Feb 5 15:26:41 2018 New Revision: 1823186 URL: http://svn.apache.org/viewvc?rev=1823186&view=rev Log: OAK-7174 - Let the check command properly propagate errors
Backport r1822934 from trunk. Modified: jackrabbit/oak/branches/1.8/ (props changed) jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java Propchange: jackrabbit/oak/branches/1.8/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Feb 5 15:26:41 2018 @@ -1,3 +1,3 @@ /jackrabbit/oak/branches/1.0:1665962 -/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1822723,1823135,1823163,1823169 +/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1822723,1822934,1823135,1823163,1823169 /jackrabbit/trunk:1345480 Modified: jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java?rev=1823186&r1=1823185&r2=1823186&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java (original) +++ jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java Mon Feb 5 15:26:41 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/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java?rev=1823186&r1=1823185&r2=1823186&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java (original) +++ jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java Mon Feb 5 15:26:41 2018 @@ -23,8 +23,6 @@ import static org.apache.jackrabbit.oak. import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.util.Set; import com.google.common.io.Closer; import org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever; @@ -36,7 +34,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.Diff; import org.apache.jackrabbit.oak.segment.tool.Restore; import org.apache.jackrabbit.oak.segment.tool.Revisions; @@ -83,23 +80,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/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java?rev=1823186&r1=1823185&r2=1823186&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java (original) +++ jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java Mon Feb 5 15:26:41 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; } }