adoroszlai commented on code in PR #3185:
URL: https://github.com/apache/ozone/pull/3185#discussion_r865317097


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java:
##########
@@ -448,6 +448,16 @@ public final class OzoneConfigKeys {
   public static final boolean OZONE_CLIENT_KEY_LATEST_VERSION_LOCATION_DEFAULT 
=
       true;
 
+  public static final String OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED =
+          "ozone.flexible.fqdn.resolution.enabled";
+  public static final boolean OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED_DEFAULT =
+          false;
+
+  public static final String OZONE_JVM_NETWORK_ADDRESS_CACHE_ENABLED =
+          "ozone.jvm.network.address.cache.enabled";
+  public static final boolean OZONE_JVM_NETWORK_ADDRESS_CACHE_ENABLED_DEFAULT =
+          true;
+

Review Comment:
   I think it would be useful to group these config keys by adding a common 
prefix (after `ozone.`):
   
    * `ozone.network.flexible.fqdn.resolution.enabled`
    * `ozone.network.jvm.address.cache.enabled`



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHANodeDetails.java:
##########
@@ -227,13 +230,22 @@ public static SCMHANodeDetails 
loadSCMHAConfig(OzoneConfiguration conf)
           throw e;
         }
 
-        if (addr.isUnresolved()) {
+        boolean flexibleFqdnResolutionEnabled = conf.getBoolean(
+                OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED,
+                OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED_DEFAULT);
+        if (!flexibleFqdnResolutionEnabled && addr.isUnresolved()
+                || flexibleFqdnResolutionEnabled
+                && !isAddressHostNameLocal(addr)) {
           LOG.error("Address for SCM {} : {} couldn't be resolved. Proceeding "
                   + "with unresolved host to create Ratis ring.", nodeId,
               rpcAddrStr);
         }
 
-        if (!addr.isUnresolved() && !isPeer && ConfUtils.isAddressLocal(addr)) 
{
+        if (!isPeer && (!flexibleFqdnResolutionEnabled
+                && !addr.isUnresolved()
+                && ConfUtils.isAddressLocal(addr)
+                || flexibleFqdnResolutionEnabled
+                && isAddressHostNameLocal(addr))) {

Review Comment:
   Also for this condition, something like this:
   
   ```suggestion
           if (!isPeer && isAddressLocal(addr, conf)) {
   ```



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ha/ConfUtils.java:
##########
@@ -69,6 +69,9 @@ public static String concatSuffixes(String... suffixes) {
    * Return true if it matches, false otherwsie.
    */
   public static boolean isAddressLocal(InetSocketAddress addr) {
+    if (addr.getAddress() == null) {
+      return false;
+    }
     return NetUtils.isLocalAddress(addr.getAddress());

Review Comment:
   Nit: store value locally and simplify condition.
   
   ```suggestion
       InetAddress addr = addr.getAddress();
       return addr != null && NetUtils.isLocalAddress(addr.getAddress());
   ```



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java:
##########
@@ -151,6 +152,8 @@ private static HddsDatanodeService 
createHddsDatanodeService(
 
   public static void main(String[] args) {
     try {
+      FlexibleFQDNResolution.disableJvmNetworkAddressCacheIfRequired(
+              new OzoneConfiguration());

Review Comment:
   I think S3 Gateway and Recon could benefit from the same setting.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHANodeDetails.java:
##########
@@ -227,13 +230,22 @@ public static SCMHANodeDetails 
loadSCMHAConfig(OzoneConfiguration conf)
           throw e;
         }
 
-        if (addr.isUnresolved()) {
+        boolean flexibleFqdnResolutionEnabled = conf.getBoolean(
+                OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED,
+                OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED_DEFAULT);
+        if (!flexibleFqdnResolutionEnabled && addr.isUnresolved()
+                || flexibleFqdnResolutionEnabled
+                && !isAddressHostNameLocal(addr)) {

Review Comment:
   I think it would be nice to create a helper method to avoid repeating this 
condition.
   
   ```suggestion
           if (isUnresolved(addr, conf)) {
   ```



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ha/FlexibleFQDNResolution.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.ozone.ha;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.net.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetSocketAddress;
+import java.security.Security;
+
+import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_JVM_NETWORK_ADDRESS_CACHE_ENABLED;
+import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_JVM_NETWORK_ADDRESS_CACHE_ENABLED_DEFAULT;
+
+/**
+ * FQDN related utils. Provides methods related to local host name and
+ * jvm network address cache. This utils is mainly used in kubernetes where
+ * the FQDN [pod_name].[service_name] is not resolvable at the service
+ * starting time.
+ */
+public final class FlexibleFQDNResolution {

Review Comment:
   I would change this class to a bit more generic Ozone-specific network 
utility.
   
   1. Rename to `OzoneNetUtils` (or similar)
   2. Move to a non-`ha`-specific package, e.g. `org/apache/hadoop/ozone/util` 
or `org/apache/hadoop/hdds/utils`.
   3. Move `isAddressLocal` from `ConfUtils` to this class.
   4. Also add the suggested new `isUnresolved` and `isAddressLocal` methods in 
this class.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java:
##########
@@ -56,6 +57,8 @@ public class StorageContainerManagerStarter extends 
GenericCli {
       LoggerFactory.getLogger(StorageContainerManagerStarter.class);
 
   public static void main(String[] args) {
+    FlexibleFQDNResolution.disableJvmNetworkAddressCacheIfRequired(
+            new OzoneConfiguration());

Review Comment:
   Same comment here about `commonInit()`.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerStarter.java:
##########
@@ -51,6 +52,8 @@ public class OzoneManagerStarter extends GenericCli {
       LoggerFactory.getLogger(OzoneManagerStarter.class);
 
   public static void main(String[] args) throws Exception {
+    FlexibleFQDNResolution.disableJvmNetworkAddressCacheIfRequired(
+            new OzoneConfiguration());

Review Comment:
   Instead of creating a `new OzoneConfiguration`, can we place this call in 
`commonInit`?  Or is that too late?
   
   
https://github.com/apache/ozone/blob/a3f5021b23cc09af95f9053511a9624dab226029/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerStarter.java#L166-L168



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