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


##########
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:
   Good catch! I've updated it to compare IPv6 literals canonically while 
preserving the scope as text and add tests.



##########
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:
   Good catch! I've updated it to compare IPv6 literals canonically while 
preserving the scope as text and added tests.



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