hfutatzhanghb commented on code in PR #7108:
URL: https://github.com/apache/hadoop/pull/7108#discussion_r1796318649
##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java:
##########
@@ -791,6 +801,46 @@ <T> T invokeAtAvailableNs(RemoteMethod method, Class<T>
clazz)
return invokeOnNs(method, clazz, io, nss);
}
+ /**
+ * Invokes the method at default namespace, if default namespace is not
+ * available then at the other available namespaces.
+ * If the namespace is unavailable, retry with other namespaces.
+ * Asynchronous version of invokeAtAvailableNs method.
+ * @param <T> expected return type.
+ * @param method the remote method.
+ * @return the response received after invoking method.
+ * @throws IOException
+ */
+ <T> T invokeAtAvailableNsAsync(RemoteMethod method, Class<T> clazz)
+ throws IOException {
+ String nsId = subclusterResolver.getDefaultNamespace();
+ // If default Ns is not present return result from first namespace.
+ Set<FederationNamespaceInfo> nss = namenodeResolver.getNamespaces();
+ // If no namespace is available, throw IOException.
+ IOException io = new IOException("No namespace available.");
+
+ asyncComplete(null);
+ if (!nsId.isEmpty()) {
+ asyncTry(() -> {
+ rpcClient.invokeSingle(nsId, method, clazz);
+ });
+
+ asyncCatch((AsyncCatchFunction<T, IOException>)(res, ioe) -> {
+ if (!clientProto.isUnavailableSubclusterException(ioe)) {
+ LOG.debug("{} exception cannot be retried",
+ ioe.getClass().getSimpleName());
+ throw ioe;
+ }
+ nss.removeIf(n -> n.getNameserviceId().equals(nsId));
+ invokeOnNs(method, clazz, io, nss);
Review Comment:
Thanks, fixed.
--
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]