-
Notifications
You must be signed in to change notification settings - Fork 622
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 1 commit
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |||||
| 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 +61,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. | ||||||
|
|
@@ -177,8 +178,8 @@ public static List<SCMNodeInfo> buildNodeInfo(ConfigurationSource conf) { | |||||
|
|
||||||
| } | ||||||
|
|
||||||
| 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,8 +210,8 @@ 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; | ||||||
|
|
@@ -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,92 @@ | ||
| /* | ||
| * 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 InetSocketAddress address; | ||
|
|
||
| private HostAndPort(String host, int port, InetSocketAddress address) { | ||
| this.host = host; | ||
| this.port = port; | ||
| this.hostAndPortString = host + ":" + port; | ||
| this.hash = host.hashCode() ^ Integer.hashCode(port); | ||
| this.address = address != null ? address : NetUtils.createSocketAddr(hostAndPortString); | ||
|
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. The constructor resolves eagerly. For the block/client/security addresses in — 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. Use
Contributor
Author
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.
Let's change the address resolution logic in HDDS-15533. This PR just do refactoring. |
||
| } | ||
|
|
||
| public HostAndPort(String host, int port) { | ||
| this(host, port, null); | ||
| } | ||
|
|
||
| public HostAndPort(InetSocketAddress address) { | ||
|
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.
— Claude Code (AI-assisted review)
Contributor
Author
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. This is only used in ContainerTestUtils. Let me change the code there. |
||
| this(address.getHostName(), address.getPort(), address); | ||
| } | ||
|
|
||
| public String getHostName() { | ||
| return host; | ||
| } | ||
|
|
||
| public int getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| public String getHostAndPortString() { | ||
| return hostAndPortString; | ||
| } | ||
|
|
||
| public synchronized InetSocketAddress getAddress() { | ||
|
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. why is this synchronized?
Contributor
Author
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. It is for HDDS-15533, which will update it. Actually, let's remove it here and add it there. |
||
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
|
|
||
| import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import java.io.Closeable; | ||
| import java.net.InetSocketAddress; | ||
| import java.time.ZonedDateTime; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
|
|
@@ -31,6 +30,7 @@ | |
| import java.util.concurrent.locks.Lock; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.scm.net.HostAndPort; | ||
| import org.apache.hadoop.ozone.protocol.VersionResponse; | ||
| import org.apache.hadoop.ozone.protocolPB.ReconDatanodeProtocolPB; | ||
| import org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolClientSideTranslatorPB; | ||
|
|
@@ -46,7 +46,7 @@ public class EndpointStateMachine | |
| LOG = LoggerFactory.getLogger(EndpointStateMachine.class); | ||
| private final StorageContainerDatanodeProtocolClientSideTranslatorPB endPoint; | ||
| private final AtomicLong missedCount; | ||
| private final InetSocketAddress address; | ||
| private final HostAndPort hostAndPort; | ||
| private final Lock lock; | ||
| private final ConfigurationSource conf; | ||
| private EndPointStates state = EndPointStates.FIRST; | ||
|
|
@@ -64,18 +64,17 @@ public class EndpointStateMachine | |
| * | ||
| * @param endPoint - RPC endPoint. | ||
| */ | ||
| public EndpointStateMachine(InetSocketAddress address, | ||
| public EndpointStateMachine(HostAndPort hostAndPort, | ||
| StorageContainerDatanodeProtocolClientSideTranslatorPB endPoint, | ||
| ConfigurationSource conf, String threadNamePrefix) { | ||
| this.endPoint = endPoint; | ||
| this.missedCount = new AtomicLong(0); | ||
| this.address = address; | ||
| this.hostAndPort = hostAndPort; | ||
| lock = new ReentrantLock(); | ||
| this.conf = conf; | ||
| executorService = Executors.newSingleThreadExecutor( | ||
| new ThreadFactoryBuilder() | ||
| .setNameFormat(threadNamePrefix + "EndpointStateMachineTaskThread-" | ||
| + this.address + "-%d ") | ||
| .setNameFormat(threadNamePrefix + "EndpointStateMachineTaskThread-" + hostAndPort + "-%d ") | ||
| .build()); | ||
| } | ||
|
|
||
|
|
@@ -180,7 +179,7 @@ public long getMissedCount() { | |
|
|
||
| @Override | ||
| public String getAddressString() { | ||
| return getAddress().toString(); | ||
| return getAddress().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.
— Claude Code (AI-assisted review) |
||
| } | ||
|
|
||
| public void zeroMissedCount() { | ||
|
|
@@ -192,8 +191,8 @@ public void zeroMissedCount() { | |
| * | ||
| * @return - EndPoint. | ||
| */ | ||
| public InetSocketAddress getAddress() { | ||
| return this.address; | ||
| public HostAndPort getAddress() { | ||
| return hostAndPort; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -213,7 +212,7 @@ public InetSocketAddress getAddress() { | |
| */ | ||
| @Override | ||
| public String toString() { | ||
| return address.toString(); | ||
| return hostAndPort.toString(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -236,14 +235,8 @@ public void logIfNeeded(Exception ex) { | |
| long missedDurationSeconds = TimeUnit.MILLISECONDS.toSeconds( | ||
| this.getMissedCount() * getScmHeartbeatInterval(this.conf) | ||
| ); | ||
| LOG.warn( | ||
| "Unable to communicate to {} server at {}:{} for past {} seconds.", | ||
| serverName, | ||
| address.getAddress(), | ||
| address.getPort(), | ||
| missedDurationSeconds, | ||
| ex | ||
| ); | ||
| LOG.warn("Unable to communicate to {} server at {} past {} seconds.", | ||
| serverName, hostAndPort, missedDurationSeconds, ex); | ||
| } | ||
|
|
||
| if (LOG.isTraceEnabled()) { | ||
|
|
||
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.