Skip to content

Commit 536fe80

Browse files
author
Tom McCormick
committed
HDFS-16791 fix pr comments
1 parent 8f87758 commit 536fe80

15 files changed

Lines changed: 89 additions & 33 deletions

File tree

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,11 +4877,16 @@ public CompletableFuture<FSDataInputStream> build() throws IOException {
48774877
}
48784878

48794879
/**
4880-
* Return root path
4881-
* @param path
4882-
* @return
4880+
* Return path of the enclosing root for a given path
4881+
* The enclosing root path is a common ancestor that should be used for temp and staging dirs
4882+
* as well as within encryption zones and other restricted directories
4883+
* @param path file path to find the enclosing root path for
4884+
* @return a path to the enclosing rot
48834885
* @throws IOException
48844886
*/
4887+
@InterfaceAudience.Public
4888+
@InterfaceStability.Unstable
4889+
// Should this throw RuntimeException (instead of IO), so we can throw NotInMountpointException from viewfs/rbf?
48854890
public Path getEnclosingRoot(Path path) throws IOException {
48864891
return this.makeQualified(new Path("/"));
48874892
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,13 +1369,13 @@ public boolean hasPathCapability(Path path, String capability)
13691369
throw new NotInMountpointException(p, "hasPathCapability");
13701370
}
13711371
}
1372-
1372+
13731373
@Override
13741374
public Path getEnclosingRoot(Path path) throws IOException {
13751375
InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(path), true);
13761376
Path fullPath = new Path(res.resolvedPath);
13771377
Path enclosingPath = res.targetFileSystem.getEnclosingRoot(path);
1378-
return enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath;
1378+
return fixRelativePart(enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath);
13791379
}
13801380

13811381
/**
@@ -1933,7 +1933,7 @@ public Path getEnclosingRoot(Path path) throws IOException {
19331933
InodeTree.ResolveResult<FileSystem> res = fsState.resolve(path.toString(), true);
19341934
Path fullPath = new Path(res.resolvedPath);
19351935
Path enclosingPath = res.targetFileSystem.getEnclosingRoot(path);
1936-
return enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath;
1936+
return (enclosingPath.depth() > fullPath.depth() ? enclosingPath : fullPath).makeQualified(myUri, null);
19371937
}
19381938
}
19391939

hadoop-common-project/hadoop-common/src/site/markdown/filesystem/filesystem.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,25 @@ on the filesystem.
599599
if len(FS, P) > 0: getFileStatus(P).getBlockSize() > 0
600600
result == getFileStatus(P).getBlockSize()
601601

602+
1. The outcome of this operation MUST be identical to the value of
603+
`getFileStatus(P).getBlockSize()`.
604+
2. By inference, it MUST be > 0 for any file of length > 0.
605+
### `Path getEnclosingRoot(Path p)`
606+
607+
This method is used to find a root directory for a path given. This is useful for creating
608+
staging and temp directories in the same root directory. There are constraints around how
609+
renames are allowed to atomically occur (ex. across hdfs volumes or across encryption zones).
610+
611+
#### Preconditions
612+
613+
if no root path is found: raise IOException
614+
No root path would be found only if there is no mount point for the given path
615+
616+
617+
#### Postconditions
618+
619+
The path return will not be null
620+
602621
1. The outcome of this operation MUST be identical to the value of
603622
`getFileStatus(P).getBlockSize()`.
604623
1. By inference, it MUST be > 0 for any file of length > 0.

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ CompletableFuture<FSDataInputStream> openFileWithOptions(
250250

251251
MultipartUploaderBuilder createMultipartUploader(Path basePath)
252252
throws IOException;
253+
254+
Path getEnclosingRoot(Path path) throws IOException;
253255
}
254256

255257
@Test

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3531,7 +3531,7 @@ public DatanodeInfo[] slowDatanodeReport() throws IOException {
35313531
public Path getEnclosingRoot(String src) throws IOException {
35323532
checkOpen();
35333533
try (TraceScope ignored = newPathTraceScope("getEnclosingRoot", src)) {
3534-
return new Path(namenode.getEnclosingRoot(src));
3534+
return namenode.getEnclosingRoot(src);
35353535
} catch (RemoteException re) {
35363536
throw re.unwrapRemoteException(AccessControlException.class,
35373537
UnresolvedPathException.class);

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,15 +3913,14 @@ public Path doCall(final Path p) throws IOException {
39133913
@Override
39143914
public Path next(final FileSystem fs, final Path p)
39153915
throws IOException {
3916-
if (fs instanceof DistributedFileSystem) {
3917-
DistributedFileSystem myDfs = (DistributedFileSystem) fs;
3918-
return myDfs.getEnclosingRoot(p);
3919-
} else {
3916+
if (!(fs instanceof DistributedFileSystem)) {
39203917
throw new UnsupportedOperationException(
3921-
"Cannot call getEZForPath"
3918+
"Cannot call getEnclosingRoot"
39223919
+ " on a symlink to a non-DistributedFileSystem: " + path
39233920
+ " -> " + p);
39243921
}
3922+
DistributedFileSystem myDfs = (DistributedFileSystem) fs;
3923+
return myDfs.getEnclosingRoot(p);
39253924
}
39263925
}.resolve(this, absF);
39273926
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,6 @@ BatchedEntries<OpenFileEntry> listOpenFiles(long prevId,
18941894
*/
18951895
@Idempotent
18961896
@ReadOnly(isCoordinated = true)
1897-
String getEnclosingRoot(String src) throws IOException;
1897+
Path getEnclosingRoot(String src) throws IOException;
18981898

