2929import org .apache .hadoop .hdfs .protocol .ClientProtocol ;
3030import org .apache .hadoop .hdfs .protocol .DatanodeInfo ;
3131import org .apache .hadoop .hdfs .protocol .DirectoryListing ;
32+ import org .apache .hadoop .hdfs .protocol .EncryptionZone ;
3233import org .apache .hadoop .hdfs .protocol .HdfsConstants ;
3334import org .apache .hadoop .hdfs .protocol .HdfsFileStatus ;
3435import org .apache .hadoop .hdfs .protocol .LastBlockWithStatus ;
4243import org .apache .hadoop .hdfs .server .federation .resolver .RemoteLocation ;
4344import org .apache .hadoop .hdfs .server .federation .resolver .RouterResolveException ;
4445import org .apache .hadoop .hdfs .server .federation .router .NoLocationException ;
46+ import org .apache .hadoop .hdfs .server .federation .router .RBFConfigKeys ;
4547import org .apache .hadoop .hdfs .server .federation .router .RemoteMethod ;
4648import org .apache .hadoop .hdfs .server .federation .router .RemoteParam ;
4749import 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