Author: frm Date: Wed Jan 17 15:04:52 2018 New Revision: 1821378 URL: http://svn.apache.org/viewvc?rev=1821378&view=rev Log: OAK-7169 - Let the datastorecheck command properly propagate errors
Backport r1821370 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/DataStoreCheckCommand.java jackrabbit/oak/branches/1.8/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java Propchange: jackrabbit/oak/branches/1.8/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jan 17 15:04:52 2018 @@ -1,3 +1,3 @@ /jackrabbit/oak/branches/1.0:1665962 -/jackrabbit/oak/trunk:1820660-1820661,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821258,1821362 +/jackrabbit/oak/trunk:1820660-1820661,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821258,1821362,1821370 /jackrabbit/trunk:1345480 Modified: jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java?rev=1821378&r1=1821377&r2=1821378&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java (original) +++ jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCheckCommand.java Wed Jan 17 15:04:52 2018 @@ -16,6 +16,21 @@ */ package org.apache.jackrabbit.oak.run; +import static com.google.common.base.StandardSystemProperty.FILE_SEPARATOR; +import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static com.google.common.base.Stopwatch.createStarted; +import static com.google.common.io.Closeables.close; +import static java.io.File.createTempFile; +import static java.util.Arrays.asList; +import static org.apache.commons.io.FileUtils.forceDelete; +import static org.apache.commons.io.FileUtils.listFiles; +import static org.apache.jackrabbit.oak.commons.FileIOUtils.sort; +import static org.apache.jackrabbit.oak.commons.FileIOUtils.writeAsLine; +import static org.apache.jackrabbit.oak.commons.FileIOUtils.writeStrings; +import static org.apache.jackrabbit.oak.commons.sort.EscapeUtils.escapeLineBreak; +import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; +import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; + import java.io.BufferedWriter; import java.io.Closeable; import java.io.File; @@ -72,21 +87,6 @@ import org.apache.jackrabbit.oak.spi.sta import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStore; -import static com.google.common.base.StandardSystemProperty.FILE_SEPARATOR; -import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; -import static com.google.common.base.Stopwatch.createStarted; -import static com.google.common.io.Closeables.close; -import static java.io.File.createTempFile; -import static java.util.Arrays.asList; -import static org.apache.commons.io.FileUtils.forceDelete; -import static org.apache.commons.io.FileUtils.listFiles; -import static org.apache.jackrabbit.oak.commons.FileIOUtils.sort; -import static org.apache.jackrabbit.oak.commons.FileIOUtils.writeAsLine; -import static org.apache.jackrabbit.oak.commons.FileIOUtils.writeStrings; -import static org.apache.jackrabbit.oak.commons.sort.EscapeUtils.escapeLineBreak; -import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder; -import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder; - /** * Command to check data store consistency and also optionally retrieve ids * and references. @@ -108,6 +108,10 @@ public class DataStoreCheckCommand imple @Override public void execute(String... args) throws Exception { + System.exit(checkDataStore(args)); + } + + static int checkDataStore(String... args) { OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -116,8 +120,7 @@ public class DataStoreCheckCommand imple + "[--s3ds <s3ds_config>|--fds <fds_config>|--azureblobds <azureblobds_config>|--nods]" + " [--dump <path>] [--repoHome <repo_home>] [--track] [--verbose]"; - Closer closer = Closer.create(); - try { + try (Closer closer = Closer.create()) { // Options for operations requested OptionSpecBuilder idOp = parser.accepts("id", "Get ids"); OptionSpecBuilder refOp = parser.accepts("ref", "Get references"); @@ -158,12 +161,12 @@ public class DataStoreCheckCommand imple System.err.println(); System.err.println("Options :"); parser.printHelpOn(System.err); - return; + return 1; } if (options.has(help)) { parser.printHelpOn(System.out); - return; + return 0; } String dumpPath = JAVA_IO_TMPDIR.value(); @@ -206,7 +209,7 @@ public class DataStoreCheckCommand imple if (blobStore == null) { System.err.println("Operation not defined for SegmentNodeStore without external datastore"); parser.printHelpOn(System.err); - return; + return 1; } FileRegister register = new FileRegister(options); @@ -257,10 +260,11 @@ public class DataStoreCheckCommand imple checkConsistency(register.get(idOp), register.get(refOp), register.createFile(consistencyOp, dumpPath), options.valueOf(repoHome), dsType); } + + return 0; } catch (Throwable t) { - t.printStackTrace(); - } finally { - closer.close(); + t.printStackTrace(System.err); + return 1; } } Modified: jackrabbit/oak/branches/1.8/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java?rev=1821378&r1=1821377&r2=1821378&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java (original) +++ jackrabbit/oak/branches/1.8/oak-run/src/test/java/org/apache/jackrabbit/oak/run/DataStoreCheckTest.java Wed Jan 17 15:04:52 2018 @@ -315,21 +315,17 @@ public class DataStoreCheckTest { } private void testAllParams(File dump, File repoHome) throws Exception { - DataStoreCheckCommand checkCommand = new DataStoreCheckCommand(); List<String> argsList = Lists .newArrayList("--id", "--ref", "--consistency", "--" + dsOption, cfgFilePath, "--store", storePath, "--dump", dump.getAbsolutePath(), "--repoHome", repoHome.getAbsolutePath()); - - checkCommand.execute(argsList.toArray(new String[0])); + DataStoreCheckCommand.checkDataStore(argsList.toArray(new String[0])); } private void testAllParamsVerbose(File dump, File repoHome) throws Exception { - DataStoreCheckCommand checkCommand = new DataStoreCheckCommand(); List<String> argsList = Lists .newArrayList("--id", "--ref", "--consistency", "--" + dsOption, cfgFilePath, "--store", storePath, "--dump", dump.getAbsolutePath(), "--repoHome", repoHome.getAbsolutePath(), "--verbose"); - - checkCommand.execute(argsList.toArray(new String[0])); + DataStoreCheckCommand.checkDataStore(argsList.toArray(new String[0])); } @Test @@ -344,11 +340,10 @@ public class DataStoreCheckTest { } public void testTarNoDSOption(File dump) throws Exception { - DataStoreCheckCommand checkCommand = new DataStoreCheckCommand(); List<String> argsList = Lists .newArrayList("--id", "--ref", "--consistency", "--nods", "--store", storePath, "--dump", dump.getAbsolutePath(), "--repoHome", temporaryFolder.newFolder().getAbsolutePath()); - checkCommand.execute(argsList.toArray(new String[0])); + DataStoreCheckCommand.checkDataStore(argsList.toArray(new String[0])); } @Test @@ -412,9 +407,7 @@ public class DataStoreCheckTest { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); System.setErr(new PrintStream(buffer, true, UTF_8.toString())); - DataStoreCheckCommand checkCommand = new DataStoreCheckCommand(); - - checkCommand.execute(argList.toArray(new String[0])); + DataStoreCheckCommand.checkDataStore(argList.toArray(new String[0])); String message = buffer.toString(UTF_8.toString()); log.info("Assert message: {}", assertMsg); log.info("Message logged in System.err: {}", message);