Browse Source

HDFS-6032. -rollingUpgrade query hits NPE after the NN restarts. Contributed by Haohui Mai.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1572801 13f79535-47bb-0310-9956-ffa450edef68
Jing Zhao 11 năm trước cách đây
mục cha
commit
5409908026

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt

@@ -120,3 +120,6 @@ HDFS-5535 subtasks:
 
     HDFS-6029. Secondary NN fails to checkpoint after -rollingUpgrade prepare.
     (jing9)
+
+    HDFS-6032. -rollingUpgrade query hits NPE after the NN restarts. (Haohui Mai
+    via jing9)

+ 4 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java

@@ -881,9 +881,12 @@ public class FSImage implements Closeable {
    */
   private void loadFSImage(File curFile, MD5Hash expectedMd5,
       FSNamesystem target, MetaRecoveryContext recovery) throws IOException {
+    // BlockPoolId is required when the FsImageLoader loads the rolling upgrade
+    // information. Make sure the ID is properly set.
+    target.setBlockPoolId(this.getBlockPoolID());
+
     FSImageFormat.LoaderDelegator loader = FSImageFormat.newLoader(conf, target);
     loader.load(curFile);
-    target.setBlockPoolId(this.getBlockPoolID());
 
     // Check that the image digest we loaded matches up with what
     // we expected

+ 26 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java

@@ -432,6 +432,32 @@ public class TestRollingUpgrade {
     }
   }
 
+  @Test (timeout = 300000)
+  public void testQueryAfterRestart() throws IOException, InterruptedException {
+    final Configuration conf = new Configuration();
+    MiniDFSCluster cluster = null;
+    try {
+      cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
+      cluster.waitActive();
+      DistributedFileSystem dfs = cluster.getFileSystem();
+
+      dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
+      // start rolling upgrade
+      dfs.rollingUpgrade(RollingUpgradeAction.PREPARE);
+      queryForPreparation(dfs);
+      dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
+      dfs.saveNamespace();
+      dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
+
+      cluster.restartNameNodes();
+      dfs.rollingUpgrade(RollingUpgradeAction.QUERY);
+    } finally {
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
+
   @Test(timeout = 300000)
   public void testCheckpoint() throws IOException, InterruptedException {
     final Configuration conf = new Configuration();