slfan1989 commented on code in PR #9019:
URL: https://github.com/apache/hadoop/pull/9019#discussion_r4729942131


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java:
##########
@@ -944,46 +943,102 @@ public NodeInfo getNode(String nodeId) {
     }
 
     if (nodeInfo == null) {
-      throw new NotFoundException("nodeId, " + nodeId + ", is not found");
+      throwNodeNotResolvable(nodeId, fanout.failedSubClusters,
+          "nodeId, " + nodeId + ", is not found");
     }
     return nodeInfo;
   }
 
+  /**
+   * Throws the exception that matches a fan-out in which no subcluster hosts
+   * the node: {@link NotFoundException} when every subcluster answered, or a
+   * {@link YarnRuntimeException} when at least one lookup failed, because
+   * "not found" would be a wrong answer when the subcluster owning the node
+   * may not have been checked at all (YARN-12069).
+   */
+  private static void throwNodeNotResolvable(String nodeId,
+      List<SubClusterId> failedSubClusters, String notFoundMessage) {
+    if (!failedSubClusters.isEmpty()) {
+      throw new YarnRuntimeException("Cannot determine the subcluster hosting "
+          + nodeId + ": node lookup failed on subcluster(s) "
+          + failedSubClusters);
+    }
+    throw new NotFoundException(notFoundMessage);
+  }
+
+  /**
+   * The outcome of a single subcluster's node lookup: the node was found
+   * ({@code nodeInfo != null}), the subcluster answered that it does not host
+   * the node ({@code nodeInfo == null} with no error), or the lookup itself
+   * failed ({@code error != null}) and the subcluster's state is unknown.
+   */
+  private static final class SubClusterNodeLookup {
+    private final SubClusterInfo subCluster;
+    private final NodeInfo nodeInfo;
+    private final Exception error;
+
+    SubClusterNodeLookup(SubClusterInfo subCluster, NodeInfo nodeInfo,
+        Exception error) {
+      this.subCluster = subCluster;
+      this.nodeInfo = nodeInfo;
+      this.error = error;
+    }
+  }
+
+  /**
+   * Aggregated fan-out of a node lookup across subclusters: the answers of
+   * the subclusters that host the node, and the ids of the subclusters whose
+   * lookup failed. A subcluster that answered "node not here" appears in
+   * neither.
+   */
+  private static final class NodeLookupFanout {
+    private final Map<SubClusterInfo, NodeInfo> answers = new HashMap<>();
+    private final List<SubClusterId> failedSubClusters = new ArrayList<>();
+  }
+
   /**
    * Get a node and the subcluster where it is.
    *
    * @param subClusters Subclusters where to search.
    * @param nodeId      Identifier of the node we are looking for.
-   * @return Map between subcluster and node.
+   * @return the fan-out result: the subclusters that host the node, and the
+   *         ids of the subclusters whose lookup failed.
    */
-  private Map<SubClusterInfo, NodeInfo> getNode(Collection<SubClusterInfo> 
subClusters,
+  private NodeLookupFanout getNode(Collection<SubClusterInfo> subClusters,
       String nodeId) {
 
-    // Parallel traversal of subClusters
-    Stream<Pair<SubClusterInfo, NodeInfo>> pairStream = 
subClusters.parallelStream().map(
+    // Parallel traversal of subClusters. Every worker reports an outcome
+    // instead of throwing: a null NodeInfo with no error means the subcluster
+    // answered that it does not host the node, while a non-null error means
+    // the lookup could not be completed and the subcluster's state is unknown
+    // (YARN-12069).
+    Stream<SubClusterNodeLookup> lookupStream = 
subClusters.parallelStream().map(
         subClusterInfo -> {
-            final SubClusterId subClusterId = subClusterInfo.getSubClusterId();
-            try {
-              DefaultRequestInterceptorREST interceptor =
-                   getOrCreateInterceptorForSubCluster(subClusterInfo);
-              return Pair.of(subClusterInfo, interceptor.getNode(nodeId));
-            } catch (Exception e) {
-              LOG.error("Subcluster {} failed to return nodeInfo.", 
subClusterId, e);
-              return null;
-            }
+          try {
+            DefaultRequestInterceptorREST interceptor =
+                getOrCreateInterceptorForSubCluster(subClusterInfo);
+            return new SubClusterNodeLookup(subClusterInfo,
+                interceptor.getNode(nodeId), null);
+          } catch (Exception e) {

Review Comment:
   Could we handle `NotFoundException` separately from lookup failures?
   
   A real RM returns HTTP 404 when it does not host the node, and 
`RouterWebServiceUtil.retrieveException()` converts that response into 
`NotFoundException`.
   
   The catch-all here records it as a failed lookup, so even when every healthy 
subcluster confirms the node is absent, the Router returns 503 instead of 404.
   
   The new tests miss this because the mock returns null for an absent node. 
Please add coverage using downstream `NotFoundException` responses.



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