smengcl commented on code in PR #10807:
URL: https://github.com/apache/ozone/pull/10807#discussion_r3756051855


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/proxy/SCMFailoverProxyProviderBase.java:
##########
@@ -249,24 +249,46 @@ public synchronized void 
performFailoverToAssignedLeader(String newLeader,
                                                            Exception e) {
     ServerNotLeaderException snle =
         (ServerNotLeaderException) SCMHAUtils.getServerNotLeaderException(e);
-    if (snle != null && snle.getSuggestedLeader() != null) {
-      Optional<SCMProxyInfo> matchedProxyInfo =
-          scmProxyInfoMap.values().stream().filter(
-              proxyInfo -> NetUtils.getHostPortString(proxyInfo.getAddress())
-                  .equals(snle.getSuggestedLeader())).findFirst();
-      if (matchedProxyInfo.isPresent()) {
-        newLeader = matchedProxyInfo.get().getNodeId();
+    String suggestedLeader = snle != null ? snle.getSuggestedLeader() : null;
+    if (suggestedLeader != null) {
+      Optional<String> matchedNodeId = 
findSuggestedLeaderNodeId(suggestedLeader);
+      if (matchedNodeId.isPresent()) {
+        newLeader = matchedNodeId.get();
         getLogger().debug("Performing failover to suggested leader {}, nodeId 
{}",
-            snle.getSuggestedLeader(), newLeader);
+            suggestedLeader, newLeader);
       } else {
         getLogger().debug("Suggested leader {} does not match with any of the 
" +
-                "proxyInfo address {}", snle.getSuggestedLeader(),
+                "proxyInfo address {}", suggestedLeader,
             Arrays.toString(scmProxyInfoMap.values().toArray()));
       }
     }
     assignLeaderToNode(newLeader);
   }
 
+  /**
+   * Resolve the suggested-leader authority to a known SCM nodeId. First try a
+   * DNS-free string match against the cached proxy authorities; only when that
+   * misses (for example a bracketed IPv6 literal, whose cached authority is 
not
+   * bracketed) fall back to a resolved-address comparison, the one branch that
+   * may perform a DNS lookup. Returns empty when nothing matches or the
+   * authority cannot be parsed.
+   */
+  private Optional<String> findSuggestedLeaderNodeId(String suggestedLeader) {
+    Optional<SCMProxyInfo> matchedProxyInfo = 
scmProxyInfoMap.values().stream().filter(
+        proxyInfo -> 
NetUtils.getHostPortString(proxyInfo.getAddress()).equals(suggestedLeader))
+        .findFirst();
+    if (!matchedProxyInfo.isPresent()) {
+      try {
+        InetSocketAddress suggestedLeaderAddress = 
NetUtils.createSocketAddr(suggestedLeader);
+        matchedProxyInfo = scmProxyInfoMap.values().stream().filter(
+            proxyInfo -> 
proxyInfo.getAddress().equals(suggestedLeaderAddress)).findFirst();

Review Comment:
   `InetSocketAddress.equals` does not compare IPv6 scope IDs. With entries at 
`[fe80::1%1]:9863` and `[fe80::1%2]:9863`, this fallback treats both addresses 
as equal; a regression test shows a `%2` hint selecting the `%1` SCM. This can 
pin failover to the wrong node. Please preserve the scope when comparing 
authorities and add same-address/different-scope coverage.



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/proxy/SCMFailoverProxyProviderBase.java:
##########
@@ -249,24 +249,46 @@ public synchronized void 
performFailoverToAssignedLeader(String newLeader,
                                                            Exception e) {
     ServerNotLeaderException snle =
         (ServerNotLeaderException) SCMHAUtils.getServerNotLeaderException(e);
-    if (snle != null && snle.getSuggestedLeader() != null) {
-      Optional<SCMProxyInfo> matchedProxyInfo =
-          scmProxyInfoMap.values().stream().filter(
-              proxyInfo -> NetUtils.getHostPortString(proxyInfo.getAddress())
-                  .equals(snle.getSuggestedLeader())).findFirst();
-      if (matchedProxyInfo.isPresent()) {
-        newLeader = matchedProxyInfo.get().getNodeId();
+    String suggestedLeader = snle != null ? snle.getSuggestedLeader() : null;
+    if (suggestedLeader != null) {
+      Optional<String> matchedNodeId = 
findSuggestedLeaderNodeId(suggestedLeader);
+      if (matchedNodeId.isPresent()) {
+        newLeader = matchedNodeId.get();
         getLogger().debug("Performing failover to suggested leader {}, nodeId 
{}",
-            snle.getSuggestedLeader(), newLeader);
+            suggestedLeader, newLeader);
       } else {
         getLogger().debug("Suggested leader {} does not match with any of the 
" +
-                "proxyInfo address {}", snle.getSuggestedLeader(),
+                "proxyInfo address {}", suggestedLeader,
             Arrays.toString(scmProxyInfoMap.values().toArray()));
       }
     }
     assignLeaderToNode(newLeader);
   }
 
+  /**
+   * Resolve the suggested-leader authority to a known SCM nodeId. First try a
+   * DNS-free string match against the cached proxy authorities; only when that
+   * misses (for example a bracketed IPv6 literal, whose cached authority is 
not
+   * bracketed) fall back to a resolved-address comparison, the one branch that
+   * may perform a DNS lookup. Returns empty when nothing matches or the
+   * authority cannot be parsed.
+   */
+  private Optional<String> findSuggestedLeaderNodeId(String suggestedLeader) {
+    Optional<SCMProxyInfo> matchedProxyInfo = 
scmProxyInfoMap.values().stream().filter(
+        proxyInfo -> 
NetUtils.getHostPortString(proxyInfo.getAddress()).equals(suggestedLeader))
+        .findFirst();
+    if (!matchedProxyInfo.isPresent()) {
+      try {
+        InetSocketAddress suggestedLeaderAddress = 
NetUtils.createSocketAddr(suggestedLeader);

Review Comment:
   `performFailoverToAssignedLeader` is synchronized, so this call may perform 
DNS resolution while holding the provider monitor. A slow or 
client-unresolvable suggested-leader hostname can therefore block concurrent 
proxy and failover operations. The nearby `refreshProxyAddressIfChanged` path 
explicitly resolves outside this monitor. Please keep literal-address 
normalization DNS-free or move resolution outside the synchronized section.



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