HDFS-15563. Incorrect getTrashRoot return value when a non-snapshottable dir prefix matches the path of a snapshottable dir (#2295)

Change-Id: Iefcbc14ca939b61f0c1befc9a94d686be1684ddc
This commit is contained in:
Siyao Meng 2020-09-10 03:25:23 -07:00 committed by GitHub
parent e5fe326270
commit 43c52d6495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -3168,6 +3168,9 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
}
for (SnapshottableDirectoryStatus dirStatus : dirStatusList) {
String currDir = dirStatus.getFullPath().toString();
if (!currDir.endsWith(Path.SEPARATOR)) {
currDir += Path.SEPARATOR;
}
if (path.toUri().getPath().startsWith(currDir)) {
return currDir;
}

View File

@ -2172,9 +2172,19 @@ public class TestDistributedFileSystem {
String testDirStr = testDir.toUri().getPath();
assertTrue(trAfterAllowSnapshotStr.startsWith(testDirStr));
// test2Dir has the same prefix as testDir, but not snapshottable
Path test2Dir = new Path("/ssgtr/test12/");
Path file1path = new Path(test2Dir, "file-1");
trAfterAllowSnapshot = dfs.getTrashRoot(file1path);
trAfterAllowSnapshotStr = trAfterAllowSnapshot.toUri().getPath();
// The trash root should not be in the snapshot root
assertFalse(trAfterAllowSnapshotStr.startsWith(testDirStr));
assertTrue(trBeforeAllowSnapshotStr.startsWith(homeDirStr));
// Cleanup
dfs.disallowSnapshot(testDir);
dfs.delete(testDir, true);
dfs.delete(test2Dir, true);
} finally {
if (cluster != null) {
cluster.shutdown();