Quellcode durchsuchen

HDFS-17752. Host2DatanodeMap will not update when re-register a node with a different hostname. (#7468). Contributed by liuwenjing17.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
liuwenjing17 vor 3 Wochen
Ursprung
Commit
445298003d

+ 12 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java

@@ -712,6 +712,14 @@ public class DatanodeManager {
     return host2DatanodeMap.getDatanodeByHost(host);
   }
 
+  /**
+   * @param hostname hostname of the datanode
+   * @return the datanode descriptor for the host.
+   */
+  public DatanodeDescriptor getDatanodeByHostName(final String hostname) {
+    return host2DatanodeMap.getDataNodeByHostName(hostname);
+  }
+
   /** @return the datanode descriptor for the host. */
   public DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort) {
     return host2DatanodeMap.getDatanodeByXferAddr(host, xferPort);
@@ -1245,6 +1253,10 @@ public class DatanodeManager {
               + " is replaced by " + nodeReg + " with the same storageID "
               + nodeReg.getDatanodeUuid());
         }
+
+        if (!updateHost2DatanodeMap) {
+          updateHost2DatanodeMap = !nodeS.getHostName().equals(nodeReg.getHostName());
+        }
         
         boolean success = false;
         try {

+ 15 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeManager.java

@@ -174,6 +174,21 @@ public class TestDatanodeManager {
 
     assertNull("should be no node with old ip", dm.getDatanodeByHost(ipOld));
     assertNotNull("should be a node with new ip", dm.getDatanodeByHost(ipNew));
+
+    storageID = "someStorageID2";
+    String hostnameOld = "someHostNameOld" + storageID;
+    String hostnameNew = "someHostNameNew" + storageID;
+
+    dm.registerDatanode(new DatanodeRegistration(
+            new DatanodeID("ip", hostnameOld, storageID, 9000, 0, 0, 0),
+            null, null, "version"));
+
+    dm.registerDatanode(new DatanodeRegistration(
+            new DatanodeID("ip", hostnameNew, storageID, 9000, 0, 0, 0),
+            null, null, "version"));
+
+    assertNull("should be no node with old hostname", dm.getDatanodeByHostName(hostnameOld));
+    assertNotNull("should be a node with new hostname", dm.getDatanodeByHostName(hostnameNew));
   }
 
   /**