Author: frm Date: Wed Jan 17 15:02:25 2018 New Revision: 1821377 URL: http://svn.apache.org/viewvc?rev=1821377&view=rev Log: OAK-7168 - Let the debug command properly propagate errors
Backport r1821362 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/DebugCommand.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/DebugSegments.java jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugStore.java jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugTars.java Propchange: jackrabbit/oak/branches/1.8/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Jan 17 15:02:25 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 +/jackrabbit/oak/trunk:1820660-1820661,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821258,1821362 /jackrabbit/trunk:1345480 Modified: jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DebugCommand.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DebugCommand.java?rev=1821377&r1=1821376&r2=1821377&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DebugCommand.java (original) +++ jackrabbit/oak/branches/1.8/oak-run/src/main/java/org/apache/jackrabbit/oak/run/DebugCommand.java Wed Jan 17 15:02:25 2018 @@ -17,10 +17,17 @@ package org.apache.jackrabbit.oak.run; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import joptsimple.OptionParser; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.apache.jackrabbit.oak.run.commons.Command; +import org.apache.jackrabbit.oak.segment.tool.DebugSegments; +import org.apache.jackrabbit.oak.segment.tool.DebugStore; +import org.apache.jackrabbit.oak.segment.tool.DebugTars; class DebugCommand implements Command { @@ -35,9 +42,71 @@ class DebugCommand implements Command { System.exit(1); } - String[] nonOptionsArray = options.valuesOf(nonOptions).toArray(new String[0]); + System.exit(debug(options.valuesOf(nonOptions))); + } + + private static int debug(List<String> args) { + File file = new File(args.get(0)); + + List<String> tars = new ArrayList<>(); + List<String> segs = new ArrayList<>(); + + for (int i = 1; i < args.size(); i++) { + if (args.get(i).endsWith(".tar")) { + tars.add(args.get(i)); + } else { + segs.add(args.get(i)); + } + } + + int returnCode = 0; + + if (tars.size() > 0) { + if (debugTars(file, tars) != 0) { + returnCode = 1; + } + } + + if (segs.size() > 0) { + if (debugSegments(file, segs) != 0) { + returnCode = 1; + } + } + + if (tars.isEmpty() && segs.isEmpty()) { + if (debugStore(file) != 0) { + returnCode = 1; + } + } + + return returnCode; + } + + private static int debugTars(File store, List<String> tars) { + DebugTars.Builder builder = DebugTars.builder().withPath(store); + + for (String tar : tars) { + builder.withTar(tar); + } + + return builder.build().run(); + } + + private static int debugSegments(File store, List<String> segments) { + DebugSegments.Builder builder = DebugSegments.builder().withPath(store); + + for (String segment : segments) { + builder.withSegment(segment); + } + + return builder.build().run(); + } - SegmentTarUtils.debug(nonOptionsArray); + private static int debugStore(File store) { + return DebugStore.builder() + .withPath(store) + .build() + .run(); } } \ No newline at end of file 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=1821377&r1=1821376&r2=1821377&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 Wed Jan 17 15:02:25 2018 @@ -24,13 +24,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 javax.annotation.Nonnull; -import javax.annotation.Nullable; - import com.google.common.io.Closer; import org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever; import org.apache.jackrabbit.oak.segment.SegmentBlobReferenceRetriever; @@ -42,10 +37,6 @@ import org.apache.jackrabbit.oak.segment 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.Compact; -import org.apache.jackrabbit.oak.segment.tool.DebugSegments; -import org.apache.jackrabbit.oak.segment.tool.DebugStore; -import org.apache.jackrabbit.oak.segment.tool.DebugTars; import org.apache.jackrabbit.oak.segment.tool.Diff; import org.apache.jackrabbit.oak.segment.tool.History; import org.apache.jackrabbit.oak.segment.tool.Restore; @@ -94,61 +85,6 @@ final class SegmentTarUtils { .run(); } - static void debug(String... args) { - File file = new File(args[0]); - - List<String> tars = new ArrayList<>(); - List<String> segs = new ArrayList<>(); - - for (int i = 1; i < args.length; i++) { - if (args[i].endsWith(".tar")) { - tars.add(args[i]); - } else { - segs.add(args[i]); - } - } - - if (tars.size() > 0) { - debugTars(file, tars); - } - - if (segs.size() > 0) { - debugSegments(file, segs); - } - - if (tars.isEmpty() && segs.isEmpty()) { - debugStore(file); - } - } - - private static void debugTars(File store, List<String> tars) { - DebugTars.Builder builder = DebugTars.builder().withPath(store); - - for (String tar : tars) { - builder.withTar(tar); - } - - builder.build().run(); - } - - private static void debugSegments(File store, List<String> segments) { - DebugSegments.Builder builder = DebugSegments.builder().withPath(store); - - for (String segment : segments) { - builder.withSegment(segment); - } - - builder.build().run(); - } - - private static void debugStore(File store) { - DebugStore.builder() - .withPath(store) - .build() - .run(); - ; - } - static void history(File directory, File journal, String path, int depth) { History.builder() .withPath(directory) Modified: jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugSegments.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugSegments.java?rev=1821377&r1=1821376&r2=1821377&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugSegments.java (original) +++ jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugSegments.java Wed Jan 17 15:02:25 2018 @@ -42,7 +42,7 @@ import org.apache.jackrabbit.oak.spi.sta * Print debugging information about segments, node records and node record * ranges. */ -public class DebugSegments implements Runnable { +public class DebugSegments { private static final Pattern SEGMENT_REGEX = Pattern.compile("([0-9a-f-]+)|(([0-9a-f-]+:[0-9a-f]+)(-([0-9a-f-]+:[0-9a-f]+))?)?(/.*)?"); @@ -112,7 +112,7 @@ public class DebugSegments implements Ru * * @return an instance of {@link Runnable}. */ - public Runnable build() { + public DebugSegments build() { checkNotNull(path); checkArgument(!segments.isEmpty()); return new DebugSegments(this); @@ -129,12 +129,13 @@ public class DebugSegments implements Ru this.segments = new ArrayList<>(builder.segments); } - @Override - public void run() { + public int run() { try (ReadOnlyFileStore store = openReadOnlyFileStore(path)) { debugSegments(store); + return 0; } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(System.err); + return 1; } } Modified: jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugStore.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugStore.java?rev=1821377&r1=1821376&r2=1821377&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugStore.java (original) +++ jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugStore.java Wed Jan 17 15:02:25 2018 @@ -35,19 +35,16 @@ import java.util.UUID; import com.google.common.collect.Maps; import com.google.common.collect.Queues; - import org.apache.jackrabbit.oak.segment.RecordId; -import org.apache.jackrabbit.oak.segment.RecordType; import org.apache.jackrabbit.oak.segment.RecordUsageAnalyser; import org.apache.jackrabbit.oak.segment.Segment; -import org.apache.jackrabbit.oak.segment.Segment.RecordConsumer; import org.apache.jackrabbit.oak.segment.SegmentId; import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore; /** * Print debugging information about a segment store. */ -public class DebugStore implements Runnable { +public class DebugStore { /** * Create a builder for the {@link DebugStore} command. @@ -85,7 +82,7 @@ public class DebugStore implements Runna * * @return an instance of {@link Runnable}. */ - public Runnable build() { + public DebugStore build() { checkNotNull(path); return new DebugStore(this); } @@ -98,12 +95,13 @@ public class DebugStore implements Runna this.path = builder.path; } - @Override - public void run() { + public int run() { try (ReadOnlyFileStore store = openReadOnlyFileStore(path)) { debugFileStore(store); + return 0; } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(System.err); + return 1; } } @@ -177,15 +175,10 @@ public class DebugStore implements Runna private static void analyseSegment(final Segment segment, final RecordUsageAnalyser analyser) { final List<RecordId> ids = newArrayList(); - segment.forEachRecord(new RecordConsumer() { - - @Override - public void consume(int number, RecordType type, int offset) { - if (type == NODE) { - ids.add(new RecordId(segment.getSegmentId(), number)); - } + segment.forEachRecord((number, type, offset) -> { + if (type == NODE) { + ids.add(new RecordId(segment.getSegmentId(), number)); } - }); for (RecordId id : ids) { @@ -193,7 +186,7 @@ public class DebugStore implements Runna analyser.analyseNode(id); } catch (Exception e) { System.err.format("Error while processing node at %s", id); - e.printStackTrace(); + e.printStackTrace(System.err); } } } Modified: jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugTars.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugTars.java?rev=1821377&r1=1821376&r2=1821377&view=diff ============================================================================== --- jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugTars.java (original) +++ jackrabbit/oak/branches/1.8/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/DebugTars.java Wed Jan 17 15:02:25 2018 @@ -50,7 +50,7 @@ import org.apache.jackrabbit.oak.spi.sta /** * Print information about one or more TAR files from an existing segment store. */ -public class DebugTars implements Runnable { +public class DebugTars { /** * Create a builder for the {@link DebugTars} command. @@ -106,7 +106,7 @@ public class DebugTars implements Runnab * * @return an instance of {@link Runnable}. */ - public Runnable build() { + public DebugTars build() { checkNotNull(path); checkArgument(!tars.isEmpty()); return new DebugTars(this); @@ -126,12 +126,13 @@ public class DebugTars implements Runnab this.maxCharDisplay = builder.maxCharDisplay; } - @Override - public void run() { + public int run() { try (ReadOnlyFileStore store = openReadOnlyFileStore(path)) { debugTarFiles(store); + return 0; } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(System.err); + return 1; } } @@ -179,8 +180,8 @@ public class DebugTars implements Runnab System.out.println("" + entry.getKey() + '=' + entry.getValue()); } } catch (IOException e) { - System.out.println("Error getting tar graph:"); - e.printStackTrace(); + System.err.println("Error getting tar graph:"); + e.printStackTrace(System.err); } }