kerneltime commented on code in PR #10612:
URL: https://github.com/apache/ozone/pull/10612#discussion_r3479414557


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/HostAndPort.java:
##########
@@ -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 {
+  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);

Review 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)



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/HostAndPort.java:
##########
@@ -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 {

Review 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)



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/HostAndPort.java:
##########
@@ -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 {
+  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);
+  }
+
+  public HostAndPort(String host, int port) {
+    this(host, port, null);
+  }
+
+  public HostAndPort(InetSocketAddress address) {

Review 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)



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/EndpointStateMachine.java:
##########
@@ -180,7 +179,7 @@ public long getMissedCount() {
 
   @Override
   public String getAddressString() {
-    return getAddress().toString();
+    return getAddress().getHostAndPortString();

Review 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)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to