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


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +176,35 @@ public static synchronized DatanodeDetails 
readDatanodeDetailsFrom(File path)
     if (!path.exists()) {
       throw new IOException("Datanode ID file not found.");
     }
+    DatanodeDetails datanodeDetails;
     try {
-      return DatanodeIdYaml.readDatanodeIdFile(path);
+      datanodeDetails = DatanodeIdYaml.readDatanodeIdFile(path);
     } catch (IOException e) {
       LOG.warn("Error loading DatanodeDetails yaml from {}",
           path.getAbsolutePath(), e);
       // Try to load as protobuf before giving up
       try (FileInputStream in = new FileInputStream(path)) {
-        return DatanodeDetails.getFromProtoBuf(
+        datanodeDetails = DatanodeDetails.getFromProtoBuf(
             HddsProtos.DatanodeDetailsProto.parseFrom(in));
       } catch (IOException io) {
         throw new IOException("Failed to parse DatanodeDetails from "
             + path.getAbsolutePath(), io);
       }
     }
+
+    try {
+      InetAddress inetAddress = 
InetAddress.getByName(datanodeDetails.getHostName());
+
+      if 
(!inetAddress.getHostAddress().equals(datanodeDetails.getIpAddress())) {
+        LOG.warn("Resolved IP address '{}' differs from the persisted IP 
address '{}' for the datanode '{}'",
+            inetAddress.getHostAddress(), datanodeDetails.getIpAddress(), 
datanodeDetails.getHostName());
+        datanodeDetails.setIpAddress(inetAddress.getHostAddress());
+      }
+    } catch (UnknownHostException e) {
+      LOG.warn("Failed to validate IP address for the datanode '{}'", 
datanodeDetails.getHostName(), e);
+    }

Review Comment:
   Fixed



##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/helpers/TestContainerUtils.java:
##########
@@ -133,6 +154,15 @@ private void assertWriteRead(@TempDir File tempDir,
     assertEquals(details.getCurrentVersion(), read.getCurrentVersion());
   }
 
+  private void assertWriteReadWithChangedIpAddress(@TempDir File tempDir,
+                                                   DatanodeDetails details) 
throws IOException {

Review Comment:
   Fixed



##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/helpers/TestContainerUtils.java:
##########
@@ -133,6 +154,15 @@ private void assertWriteRead(@TempDir File tempDir,
     assertEquals(details.getCurrentVersion(), read.getCurrentVersion());
   }
 
+  private void assertWriteReadWithChangedIpAddress(@TempDir File tempDir,
+                                                   DatanodeDetails details) 
throws IOException {
+    // Write a single ID to the file and read it out
+    File file = new File(tempDir, "valid-values.id");
+    ContainerUtils.writeDatanodeDetailsTo(details, file, conf);
+    DatanodeDetails read = ContainerUtils.readDatanodeDetailsFrom(file);
+    assertNotEquals(details.toString(), read.toString());

Review Comment:
   Fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to