Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-1480. Prefer resolved datanode ip address over persisted ip address #7495

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ptlrs
Copy link
Contributor

@ptlrs ptlrs commented Nov 27, 2024

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.

The original task suggests removal of the IP address field.
Currently the IP address field of the DatanodeDetails class is used in several places.
So removal of the IP address field either from persistence or from usage is not straightforward. As an alternative, we resolve the IP address based on the hostname to detect if the IP address has changed.

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 unit test
  • Updated docker compose configuration to add a hostname for datanodes, without which we face UnknownHostException

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/12135607178
https://github.com/ptlrs/ozone/actions/runs/12627875515

@ptlrs ptlrs changed the title HDDS-1480. Verify if the saved ip address differs from the current datanode ip address HDDS-1480. Prefer resolved datanode ip address over persisted ip address Nov 27, 2024
@ptlrs ptlrs force-pushed the HDDS-1480-remove-ipaddress branch from fe2316f to 85546fa Compare November 27, 2024 21:14
@errose28 errose28 requested a review from swamirishi December 2, 2024 16:57
@ptlrs ptlrs force-pushed the HDDS-1480-remove-ipaddress branch from 85546fa to f0c156d Compare December 2, 2024 17:50
@ptlrs ptlrs force-pushed the HDDS-1480-remove-ipaddress branch from 3f0d40f to e35572c Compare December 3, 2024 08:21
@ptlrs ptlrs marked this pull request as ready for review December 3, 2024 16:47
@nandakumar131
Copy link
Contributor

@ptlrs, please avoid unnecessary formatting changes to the code, this makes it hard to review the logical changes done in the PR.

Copy link
Contributor

@swamirishi swamirishi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptlrs Thanks for the patch. The changes look good to me, excepting for some nitpicky changes. LGTM

if (!path.exists()) {
throw new IOException("Datanode ID file not found.");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why extra line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Although I do prefer to add space around if-clauses and in some places to have a logical grouping of statements.

Copy link
Contributor

@swamirishi swamirishi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @ptlrs thanks for the patch

@swamirishi
Copy link
Contributor

@nandakumar131 Do you want to take another look at the patch?

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ptlrs for the patch.

Comment on lines 195 to 205
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract the new logic to a separate method (preferably in DatanodeDetails). Previously readDatanodeDetailsFrom(File) did what its name said.

Comment on lines +157 to +158
private void assertWriteReadWithChangedIpAddress(@TempDir File tempDir,
DatanodeDetails details) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adoroszlai Can you please point me to any existing methods which follow the preferred format for my reference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

private void assertWriteRead(@TempDir File tempDir,
DatanodeDetails details) throws IOException {

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.

File file = new File(tempDir, "valid-values.id");
ContainerUtils.writeDatanodeDetailsTo(details, file, conf);
DatanodeDetails read = ContainerUtils.readDatanodeDetailsFrom(file);
assertNotEquals(details.toString(), read.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a bit stronger assertion about the IP address?

…ozone/container/common/helpers/ContainerUtils.java

Co-authored-by: Siyao Meng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants