adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1991214646
##########
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:
- Let's use local variables to make it a bit easier to follow, and ensure
consistency of values.
- Changing IP address is normal, I think it can be logged at info level.
- Use `this` instead of `getHostName()` in the messages, since
`DatanodeDetails#toString` shows UUID, IP and hostname. (UUID is especially
useful in tests where multiple datanodes may be running on the same host.)
https://github.com/apache/ozone/blob/df4def4077319ff2854b9eedea876db32db6b7d1/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java#L648-L649
```java
final String oldIP = getIpAddress();
final String hostname = getHostName();
if (StringUtils.isBlank(hostname)) {
return;
}
try {
final String newIP = InetAddress.getByName(hostname).getHostAddress();
if (StringUtils.isNotBlank(newIP) && !newIP.equals(oldIP)) {
LOG.info("Updating IP address of datanode {} to {}", this, newIP);
setIpAddress(newIP);
}
} catch (UnknownHostException e) {
LOG.warn("Could not resolve IP address of datanode {}", this, e);
}
```
--
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]