Skip to content

Commit f65c7c0

Browse files
committed
HDFS-17735. [ARR] LocalResolver#getDatanodesSubcluster adapts to async rpc.
1 parent 5067082 commit f65c7c0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/order/LocalResolver.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.hadoop.classification.VisibleForTesting;
4646
import org.apache.hadoop.thirdparty.com.google.common.net.HostAndPort;
4747

48+
import static org.apache.hadoop.hdfs.server.federation.router.async.utils.AsyncUtil.syncReturn;
4849

4950
/**
5051
* The local subcluster (where the writer is) should be tried first. The writer
@@ -143,9 +144,16 @@ private Map<String, String> getDatanodesSubcluster() {
143144
@Override
144145
public Map<String, DatanodeStorageReport[]> run() {
145146
try {
146-
return rpcServer.getDatanodeStorageReportMap(
147-
DatanodeReportType.ALL);
148-
} catch (IOException e) {
147+
Map<String, DatanodeStorageReport[]> result;
148+
if (rpcServer.isAsync()) {
149+
rpcServer.getDatanodeStorageReportMapAsync(DatanodeReportType.ALL);
150+
result = syncReturn(Map.class);
151+
} else {
152+
result = rpcServer.getDatanodeStorageReportMap(
153+
DatanodeReportType.ALL);
154+
}
155+
return result;
156+
} catch (Exception e) {
149157
LOG.error("Cannot get the datanodes from the RPC server", e);
150158
return null;
151159
}

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/utils/AsyncUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static <R> R syncReturn(Class<R> clazz)
127127
try {
128128
return (R) completableFuture.get();
129129
} catch (ExecutionException e) {
130-
throw (Exception)e.getCause();
130+
throw (Exception) e.getCause();
131131
}
132132
}
133133

0 commit comments

Comments
 (0)