HDDS-15682. Use the original configured host and port to identify SCM nodes#10612
HDDS-15682. Use the original configured host and port to identify SCM nodes#10612szetszwo wants to merge 4 commits into
Conversation
|
|
||
| public String getBlockClientAddress() { | ||
| return blockClientAddress; | ||
| return blockClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
| return blockClientAddress.getHostAndPortString(); | |
| return blockClientAddress == null ? null : blockClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
These HostAndPort variables in SCMNodeInfo are never null. Let's add Objects.requireNonNull in the constructor instead.
|
|
||
| public String getScmClientAddress() { | ||
| return scmClientAddress; | ||
| return scmClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
| return scmClientAddress.getHostAndPortString(); | |
| return scmClientAddress == null ? null : scmClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
For comments along the same line, it is better to suggest one change and mention that the suggestion applies to other parts of the code. This makes the review less verbose, plus others do not need to respond to each similar comment.
|
|
||
| public String getScmSecurityAddress() { | ||
| return scmSecurityAddress; | ||
| return scmSecurityAddress.getHostAndPortString(); |
There was a problem hiding this comment.
| return scmSecurityAddress.getHostAndPortString(); | |
| return scmSecurityAddress == null ? null : scmSecurityAddress.getHostAndPortString(); |
| } | ||
|
|
||
| public String getScmDatanodeAddress() { | ||
| return scmDatanodeAddress.getHostAndPortString(); |
There was a problem hiding this comment.
| return scmDatanodeAddress.getHostAndPortString(); | |
| return scmDatanodeAddress == null ? null : scmDatanodeAddress.getHostAndPortString(); |
| return hostAndPortString; | ||
| } | ||
|
|
||
| public synchronized InetSocketAddress getAddress() { |
There was a problem hiding this comment.
why is this synchronized?
There was a problem hiding this comment.
It is for HDDS-15533, which will update it. Actually, let's remove it here and add it there.
kerneltime
left a comment
There was a problem hiding this comment.
Keying SCM identity on configured host+port rather than the resolved InetSocketAddress reads as a sound fix for the IP-churn problem. A few non-blocking notes from an AI-assisted review pass below — all minor/cleanup, nothing that blocks merge.
| * A class for host and port. | ||
| * It also has an address which can be updated from time to time. | ||
| */ | ||
| public class HostAndPort { |
There was a problem hiding this comment.
Minor (naming): this collides with Guava's com.google.common.net.HostAndPort, which is already imported in this same module at HddsUtils.java:36. It also lives in scm.net, which package-info scopes to network topology (NetworkTopology/Node/…) and which already has its own NetUtils — so the import org.apache.hadoop.net.NetUtils here shadows the same-package type. A more specific name/home (e.g. ScmEndpoint) would avoid both. Cheap while the type is new.
— Claude Code (AI-assisted review)
There was a problem hiding this comment.
We can replace Guava's HostAndPort with this. (Can be done in follow-up if considered out-of-scope.)
| this.port = port; | ||
| this.hostAndPortString = host + ":" + port; | ||
| this.hash = host.hashCode() ^ Integer.hashCode(port); | ||
| this.address = address != null ? address : NetUtils.createSocketAddr(hostAndPortString); |
There was a problem hiding this comment.
The constructor resolves eagerly. For the block/client/security addresses in SCMNodeInfo the resolved value is never read — those getters return only getHostAndPortString(), and the string consumers re-resolve it (e.g. HddsUtils.getScmAddressForClients and StorageContainerManager both call NetUtils.createSocketAddr on it again) — so each ends up resolved twice and this result is discarded. Resolving lazily inside getAddress() would drop the duplicate lookup and also fits the "address can be updated from time to time" intent.
— Claude Code (AI-assisted review)
There was a problem hiding this comment.
Use InetSocketAddress.createUnresolved(host, port) directly instead of Hadoop's NetUtils.createSocketAddr. The latter parses the string, into host and port (so we can save this processing), and handles more complex cases that we do not need here.
There was a problem hiding this comment.
The constructor resolves eagerly ...
Use InetSocketAddress.createUnresolved(host, port) directly ...
Let's change the address resolution logic in HDDS-15533. This PR just do refactoring.
| this(host, port, null); | ||
| } | ||
|
|
||
| public HostAndPort(InetSocketAddress address) { |
There was a problem hiding this comment.
equals/hashCode key on host, but this ctor derives host from address.getHostName() while the other uses the raw configured string. Those can differ (IP literal vs configured name), so two instances for the same node could be unequal and miss in the endpoint maps. It looks like this ctor is test-only today, so it's latent — but since stable host-string identity is the point of the change, might be worth dropping it or documenting that callers must use one consistent spelling.
— Claude Code (AI-assisted review)
There was a problem hiding this comment.
This is only used in ContainerTestUtils. Let me change the code there.
| @Override | ||
| public String getAddressString() { | ||
| return getAddress().toString(); | ||
| return getAddress().getHostAndPortString(); |
There was a problem hiding this comment.
getAddressString() is part of EndpointStateMachineMBean, so this shifts the JMX value from host/ip:port to host:port (drops the resolved IP). Intentional? Flagging only in case any monitoring parses it.
— Claude Code (AI-assisted review)
|
I addressed the review comments and redid the DNS fix at szetszwo#11 please take a look. |
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @szetszwo for the patch.
|
|
||
| public String getBlockClientAddress() { | ||
| return blockClientAddress; | ||
| return blockClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
These HostAndPort variables in SCMNodeInfo are never null. Let's add Objects.requireNonNull in the constructor instead.
|
|
||
| public String getScmClientAddress() { | ||
| return scmClientAddress; | ||
| return scmClientAddress.getHostAndPortString(); |
There was a problem hiding this comment.
For comments along the same line, it is better to suggest one change and mention that the suggestion applies to other parts of the code. This makes the review less verbose, plus others do not need to respond to each similar comment.
| this.port = port; | ||
| this.hostAndPortString = host + ":" + port; | ||
| this.hash = host.hashCode() ^ Integer.hashCode(port); | ||
| this.address = address != null ? address : NetUtils.createSocketAddr(hostAndPortString); |
There was a problem hiding this comment.
Use InetSocketAddress.createUnresolved(host, port) directly instead of Hadoop's NetUtils.createSocketAddr. The latter parses the string, into host and port (so we can save this processing), and handles more complex cases that we do not need here.
| * A class for host and port. | ||
| * It also has an address which can be updated from time to time. | ||
| */ | ||
| public class HostAndPort { |
There was a problem hiding this comment.
We can replace Guava's HostAndPort with this. (Can be done in follow-up if considered out-of-scope.)
What changes were proposed in this pull request?
The data structures such as SCMConnectionManager.scmMachines, StateContext.endpoint, etc. use InetSocketAddress to identify SCM nodes. Since the InetSocketAddress can changed in some environment such as Kubernetes, it is better to use the original configured host and port instead of the resolved InetSocketAddress.
What is the link to the Apache JIRA
HDDS-15682
How was this patch tested?
Updating existing tests.