ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1991883444


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -175,6 +177,29 @@ public void setIpAddress(String ip) {
     this.ipAddress = StringWithByteString.valueOf(ip);
   }
 
+  /**
+   * Resolves and validates the IP address of the datanode based on its 
hostname.
+   * If the resolved IP address differs from the current IP address,
+   * it updates the IP address to the newly resolved value and logs a warning.
+   */
+  public void validateDatanodeIpAddress() {
+    if (getIpAddress() == null) {
+      return;
+    }
+
+    try {
+      InetAddress inetAddress = InetAddress.getByName(getHostName());
+
+      if (!inetAddress.getHostAddress().equals(getIpAddress())) {
+        LOG.warn("Using resolved IP address '{}' as it differs from the 
persisted IP address '{}' for datanode '{}'",
+            inetAddress.getHostAddress(), getIpAddress(), getHostName());
+        setIpAddress(inetAddress.getHostAddress());
+      }
+    } catch (UnknownHostException e) {
+      LOG.warn("Failed to validate IP address for the datanode '{}'", 
getHostName(), e);
+    }

Review Comment:
   Thanks for the detailed review @adoroszlai. I have applied your suggestions. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to