diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 15ef11db15..b9829d0d10 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -517,6 +517,9 @@ Release 2.4.0 - UNRELEASED HDFS-5956. A file size is multiplied by the replication factor in 'hdfs oiv -p FileDistribution' option. (Akira Ajisaka via wheat9) + HDFS-5866. '-maxSize' and '-step' option fail in OfflineImageViewer. + (Akira Ajisaka via wheat9) + BREAKDOWN OF HDFS-5698 SUBTASKS AND RELATED JIRAS HDFS-5717. Save FSImage header in protobuf. (Haohui Mai via jing9) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FileDistributionCalculator.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FileDistributionCalculator.java index 04f6e5030f..61c8714b8d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FileDistributionCalculator.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FileDistributionCalculator.java @@ -62,6 +62,7 @@ final class FileDistributionCalculator { private final static long MAX_SIZE_DEFAULT = 0x2000000000L; // 1/8 TB = 2^37 private final static int INTERVAL_DEFAULT = 0x200000; // 2 MB = 2^21 + private final static int MAX_INTERVALS = 0x8000000; // 128 M = 2^27 private final Configuration conf; private final long maxSize; @@ -82,9 +83,11 @@ final class FileDistributionCalculator { this.steps = steps == 0 ? INTERVAL_DEFAULT : steps; this.out = out; long numIntervals = this.maxSize / this.steps; + // avoid OutOfMemoryError when allocating an array + Preconditions.checkState(numIntervals <= MAX_INTERVALS, + "Too many distribution intervals (maxSize/step): " + numIntervals + + ", should be less than " + (MAX_INTERVALS+1) + "."); this.distribution = new int[1 + (int) (numIntervals)]; - Preconditions.checkState(numIntervals < Integer.MAX_VALUE, - "Too many distribution intervals"); } void visit(RandomAccessFile file) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java index fbac43ac29..db112d0903 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java @@ -101,9 +101,8 @@ private static Options buildOptions() { options.addOption("p", "processor", true, ""); options.addOption("h", "help", false, ""); - options.addOption("skipBlocks", false, ""); - options.addOption("printToScreen", false, ""); - options.addOption("delimiter", true, ""); + options.addOption("maxSize", true, ""); + options.addOption("step", true, ""); return options; } @@ -118,10 +117,15 @@ private static Options buildOptions() { * @throws IOException */ public static void main(String[] args) throws IOException { + int status = run(args); + System.exit(status); + } + + public static int run(String[] args) throws IOException { Options options = buildOptions(); if (args.length == 0) { printUsage(); - return; + return 0; } CommandLineParser parser = new PosixParser(); @@ -132,12 +136,12 @@ public static void main(String[] args) throws IOException { } catch (ParseException e) { System.out.println("Error parsing command-line options: "); printUsage(); - return; + return -1; } if (cmd.hasOption("h")) { // print help and exit printUsage(); - return; + return 0; } String inputFile = cmd.getOptionValue("i"); @@ -160,6 +164,7 @@ public static void main(String[] args) throws IOException { } else { new LsrPBImage(conf, out).visit(new RandomAccessFile(inputFile, "r")); } + return 0; } catch (EOFException e) { System.err.println("Input file ended unexpectedly. Exiting"); } catch (IOException e) { @@ -167,7 +172,7 @@ public static void main(String[] args) throws IOException { } finally { IOUtils.cleanup(null, out); } - + return -1; } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java index a3a5292e90..d258ad1604 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java @@ -277,6 +277,14 @@ public int compare(FileStatus first, FileStatus second) { assertEquals(maxFile.getLen(), Long.parseLong(matcher.group(1))); } + @Test + public void testFileDistributionCalculatorWithOptions() throws IOException { + int status = OfflineImageViewerPB.run(new String[] {"-i", + originalFsimage.getAbsolutePath(), "-o", "-", "-p", "FileDistribution", + "-maxSize", "512", "-step", "8"}); + assertEquals(0, status); + } + @Test public void testPBImageXmlWriter() throws IOException, SAXException, ParserConfigurationException {