Skip to content

Commit a31497a

Browse files
committed
HDFS-17744. [ARR] getEnclosingRoot RPC adapts to async rpc.
1 parent b05c0ce commit a31497a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
3030
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
3131
import org.apache.hadoop.hdfs.protocol.DirectoryListing;
32+
import org.apache.hadoop.hdfs.protocol.EncryptionZone;
3233
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
3334
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
3435
import org.apache.hadoop.hdfs.protocol.LastBlockWithStatus;
@@ -42,6 +43,7 @@
4243
import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
4344
import org.apache.hadoop.hdfs.server.federation.resolver.RouterResolveException;
4445
import org.apache.hadoop.hdfs.server.federation.router.NoLocationException;
46+
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
4547
import org.apache.hadoop.hdfs.server.federation.router.RemoteMethod;
4648
import org.apache.hadoop.hdfs.server.federation.router.RemoteParam;
4749
import org.apache.hadoop.hdfs.server.federation.router.RemoteResult;
@@ -104,6 +106,8 @@ public class RouterAsyncClientProtocol extends RouterClientProtocol {
104106
private final boolean allowPartialList;
105107
/** Time out when getting the mount statistics. */
106108
private long mountStatusTimeOut;
109+
/** Default nameservice enabled. */
110+
private final boolean defaultNameServiceEnabled;
107111
/** Identifier for the super user. */
108112
private String superUser;
109113
/** Identifier for the super group. */
@@ -126,6 +130,9 @@ public RouterAsyncClientProtocol(Configuration conf, RouterRpcServer rpcServer)
126130
this.mountStatusTimeOut = getMountStatusTimeOut();
127131
this.superUser = getSuperUser();
128132
this.superGroup = getSuperGroup();
133+
this.defaultNameServiceEnabled = conf.getBoolean(
134+
RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE,
135+
RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT);
129136
}
130137

131138
@Override
@@ -1086,4 +1093,35 @@ public boolean isMultiDestDirectory(String src) throws IOException {
10861093
asyncCompleteWith(CompletableFuture.completedFuture(false));
10871094
return asyncReturn(Boolean.class);
10881095
}
1096+
1097+
@Override
1098+
public Path getEnclosingRoot(String src) throws IOException {
1099+
final Path[] mountPath = new Path[1];
1100+
if (defaultNameServiceEnabled) {
1101+
mountPath[0] = new Path("/");
1102+
}
1103+
1104+
if (subclusterResolver instanceof MountTableResolver) {
1105+
MountTableResolver mountTable = (MountTableResolver) subclusterResolver;
1106+
if (mountTable.getMountPoint(src) != null) {
1107+
mountPath[0] = new Path(mountTable.getMountPoint(src).getSourcePath());
1108+
}
1109+
}
1110+
1111+
if (mountPath[0] == null) {
1112+
throw new IOException(String.format("No mount point for %s", src));
1113+
}
1114+
1115+
getEZForPath(src);
1116+
asyncApply((ApplyFunction<EncryptionZone, Path>)zone -> {
1117+
if (zone == null) {
1118+
return mountPath[0];
1119+
} else {
1120+
Path zonePath = new Path(zone.getPath());
1121+
return zonePath.depth() > mountPath[0].depth() ? zonePath : mountPath[0];
1122+
}
1123+
});
1124+
return asyncReturn(Path.class);
1125+
}
1126+
10891127
}

0 commit comments

Comments
 (0)