Skip to content

Commit 15a6dcc

Browse files
author
Xing Lin
committed
GetTrashRoots(): include trash roots in fallback FS as well.
1 parent 485a650 commit 15a6dcc

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,19 @@ public Collection<FileStatus> getTrashRoots(boolean allUsers) {
12351235
return trashRoots.values();
12361236
}
12371237

1238-
// Get trash roots in TRASH_PREFIX dir inside mount points.
1238+
// Get trash roots in TRASH_PREFIX dir inside mount points and fallback FS.
1239+
List<InodeTree.MountPoint<FileSystem>> mountPoints =
1240+
fsState.getMountPoints();
1241+
// If we have a fallback FS, add a mount point for it as <"", fallback FS>.
1242+
// The source path of a mount point shall not end with '/', thus for
1243+
// fallback fs, we set its mount point src as "".
1244+
if (fsState.getRootFallbackLink() != null) {
1245+
mountPoints.add(new InodeTree.MountPoint<>("",
1246+
fsState.getRootFallbackLink()));
1247+
}
1248+
12391249
try {
1240-
for (InodeTree.MountPoint<FileSystem> mountPoint : fsState.getMountPoints()) {
1250+
for (InodeTree.MountPoint<FileSystem> mountPoint : mountPoints) {
12411251

12421252
Path trashRoot =
12431253
makeQualified(new Path(mountPoint.src + "/" + TRASH_PREFIX));
@@ -1270,7 +1280,7 @@ public Collection<FileStatus> getTrashRoots(boolean allUsers) {
12701280
}
12711281
}
12721282
} catch (IOException e) {
1273-
LOG.warn("Exception in get all trash roots", e);
1283+
LOG.warn("Exception in get all trash roots for mount points", e);
12741284
}
12751285

12761286
return trashRoots.values();

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,16 @@ public void testTrashRootsAllUsers() throws IOException {
12281228
FileSystem fsView4 = FileSystem.get(FsConstants.VIEWFS_URI, conf4);
12291229
int trashRootsNum4 = fsView4.getTrashRoots(true).size();
12301230
Assert.assertEquals(afterTrashRootsNum2 + 2, trashRootsNum4);
1231+
1232+
// Case 4: test trash roots in fallback FS
1233+
fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user10"));
1234+
fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user11"));
1235+
fsTarget.mkdirs(new Path(targetTestRoot, ".Trash/user12"));
1236+
Configuration conf5 = new Configuration(conf2);
1237+
ConfigUtil.addLinkFallback(conf5, targetTestRoot.toUri());
1238+
FileSystem fsView5 = FileSystem.get(FsConstants.VIEWFS_URI, conf5);
1239+
int trashRootsNum5 = fsView5.getTrashRoots(true).size();
1240+
Assert.assertEquals(afterTrashRootsNum2 + 3, trashRootsNum5);
12311241
}
12321242

12331243
/**
@@ -1254,6 +1264,14 @@ public void testTrashRootsCurrentUser() throws IOException {
12541264
int afterTrashRootsNum2 = fsView2.getTrashRoots(false).size();
12551265
Assert.assertEquals(beforeTrashRootNum, afterTrashRootsNum);
12561266
Assert.assertEquals(beforeTrashRootNum2 + 2, afterTrashRootsNum2);
1267+
1268+
// Test trash roots in fallback FS
1269+
Configuration conf3 = new Configuration(conf2);
1270+
fsTarget.mkdirs(new Path(targetTestRoot, TRASH_PREFIX + "/" + currentUser));
1271+
ConfigUtil.addLinkFallback(conf3, targetTestRoot.toUri());
1272+
FileSystem fsView3 = FileSystem.get(FsConstants.VIEWFS_URI, conf3);
1273+
int trashRootsNum3 = fsView3.getTrashRoots(false).size();
1274+
Assert.assertEquals(afterTrashRootsNum2 + 1, trashRootsNum3);
12571275
}
12581276

12591277
@Test(expected = NotInMountpointException.class)

0 commit comments

Comments
 (0)