From 3a4469df97538e9d5e03a870f551e1e40061d70e Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Mon, 3 Mar 2014 19:42:22 +0000 Subject: [PATCH] Merge r1573694 from trunk. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1573696 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../FileDistributionCalculator.java | 7 +++++-- .../OfflineImageViewerPB.java | 19 ++++++++++++------- .../TestOfflineImageViewer.java | 8 ++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index b9bf0d86a49..a8bcd1d9650 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -270,6 +270,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 04f6e5030f5..61c8714b8d1 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 @@ import com.google.common.io.LimitInputStream; 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 f3bfd964d49..eb5a24cd218 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 @@ public class OfflineImageViewerPB { 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 @@ public class OfflineImageViewerPB { * @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 class OfflineImageViewerPB { } 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 class OfflineImageViewerPB { } 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 class OfflineImageViewerPB { } 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 a3a5292e907..d258ad16048 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 class TestOfflineImageViewer { 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 {