You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "ptlrs (via GitHub)" <gi...@apache.org> on 2024/11/27 05:12:05 UTC
[PR] HDDS-1480. Verify if the saved ip address differs from the current datanode ip address [ozone]
ptlrs opened a new pull request, #7495:
URL: https://github.com/apache/ozone/pull/7495
Please describe your PR in detail:
`DatanodeDetails` is persisted by `ContainerUtils` and `DatanodeIdYaml` classes.
The IP address in `DatanodeDetails` is also persisted.
However, the IP address could have changed when reading back the persisted file.
As part of this change:
- Obtain the hostname's IP address and compare it with the persisted IP address
- If the IP addresses are different, prefer the resolved IP address as it is the latest
- Warn about the possible discrepancy
- Added a test
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-1480
## How was this patch tested?
CI: https://github.com/ptlrs/ozone/actions/runs/12044106534
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2741332400
@errose28 @swamirishi please take a look
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1892314730
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
Review Comment:
nit: Can we avoid this non meaningful refactoring here. We can do this as part of refactoring jira
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1914496914
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
@ptlrs The code excerpt (in my previous comment) from `HddsDatanodeService` is executed during datanode startup. `initializeDatanodeDetails` will read from file (for restart) or create from scratch (for first run). In both cases, `HddsDatanodeService` unconditionally sets the hostname and IP address after `initializeDatanodeDetails`.
Therefore, with `validateDatanodeIpAddress` called from `readDatanodeDetailsFrom` called from `initializeDatanodeDetails`:
1. the host name being checked by `validateDatanodeIpAddress` may be out of date
2. the IP address set by `validateDatanodeIpAddress` will be overwritten
This can be confirmed by adding log statement to `DatanodeDetails.setIpAddress`.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2759088117
@errose28 would you like to take a look?
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2771254304
Thank you for the extensive reviews @jojochuang @adoroszlai @swamirishi @nandakumar131 @smengcl.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1914496914
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
@ptlrs The code excerpt (in my previous comment) from `HddsDatanodeService` is executed during datanode startup. `initializeDatanodeDetails` will read from file (for restart) or create from scratch (for first run). In both cases, `HddsDatanodeService` unconditionally sets the hostname and IP address after `initializeDatanodeDetails`.
Therefore, with `validateDatanodeIpAddress` called from `readDatanodeDetailsFrom` called from `initializeDatanodeDetails`:
1. the host name being checked by `validateDatanodeIpAddress` may be out of date
2. the IP address set by `validateDatanodeIpAddress` will be overwritten
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2770691096
Merged, given the prior reviews and approvals.
Thanks @ptlrs @swamirishi @adoroszlai @nandakumar131 @smengcl
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1903729121
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
- throws IOException {
+ public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException {
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1910008554
##########
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:
@adoroszlai Can you please point me to any existing methods which follow the preferred format for my reference.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1990777409
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
Yes, I think it's completely OK to read a file with possibly bad content, and validate it in a separate step.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1903732996
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/helpers/TestContainerUtils.java:
##########
@@ -133,6 +154,17 @@ 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);
+
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1912388801
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
Sorry if it was not clear from the previous [comment](https://github.com/apache/ozone/pull/7495#discussion_r1905009590), but IP validation shouldn't be called when reading the file, rather:
https://github.com/apache/ozone/blob/0e5e5b7bcfa65795b7c60828de6146b727a3e363/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java#L227-L232
BTW, looking at this existing initialization logic, I wonder if the new IP validation logic is still needed. If it is, then it must be called after setting both hostname and IP, otherwise these would overwrite the values from `validateDatanodeIpAddress()`.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1905012325
##########
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:
nit: Please do not format method signature like this. Whenever visibility / return type / method name / other modifiers are changed, we would have to reindent all parameters.
##########
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:
Can you please add a bit stronger assertion about the IP address?
##########
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:
Please extract the new logic to a separate method (preferably in `DatanodeDetails`). Previously `readDatanodeDetailsFrom(File)` did what its name said.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2720256424
Thanks @ptlrs for updating the patch, LGTM.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1992479561
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -175,6 +178,34 @@ 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.
+ */
+ public void validateDatanodeIpAddress() {
+ final String oldIP = getIpAddress();
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1990762098
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
@adoroszlai I agree that `HddsDatanodeService` will overwrite the ip address in this instance and render the point of validating the IP address moot. Also, since `HddsDatanodeService` is setting the IP address after reading the file, there is likely no need of any extra validation logic there as that IP address is expected to be valid.
I am however not convinced that IP validation shouldn't be called when reading the file.
The question is about expectations from the `readDatanodeDetailsFrom` method in any different situation. Is it valid to expect a `DatanodeDetails` object from `readDatanodeDetailsFrom()` where the IP address and hostname do not match?
At the least, can we set the IP address in such a situation to be `null` rather than an incorrect value? We could update the `DatanodeDetails` class so that any `get` access to a null IP address would first and only once be resolved to a valid IP address based on the hostname.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "smengcl (via GitHub)" <gi...@apache.org>.
smengcl commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1905017315
##########
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 '{}'",
Review Comment:
nit
```suggestion
LOG.warn("Resolved IP address '{}' differs from the persisted IP address '{}' for datanode '{}'. Will use the resolved IP address from now on",
```
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2574491288
@nandakumar131 Do you want to take another look at the patch?
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r2023653981
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -175,13 +178,41 @@ 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.
+ */
+ public void validateDatanodeIpAddress() {
+ final String oldIP = getIpAddress();
+ final String hostname = getHostName();
+ if (StringUtils.isBlank(hostname)) {
+ LOG.warn("Could not resolve IP address of datanode '{}'", this);
+ return;
+ }
+
+ try {
+ final String newIP = InetAddress.getByName(hostname).getHostAddress();
+ if (StringUtils.isBlank(newIP)) {
+ throw new UnknownHostException("New IP address is invalid: " + newIP);
+ }
+
+ if (!newIP.equals(oldIP)) {
+ LOG.info("Updating IP address of datanode {} to {}", this, newIP);
Review Comment:
this.toString() format is "UUID(hostname/old_ip_address)" so this log would become
Updating IP address of datanode UUID(hostname/old_ip_address) to new_ip_address
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang merged PR #7495:
URL: https://github.com/apache/ozone/pull/7495
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1892314730
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
Review Comment:
nit: Can we avoid this non meaningful refactoring here. We can do this as part of refactoring jira
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1910061386
##########
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:
I don't think there is any strong preference we agreed on, but you can't go wrong by following existing style from the same file being edited:
https://github.com/apache/ozone/blob/f1fdd50ce0e01a578ab0b31b65cb53611f514eb5/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/helpers/TestContainerUtils.java#L145-L146
Some would argue for:
- putting each argument on a separate line vs. grouping few of them while respecting line length limit
- putting the first argument on its own line
Consistent formatting has benefits, but coming to agreement is not easy, and reformatting all existing code makes backports harder initially.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1903732189
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
- throws IOException {
+ public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException {
if (!path.exists()) {
throw new IOException("Datanode ID file not found.");
}
+
Review Comment:
Fixed. Although I do prefer to add space around if-clauses and in some places to have a logical grouping of statements.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1892316482
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
- throws IOException {
+ public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException {
Review Comment:
nit: Can we avoid this non meaningful refactoring here. We can do this as part of refactoring jira
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/helpers/TestContainerUtils.java:
##########
@@ -133,6 +154,17 @@ 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);
+
Review Comment:
nit: Avoid extra lines
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -169,25 +171,37 @@ public static synchronized void writeDatanodeDetailsTo(
* @return {@link DatanodeDetails}
* @throws IOException If the id file is malformed or other I/O exceptions
*/
- public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path)
- throws IOException {
+ public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path) throws IOException {
if (!path.exists()) {
throw new IOException("Datanode ID file not found.");
}
+
Review Comment:
Why extra line?
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #7495:
URL: https://github.com/apache/ozone/pull/7495#issuecomment-2548052278
@ptlrs, please avoid unnecessary formatting changes to the code, this makes it hard to review the logical changes done in the PR.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r2023653981
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -175,13 +178,41 @@ 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.
+ */
+ public void validateDatanodeIpAddress() {
+ final String oldIP = getIpAddress();
+ final String hostname = getHostName();
+ if (StringUtils.isBlank(hostname)) {
+ LOG.warn("Could not resolve IP address of datanode '{}'", this);
+ return;
+ }
+
+ try {
+ final String newIP = InetAddress.getByName(hostname).getHostAddress();
+ if (StringUtils.isBlank(newIP)) {
+ throw new UnknownHostException("New IP address is invalid: " + newIP);
+ }
+
+ if (!newIP.equals(oldIP)) {
+ LOG.info("Updating IP address of datanode {} to {}", this, newIP);
Review Comment:
this.toString() format is "UUID(hostname/old_ip_address)" so this log would become
Updating IP address of datanode UUID(hostname/old_ip_address) to new_ip_address
It may look confusing initially but okay.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1914386689
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
Hi @adoroszlai, this PR is concerned with the case where you rebuild the DatanodeDetails object based on the information saved prior in a file. When we deserialize the contents of the file into DatanodeDetails, the IP address could have changed and the persisted IP address may no longer be valid (ex. the datanode may have been re-started on a new machine). So that is the reason for validating the IP address when we read the file.
I agree there is no need to validate the IP address if we are building DatanodeDetails object without any serialization/deserialization.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
ptlrs commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1990868895
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java:
##########
@@ -174,20 +174,25 @@ 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);
}
}
+
+ datanodeDetails.validateDatanodeIpAddress();
Review Comment:
Got it, I have updated the code to remove the validation when reading the file.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #7495:
URL: https://github.com/apache/ozone/pull/7495#discussion_r1992002919
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java:
##########
@@ -175,6 +178,34 @@ 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.
+ */
+ public void validateDatanodeIpAddress() {
+ final String oldIP = getIpAddress();
Review Comment:
```
NullPointerException: Cannot invoke "org.apache.hadoop.ozone.util.StringWithByteString.getString()" because "this.ipAddress" is null
```
Sorry, it looks like we need to handle `ipAddress == null` case in `getIpAddress()` and `getHostName()`.
--
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-1480. Prefer resolved datanode ip address over persisted ip address [ozone]
Posted by "ptlrs (via GitHub)" <gi...@apache.org>.
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-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org