hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [23/50] [abbrv] hadoop git commit: HDFS-9934. ReverseXML oiv processor should bail out if the XML file's layoutVersion doesn't match oiv's (cmccabe)
Date Fri, 11 Mar 2016 22:22:41 GMT
HDFS-9934. ReverseXML oiv processor should bail out if the XML file's layoutVersion doesn't
match oiv's (cmccabe)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/bd49354c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/bd49354c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/bd49354c

Branch: refs/heads/HDFS-7240
Commit: bd49354c6d6387620b0de2219eab1714ec2d64f8
Parents: 500875d
Author: Colin Patrick Mccabe <cmccabe@cloudera.com>
Authored: Thu Mar 10 13:41:06 2016 -0800
Committer: Colin Patrick Mccabe <cmccabe@cloudera.com>
Committed: Thu Mar 10 13:41:06 2016 -0800

----------------------------------------------------------------------
 .../OfflineImageReconstructor.java              | 11 +++++++
 .../TestOfflineImageViewer.java                 | 34 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd49354c/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
index e5d0e2c..73f4a22 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
@@ -68,6 +68,7 @@ import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection;
 import org.apache.hadoop.hdfs.server.namenode.FsImageProto.NameSystemSection;
 import org.apache.hadoop.hdfs.server.namenode.FsImageProto.SecretManagerSection;
 import org.apache.hadoop.hdfs.server.namenode.FsImageProto.SnapshotDiffSection.DiffEntry;
+import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion;
 import org.apache.hadoop.hdfs.util.MD5FileUtils;
 import org.apache.hadoop.hdfs.util.XMLUtils;
 import org.apache.hadoop.io.IOUtils;
@@ -1493,6 +1494,16 @@ class OfflineImageReconstructor {
       throw new IOException("The <version> section doesn't contain " +
           "the layoutVersion.");
     }
+    if (layoutVersion.intValue() !=
+        NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION) {
+      throw new IOException("Layout version mismatch.  This oiv tool " +
+          "handles layout version " +
+          NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION + ", but the " +
+          "XML file has <layoutVersion> " + layoutVersion + ".  Please " +
+          "either re-generate the XML file with the proper layout version, " +
+          "or manually edit the XML file to be usable with this version " +
+          "of the oiv tool.");
+    }
     fileSummaryBld.setOndiskVersion(onDiskVersion);
     fileSummaryBld.setLayoutVersion(layoutVersion);
     if (LOG.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd49354c/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
----------------------------------------------------------------------
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 c7a6ae9..5d5fea6 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
@@ -29,6 +29,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.io.RandomAccessFile;
 import java.io.StringReader;
 import java.net.HttpURLConnection;
@@ -64,6 +65,7 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
 import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
+import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion;
 import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.net.NetUtils;
@@ -499,4 +501,36 @@ public class TestOfflineImageViewer {
     Assert.assertEquals("",
       GenericTestUtils.getFilesDiff(reverseImageXml, reverseImage2Xml));
   }
+
+  /**
+   * Tests that the ReverseXML processor doesn't accept XML files with the wrong
+   * layoutVersion.
+   */
+  @Test
+  public void testReverseXmlWrongLayoutVersion() throws Throwable {
+    File imageWrongVersion = new File(tempDir, "imageWrongVersion.xml");
+    PrintWriter writer = new PrintWriter(imageWrongVersion, "UTF-8");
+    try {
+      writer.println("<?xml version=\"1.0\"?>");
+      writer.println("<fsimage>");
+      writer.println("<version>");
+      writer.println(String.format("<layoutVersion>%d</layoutVersion>",
+          NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION + 1));
+      writer.println("<onDiskVersion>1</onDiskVersion>");
+      writer.println("<oivRevision>" +
+          "545bbef596c06af1c3c8dca1ce29096a64608478</oivRevision>");
+      writer.println("</version>");
+      writer.println("</fsimage>");
+    } finally {
+      writer.close();
+    }
+    try {
+      OfflineImageReconstructor.run(imageWrongVersion.getAbsolutePath(),
+          imageWrongVersion.getAbsolutePath() + ".out"); 
+      Assert.fail("Expected OfflineImageReconstructor to fail with " +
+          "version mismatch.");
+    } catch (Throwable t) {
+      GenericTestUtils.assertExceptionContains("Layout version mismatch.", t);
+    }
+  }
 }


Mime
View raw message