Explorar o código

HDFS-2820. Add a simple sanity check for HA config. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1235013 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon %!s(int64=13) %!d(string=hai) anos
pai
achega
c10853a6b9

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt

@@ -121,3 +121,5 @@ HDFS-2367. Enable the configuration of multiple HA cluster addresses. (atm)
 HDFS-2812. When becoming active, the NN should treat all leases as freshly renewed. (todd)
 HDFS-2812. When becoming active, the NN should treat all leases as freshly renewed. (todd)
 
 
 HDFS-2737. Automatically trigger log rolls periodically on the active NN. (todd and atm)
 HDFS-2737. Automatically trigger log rolls periodically on the active NN. (todd and atm)
+
+HDFS-2820. Add a simple sanity check for HA config (todd)

+ 6 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java

@@ -569,6 +569,12 @@ public class DFSUtil {
     }
     }
     return b.toString();
     return b.toString();
   }
   }
+  
+  public static String nnAddressesAsString(Configuration conf) {
+    Map<String, Map<String, InetSocketAddress>> addresses =
+      getHaNnRpcAddresses(conf);
+    return addressMapToString(addresses);
+  }
 
 
   /**
   /**
    * Represent one of the NameNodes configured in the cluster.
    * Represent one of the NameNodes configured in the cluster.

+ 11 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -752,6 +752,17 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
     String nameserviceId = DFSUtil.getNamenodeNameServiceId(conf);
     String nameserviceId = DFSUtil.getNamenodeNameServiceId(conf);
     this.haEnabled = HAUtil.isHAEnabled(conf, nameserviceId);  
     this.haEnabled = HAUtil.isHAEnabled(conf, nameserviceId);  
     this.persistBlocks |= haEnabled && HAUtil.usesSharedEditsDir(conf);
     this.persistBlocks |= haEnabled && HAUtil.usesSharedEditsDir(conf);
+    
+    // Sanity check the HA-related config.
+    if (nameserviceId != null) {
+      LOG.info("Determined nameservice ID: " + nameserviceId);
+    }
+    LOG.info("HA Enabled: " + haEnabled);
+    if (!haEnabled && HAUtil.usesSharedEditsDir(conf)) {
+      LOG.warn("Configured NNs:\n" + DFSUtil.nnAddressesAsString(conf));
+      throw new IOException("Invalid configuration: a shared edits dir " +
+          "must not be specified if HA is not enabled.");
+    }
 
 
     short filePermission = (short)conf.getInt(DFS_NAMENODE_UPGRADE_PERMISSION_KEY,
     short filePermission = (short)conf.getInt(DFS_NAMENODE_UPGRADE_PERMISSION_KEY,
                                               DFS_NAMENODE_UPGRADE_PERMISSION_DEFAULT);
                                               DFS_NAMENODE_UPGRADE_PERMISSION_DEFAULT);