18991899
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/ClientNamenodeProtocolTranslatorPB.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,15 +2110,15 @@ public HAServiceProtocol.HAServiceState getHAServiceState()
21102110
}
21112111

21122112
@Override
2113-
public String getEnclosingRoot(String filename) throws IOException {
2113+
public Path getEnclosingRoot(String filename) throws IOException {
21142114
final GetEnclosingRootRequestProto.Builder builder =
21152115
GetEnclosingRootRequestProto.newBuilder();
21162116
builder.setFilename(filename);
21172117
final GetEnclosingRootRequestProto req = builder.build();
21182118
try {
21192119
final GetEnclosingRootResponseProto response =
21202120
rpcProxy.getEnclosingRoot(null, req);
2121-
return response.getEnclosingRootPath();
2121+
return new Path(response.getEnclosingRootPath());
21222122
} catch (ServiceException e) {
21232123
throw ProtobufHelper.getRemoteException(e);
21242124
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public class RouterClientProtocol implements ClientProtocol {
144144
private final boolean allowPartialList;
145145
/** Time out when getting the mount statistics. */
146146
private long mountStatusTimeOut;
147+
148+
/** Default nameservice enabled */
149+
private final boolean defaultNameserviceEnabled;
147150

148151
/** Identifier for the super user. */
149152
private String superUser;
@@ -194,6 +197,8 @@ public class RouterClientProtocol implements ClientProtocol {
194197
this.routerCacheAdmin = new RouterCacheAdmin(rpcServer);
195198
this.securityManager = rpcServer.getRouterSecurityManager();
196199
this.rbfRename = new RouterFederationRename(rpcServer, conf);
200+
this.defaultNameserviceEnabled = conf.getBoolean(RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE,
201+
RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT);
197202
}
198203

199204
@Override
@@ -1936,18 +1941,31 @@ public DatanodeInfo[] getSlowDatanodeReport() throws IOException {
19361941
}
19371942

19381943
@Override
1939-
public String getEnclosingRoot(String src) throws IOException {
1940-
Path mountPath = new Path("/");
1944+
public Path getEnclosingRoot(String src) throws IOException {
1945+
Path mountPath = null;
1946+
if (defaultNameserviceEnabled) {
1947+
mountPath = new Path("/");
1948+
}
1949+
19411950
if (subclusterResolver instanceof MountTableResolver) {
19421951
MountTableResolver mountTable = (MountTableResolver) subclusterResolver;
19431952
if (mountTable.getMountPoint(src) != null) {
19441953
// unclear if this is the correct thing to do, probably depends on default mount point / link fallback
19451954
mountPath = new Path(mountTable.getMountPoint(src).getSourcePath());
19461955
}
19471956
}
1957+
1958+
if (mountPath == null) {
1959+
throw new IOException(String.format("No mount point for %s", src));
1960+
}
1961+
19481962
EncryptionZone zone = getEZForPath(src);
1949-
Path zonePath = new Path((zone != null ? zone.getPath() : "/"));
1950-
return (zonePath.depth() > mountPath.depth() ? zonePath : mountPath).toString();
1963+
Path zonePath = new Path((zone != null ? zone.getPath() : null));
1964+
if (zonePath == null) {
1965+
return mountPath;
1966+
} else {
1967+
return zonePath.depth() > mountPath.depth() ? zonePath : mountPath;
1968+
}
19511969
}
19521970

19531971
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ public ListenableFuture<DatanodeInfo[]> reload(
20702070
}
20712071

20722072
@Override // ClientProtocol
2073-
public String getEnclosingRoot(String src) throws IOException {
2073+
public Path getEnclosingRoot(String src) throws IOException {
20742074
// need to resolve this src to a mount point in RBF and return the max this and the enclosing root from nn
20752075
return clientProto.getEnclosingRoot(src);
20762076
}

0 commit comments

Comments
 (0)