-
Notifications
You must be signed in to change notification settings - Fork 621
HDDS-15682. Use the original configured host and port to identify SCM nodes #10612
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
Changes from all commits
bceb1a0
48f9ba9
81f05ff
1c4e33d
7946f71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,11 +39,13 @@ | |||||
|
|
||||||
| import java.util.ArrayList; | ||||||
| import java.util.List; | ||||||
| import java.util.Objects; | ||||||
| import java.util.OptionalInt; | ||||||
| import net.jcip.annotations.Immutable; | ||||||
| import org.apache.hadoop.hdds.HddsUtils; | ||||||
| import org.apache.hadoop.hdds.conf.ConfigurationException; | ||||||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||||||
| import org.apache.hadoop.hdds.scm.net.HostAndPort; | ||||||
| import org.apache.hadoop.ozone.ha.ConfUtils; | ||||||
| import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | ||||||
|
|
@@ -60,10 +62,10 @@ public class SCMNodeInfo { | |||||
| private static final Logger LOG = LoggerFactory.getLogger(SCMNodeInfo.class); | ||||||
| private final String serviceId; | ||||||
| private final String nodeId; | ||||||
| private final String blockClientAddress; | ||||||
| private final String scmClientAddress; | ||||||
| private final String scmSecurityAddress; | ||||||
| private final String scmDatanodeAddress; | ||||||
| private final HostAndPort blockClientAddress; | ||||||
| private final HostAndPort scmClientAddress; | ||||||
| private final HostAndPort scmSecurityAddress; | ||||||
| private final HostAndPort scmDatanodeAddress; | ||||||
|
|
||||||
| /** | ||||||
| * Build SCM Node information from configuration. | ||||||
|
|
@@ -130,6 +132,9 @@ public static List<SCMNodeInfo> buildNodeInfo(ConfigurationSource conf) { | |||||
| String scmClientAddress = getHostNameFromConfigKeys(conf, | ||||||
| OZONE_SCM_CLIENT_ADDRESS_KEY, | ||||||
| OZONE_SCM_NAMES).orElse(null); | ||||||
| if (scmClientAddress == null) { | ||||||
| throw new ConfigurationException(OZONE_SCM_CLIENT_ADDRESS_KEY + " is not set"); | ||||||
| } | ||||||
|
|
||||||
| String scmBlockClientAddress = getHostNameFromConfigKeys(conf, | ||||||
| OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY).orElse(scmClientAddress); | ||||||
|
|
@@ -162,23 +167,19 @@ public static List<SCMNodeInfo> buildNodeInfo(ConfigurationSource conf) { | |||||
|
|
||||||
| scmNodeInfoList.add(new SCMNodeInfo(scmServiceId, | ||||||
| SCM_DUMMY_NODEID, | ||||||
| scmBlockClientAddress == null ? null : | ||||||
| buildAddress(scmBlockClientAddress, scmBlockClientPort), | ||||||
| scmClientAddress == null ? null : | ||||||
| buildAddress(scmClientAddress, scmClientPort), | ||||||
| scmSecurityClientAddress == null ? null : | ||||||
| buildAddress(scmSecurityClientAddress, scmSecurityPort), | ||||||
| scmDatanodeAddress == null ? null : | ||||||
| buildAddress(scmDatanodeAddress, scmDatanodePort))); | ||||||
| buildAddress(scmBlockClientAddress, scmBlockClientPort), | ||||||
| buildAddress(scmClientAddress, scmClientPort), | ||||||
| buildAddress(scmSecurityClientAddress, scmSecurityPort), | ||||||
| buildAddress(scmDatanodeAddress, scmDatanodePort))); | ||||||
|
|
||||||
| return scmNodeInfoList; | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| public static String buildAddress(String address, int port) { | ||||||
| return address + ':' + port; | ||||||
| private static HostAndPort buildAddress(String address, int port) { | ||||||
| return new HostAndPort(address, port); | ||||||
| } | ||||||
|
|
||||||
| public static int getPort(ConfigurationSource conf, | ||||||
|
|
@@ -209,14 +210,14 @@ public static int getPort(ConfigurationSource conf, | |||||
| * @param scmDatanodeAddress | ||||||
| */ | ||||||
| public SCMNodeInfo(String serviceId, String nodeId, | ||||||
| String blockClientAddress, String scmClientAddress, | ||||||
| String scmSecurityAddress, String scmDatanodeAddress) { | ||||||
| HostAndPort blockClientAddress, HostAndPort scmClientAddress, | ||||||
| HostAndPort scmSecurityAddress, HostAndPort scmDatanodeAddress) { | ||||||
| this.serviceId = serviceId; | ||||||
| this.nodeId = nodeId; | ||||||
| this.blockClientAddress = blockClientAddress; | ||||||
| this.scmClientAddress = scmClientAddress; | ||||||
| this.scmSecurityAddress = scmSecurityAddress; | ||||||
| this.scmDatanodeAddress = scmDatanodeAddress; | ||||||
| this.blockClientAddress = Objects.requireNonNull(blockClientAddress, "blockClientAddress == null"); | ||||||
| this.scmClientAddress = Objects.requireNonNull(scmClientAddress, "scmClientAddress == null"); | ||||||
| this.scmSecurityAddress = Objects.requireNonNull(scmSecurityAddress, "scmSecurityAddress == null"); | ||||||
| this.scmDatanodeAddress = Objects.requireNonNull(scmDatanodeAddress, "scmDatanodeAddress == null"); | ||||||
| } | ||||||
|
|
||||||
| public String getServiceId() { | ||||||
|
|
@@ -228,18 +229,22 @@ public String getNodeId() { | |||||
| } | ||||||
|
|
||||||
| public String getBlockClientAddress() { | ||||||
| return blockClientAddress; | ||||||
| return blockClientAddress.getHostAndPortString(); | ||||||
| } | ||||||
|
|
||||||
| public String getScmClientAddress() { | ||||||
| return scmClientAddress; | ||||||
| return scmClientAddress.getHostAndPortString(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| public String getScmDatanodeAddress() { | ||||||
| public HostAndPort getScmDatanodeHostPortAddress() { | ||||||
| return scmDatanodeAddress; | ||||||
| } | ||||||
|
|
||||||
| public String getScmDatanodeAddress() { | ||||||
| return scmDatanodeAddress.getHostAndPortString(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.scm.net; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import org.apache.hadoop.net.NetUtils; | ||
|
|
||
| /** | ||
| * A class for host and port. | ||
| * It also has an address which can be updated from time to time. | ||
| */ | ||
| public class HostAndPort { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor (naming): this collides with Guava's — Claude Code (AI-assisted review)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can replace Guava's |
||
| private final String host; | ||
| private final int port; | ||
| private final String hostAndPortString; | ||
| private final int hash; | ||
| /** The address can be updated from time to time. */ | ||
| private final InetSocketAddress address; | ||
|
|
||
| public HostAndPort(String host, int port) { | ||
| this.host = host; | ||
| this.port = port; | ||
| this.hostAndPortString = host + ":" + port; | ||
| this.hash = host.hashCode() ^ Integer.hashCode(port); | ||
| // TODO: HDDS-15533 change the address resolution logic and make this.address threadsafe. | ||
| this.address = NetUtils.createSocketAddr(hostAndPortString); | ||
| } | ||
|
|
||
| public String getHostName() { | ||
| return host; | ||
| } | ||
|
|
||
| public int getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| public String getHostAndPortString() { | ||
| return hostAndPortString; | ||
| } | ||
|
|
||
| public InetSocketAddress getAddress() { | ||
| return address; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return hash; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } else if (!(obj instanceof HostAndPort)) { | ||
| return false; | ||
| } | ||
| final HostAndPort that = (HostAndPort) obj; | ||
| // address must not be compared | ||
| return this.hash == that.hash | ||
| && this.port == that.port | ||
| && this.host.equals(that.host); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| final InetSocketAddress a = getAddress(); | ||
| final Object resolved = a != null && a.getAddress() != null ? a.getAddress() : "<unresolved>"; | ||
| return hostAndPortString + "/" + resolved; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
HostAndPortvariables inSCMNodeInfoare nevernull. Let's addObjects.requireNonNullin the constructor instead.