HDFS-17261. RBF: Fix getFileInfo return wrong path when get mountTable path which is multi-level (#6288). Contributed by liuguanghua.
Reviewed-by: Inigo Goiri <inigoiri@apache.org> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
89e78a76a0
commit
071f850841
@ -993,10 +993,10 @@ public HdfsFileStatus getFileInfo(String src) throws IOException {
|
||||
if (dates != null && dates.containsKey(src)) {
|
||||
date = dates.get(src);
|
||||
}
|
||||
ret = getMountPointStatus(src, children.size(), date);
|
||||
ret = getMountPointStatus(src, children.size(), date, false);
|
||||
} else if (children != null) {
|
||||
// The src is a mount point, but there are no files or directories
|
||||
ret = getMountPointStatus(src, 0, 0);
|
||||
ret = getMountPointStatus(src, 0, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2193,6 +2193,21 @@ private static FsPermission getParentPermission(final FsPermission mask) {
|
||||
@VisibleForTesting
|
||||
HdfsFileStatus getMountPointStatus(
|
||||
String name, int childrenNum, long date) {
|
||||
return getMountPointStatus(name, childrenNum, date, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new file status for a mount point.
|
||||
*
|
||||
* @param name Name of the mount point.
|
||||
* @param childrenNum Number of children.
|
||||
* @param date Map with the dates.
|
||||
* @param setPath if true should set path in HdfsFileStatus
|
||||
* @return New HDFS file status representing a mount point.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
HdfsFileStatus getMountPointStatus(
|
||||
String name, int childrenNum, long date, boolean setPath) {
|
||||
long modTime = date;
|
||||
long accessTime = date;
|
||||
FsPermission permission = FsPermission.getDirDefault();
|
||||
@ -2242,17 +2257,20 @@ HdfsFileStatus getMountPointStatus(
|
||||
}
|
||||
}
|
||||
long inodeId = 0;
|
||||
HdfsFileStatus.Builder builder = new HdfsFileStatus.Builder();
|
||||
if (setPath) {
|
||||
Path path = new Path(name);
|
||||
String nameStr = path.getName();
|
||||
return new HdfsFileStatus.Builder()
|
||||
.isdir(true)
|
||||
builder.path(DFSUtil.string2Bytes(nameStr));
|
||||
}
|
||||
|
||||
return builder.isdir(true)
|
||||
.mtime(modTime)
|
||||
.atime(accessTime)
|
||||
.perm(permission)
|
||||
.owner(owner)
|
||||
.group(group)
|
||||
.symlink(new byte[0])
|
||||
.path(DFSUtil.string2Bytes(nameStr))
|
||||
.fileId(inodeId)
|
||||
.children(childrenNum)
|
||||
.flags(flags)
|
||||
|
@ -372,6 +372,10 @@ public void testGetMountPointStatus() throws IOException {
|
||||
HdfsFileStatus dirStatus2 =
|
||||
clientProtocol.getMountPointStatus(childPath2.toString(), 0, 0);
|
||||
assertEquals(child2, dirStatus2.getLocalName());
|
||||
|
||||
HdfsFileStatus dirStatus3 =
|
||||
clientProtocol.getMountPointStatus(childPath2.toString(), 0, 0, false);
|
||||
assertTrue(dirStatus3.isEmptyLocalName());
|
||||
}
|
||||
/**
|
||||
* GetListing of testPath through router.
|
||||
@ -666,6 +670,25 @@ public void testGetListingWithTrailingSlash() throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileInfoWithMountPoint() throws IOException {
|
||||
try {
|
||||
// Add mount table entry
|
||||
MountTable addEntry = MountTable.newInstance("/testgetfileinfo/ns1/dir",
|
||||
Collections.singletonMap("ns1", "/testgetfileinfo/ns1/dir"));
|
||||
assertTrue(addMountTable(addEntry));
|
||||
nnFs1.mkdirs(new Path("/testgetfileinfo/ns1/dir"));
|
||||
|
||||
FileStatus fileStatus = routerFs.getFileStatus(new Path("/testgetfileinfo/ns1"));
|
||||
assertEquals(fileStatus.getPath().toUri().getPath(), "/testgetfileinfo/ns1");
|
||||
|
||||
fileStatus = routerFs.getFileStatus(new Path("/testgetfileinfo/ns1/dir"));
|
||||
assertEquals(fileStatus.getPath().toUri().getPath(), "/testgetfileinfo/ns1/dir");
|
||||
} finally {
|
||||
nnFs1.delete(new Path("/testgetfileinfo/ns1/dir"), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for HDFS-13255.
|
||||
* Verify that delete fails if the path is a mount point or
|
||||
|
Loading…
Reference in New Issue
Block a user