jojochuang commented on a change in pull request #1223: HADOOP-16112. Delete
the baseTrashPath's subDir leads to don't modify baseTrashPath
URL: https://github.com/apache/hadoop/pull/1223#discussion_r311850143
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
##########
@@ -157,14 +163,37 @@ public boolean moveToTrash(Path path) throws IOException
{
} catch (FileAlreadyExistsException e) {
// find the path which is not a directory, and modify baseTrashPath
// & trashPath, then mkdirs
+ if (moveToTrashForTests) {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e1) {
+ }
+ }
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
existsFilePath = existsFilePath.getParent();
}
- baseTrashPath = new Path(baseTrashPath.toString().replace(
- existsFilePath.toString(), existsFilePath.toString() + Time.now())
- );
- trashPath = new Path(baseTrashPath, trashPath.getName());
+
+ // race condition: don't modify baseTrashPath when existsFilePath is
deleted.
+ // existsFilePath is /user/test/.Trash/Current/user/test/a/b
+ // another thread delete /user/test/.Trash/Current/user/test/a in this
corner case before the code as follow:
+ // baseTrashPath = new Path(baseTrashPath.toString().replace(
+ // existsFilePath.toString(),
existsFilePath.toString() + Time.now()));
+ // trashPath = new Path(baseTrashPath, trashPath.getName());
+ // baseTrashPath is /user/test/.Trash/Current/user/test+timestamp
+ // trashPath is /user/test/.Trash/Current/user/test+timestamp/a/b. It
is not expected result.
+ try {
+ FileStatus fileStatus = fs.getFileStatus(existsFilePath);
+ if (fileStatus.isFile()) {
+ baseTrashPath = new Path(baseTrashPath.toString().replace(
+ existsFilePath.toString(), existsFilePath.toString() +
Time.now())
+ );
+ trashPath = new Path(baseTrashPath, trashPath.getName());
+ }
+ } catch (FileNotFoundException e1) {
+ LOG.warn("The existFilePath is not found " + existsFilePath);
Review comment:
"File " + existsFilePath + " was not found"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]