[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16860469#comment-16860469
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/11/19 2:02 AM:
---

[~hexiaoqiao]
{code:java}
Yeah,I mean the trash directory should  be 
{/user/test/.Trash/Current/user/test/a+timestamp/b}. 
But when the code catch FileAlreadyExistsException, another thread delete 
/user/test/.Trash/Current/user/test/a in this corner case before the code
 
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}

So the actual result is /user/test/.Trash/Current/user/test+timestamp/a/b. It 
is not expected result. 
Please correct me if i am wrong.{code}


was (Author: leosun08):
[~hexiaoqiao]
{code:java}
I mean the trash directory should  be 
{/user/test/.Trash/Current/user/test/a+timestamp/b}. 
But when the code catch FileAlreadyExistsException, another thread delete 
/user/test/.Trash/Current/user/test/a in this corner case before the code
 
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}

So the actual result is /user/test/.Trash/Current/user/test+timestamp/a/b. It 
is not expected result. 
Please correct me if i am wrong.{code}

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16860469#comment-16860469
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/11/19 1:57 AM:
---

[~hexiaoqiao]
{code:java}
I mean the trash directory should  be 
{/user/test/.Trash/Current/user/test/a+timestamp/b}. 
But when the code catch FileAlreadyExistsException, another thread delete 
/user/test/.Trash/Current/user/test/a in this corner case before the code
 
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}

So the actual result is /user/test/.Trash/Current/user/test+timestamp/a/b. It 
is not expected result. 
Please correct me if i am wrong.{code}


was (Author: leosun08):
 

  [~hexiaoqiao]
{code:java}
I mean the trash directory should  be 
{/user/test/.Trash/Current/user/test/a+timestamp/b}. 
But when the code catch FileAlreadyExistsException, another thread delete 
/user/test/.Trash/Current/user/test/a in this corner case before the code
 
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}

So the actual result is /user/test/.Trash/Current/user/test+timestamp/a/b. It 
is not expected result.{code}
 

 

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859949#comment-16859949
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/10/19 11:56 AM:


[~hexiaoqiao] ,  thanks for the reply.

Reproduce it as follow:
{code:java}
try {
fs -mkdir /user/test 
fs -mkdir /user/test/a 
fs -mkdir /user/test/a/b 
}
catch (FileAlreadyExistsException e) {
   
   fs -rm -r/user/test/a (another thread)
   fs -mkdir /user/test/a/b
}

{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 

 But, the race condition is reproduced hard by Unit Test.


was (Author: leosun08):
[~hexiaoqiao] ,  thanks for the reply.

Reproduce it as follow:
{code:java}
try {
fs -mkdir /user/test 
fs -mkdir /user/test/a 
fs -mkdir /user/test/a/b 
}
catch (FileAlreadyExistsException e) {
   
   fs -rm -r/user/test/a (another thread)
   fs -mkdir /user/test/a/b
}

{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 

 The race condition is reproduced hard by Unit Test.

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859949#comment-16859949
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/10/19 11:56 AM:


[~hexiaoqiao] ,  thanks for the reply.

Reproduce it as follow:
{code:java}
try {
fs -mkdir /user/test 
fs -mkdir /user/test/a 
fs -mkdir /user/test/a/b 
}
catch (FileAlreadyExistsException e) {
   
   fs -rm -r/user/test/a (another thread)
   fs -mkdir /user/test/a/b
}

{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 


was (Author: leosun08):
[~hexiaoqiao] ,  thanks for the reply.

Reproduce it as follow:
{code:java}
try {
fs -mkdir /user/test 
fs -mkdir /user/test/a 
fs -mkdir /user/test/a/b 
}
catch (FileAlreadyExistsException e) {
   
   fs -rm -r/user/test/a (another thread)
   fs -mkdir /user/test/a/b
}

{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 

 But, the race condition is reproduced hard by Unit Test.

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859949#comment-16859949
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/10/19 11:55 AM:


[~hexiaoqiao] ,  thanks for the reply.

Reproduce it as follow:
{code:java}
try {
fs -mkdir /user/test 
fs -mkdir /user/test/a 
fs -mkdir /user/test/a/b 
}
catch (FileAlreadyExistsException e) {
   
   fs -rm -r/user/test/a (another thread)
   fs -mkdir /user/test/a/b
}

{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 

 The race condition is reproduced hard by Unit Test.


was (Author: leosun08):
[~hexiaoqiao] ,  thanks for the reply.
{code:java}
fs -mkdir /user/test
fs -mkdir /user/test/a
fs -mkdir /user/test/a/b fail
catch 
   fs -rm -r/user/test/a (another thread)

fs -mkdir /user/test/a/b 
{code}
 The current code is intented to mkdir /user/test/a+timestamp/b, but in actual 
mkdir /user/test+timestamp/a/b. 

 The race condition is reproduced hard by Unit Test.

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread He Xiaoqiao (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859920#comment-16859920
 ] 

He Xiaoqiao edited comment on HADOOP-16112 at 6/10/19 10:55 AM:


Sorry I don't catch the point and just verify the unit test you attach in 
[^HADOOP-16112.002.patch], and it run correctly using branch trunk at local, So 
I am confused what this issue means?
Would you mind offer how to reproduce this issue? for instance(just example, no 
more info.)
{code:java}
fs -mkdir /user/test
fs -rm -r /user/test
fs -mkdir /user/test/a
fs -rm -r /user/test/b (another thread)
{code}


was (Author: hexiaoqiao):
Sorry I don't catch the point and just verify the unit test you attach in 
[^HADOOP-16112.002.patch], and it run correct, So I am confused what this issue 
means?
Would you mind offer how to reproduce this issue? for instance(just example, no 
more info.)
{code:java}
fs -mkdir /user/test
fs -rm -r /user/test
fs -mkdir /user/test/a
fs -rm -r /user/test/b (another thread)
{code}

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the results 
> doesn't  meet expectation{color}
> {color:#ff} for example{color}
> {color:#ff}   there is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff}   when delete /user/u_sunlisheng/b/a. if existsFilePath is 
> deleted, the result is 
> /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a{color}
> {color:#ff}  so  when existsFilePath is deleted, don't modify 
> baseTrashPath.    {color}
> baseTrashPath = new Path(baseTrashPath.toString().replace(
>  existsFilePath.toString(), existsFilePath.toString() + Time.now())
>  );
> trashPath = new Path(baseTrashPath, trashPath.getName());
>  // retry, ignore current failure
>  --i;
>  continue;
>  } catch (IOException e)
> { LOG.warn("Can't create trash directory: " + baseTrashPath, e); cause = e; 
> break; }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859794#comment-16859794
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/10/19 9:53 AM:
---

[~hexiaoqiao]Thanks for watching this issue.

The issue is a race condition in TrashPolicyDefault#moveToTrash.
{code:java}
 try {
 if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current
 LOG.warn("Can't create(mkdir) trash directory: " + baseTrashPath);
 return false;
 }
 } catch (FileAlreadyExistsException e) {
 // find the path which is not a directory, and modify baseTrashPath
 // & trashPath, then mkdirs
 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());
 // retry, ignore current failure
 --i;
 continue;
 } catch (IOException e) {
 LOG.warn("Can't create trash directory: " + baseTrashPath, e);
 cause = e;
 break;
 }
 try {
 // if the target path in Trash already exists, then append with 
 // a current time in millisecs.
 String orig = trashPath.toString();
 
 while(fs.exists(trashPath)) {
 trashPath = new Path(orig + Time.now());
 }
 
 // move to current trash
 fs.rename(path, trashPath,
 Rename.TO_TRASH);
 LOG.info("Moved: '" + path + "' to trash at: " + trashPath);
 return true;
 } catch (IOException e) {
 cause = e;
 }

{code}
 when run the following code,  the other thread deletes the existsFilePath 
simultaneously. Finally the results doesn't meet expectation. 
{code:java}
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}{code}
According to current code, the result is:
{code:java}
there is /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b  //existFilePath

when delete /user/u_sunlisheng/b/a. if existsFilePath is deleted, the result is 
/user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a

so when existsFilePath is deleted, don't modify baseTrashPath.    
{code}
Please correct me if i am wrong.


was (Author: leosun08):
[~hexiaoqiao]Thanks for watching this issue.

The issue is a race condition in TrashPolicyDefault#moveToTrash.
{code:java}
 try {
 if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current
 LOG.warn("Can't create(mkdir) trash directory: " + baseTrashPath);
 return false;
 }
 } catch (FileAlreadyExistsException e) {
 // find the path which is not a directory, and modify baseTrashPath
 // & trashPath, then mkdirs
 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());
 // retry, ignore current failure
 --i;
 continue;
 } catch (IOException e) {
 LOG.warn("Can't create trash directory: " + baseTrashPath, e);
 cause = e;
 break;
 }
 try {
 // if the target path in Trash already exists, then append with 
 // a current time in millisecs.
 String orig = trashPath.toString();
 
 while(fs.exists(trashPath)) {
 trashPath = new Path(orig + Time.now());
 }
 
 // move to current trash
 fs.rename(path, trashPath,
 Rename.TO_TRASH);
 LOG.info("Moved: '" + path + "' to trash at: " + trashPath);
 return true;
 } catch (IOException e) {
 cause = e;
 }

{code}
 when run the following code,  the other thread deletes the existsFilePath 
simultaneously,  the results doesn't meet expectation. 
{code:java}
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}{code}
According to current code, the result is:
{code:java}
there is /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b  //existFilePath

when delete /user/u_sunlisheng/b/a. if existsFilePath is deleted, the result is 
/user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a

so when existsFilePath is deleted, don't modify baseTrashPath.    
{code}
Please correct me if i am wrong.

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 

[jira] [Comment Edited] (HADOOP-16112) Delete the baseTrashPath's subDir leads to don't modify baseTrashPath

2019-06-10 Thread Lisheng Sun (JIRA)


[ 
https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859794#comment-16859794
 ] 

Lisheng Sun edited comment on HADOOP-16112 at 6/10/19 8:15 AM:
---

[~hexiaoqiao]Thanks for watching this issue.

The issue is a race condition in TrashPolicyDefault#moveToTrash.
{code:java}
 try {
 if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current
 LOG.warn("Can't create(mkdir) trash directory: " + baseTrashPath);
 return false;
 }
 } catch (FileAlreadyExistsException e) {
 // find the path which is not a directory, and modify baseTrashPath
 // & trashPath, then mkdirs
 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());
 // retry, ignore current failure
 --i;
 continue;
 } catch (IOException e) {
 LOG.warn("Can't create trash directory: " + baseTrashPath, e);
 cause = e;
 break;
 }
 try {
 // if the target path in Trash already exists, then append with 
 // a current time in millisecs.
 String orig = trashPath.toString();
 
 while(fs.exists(trashPath)) {
 trashPath = new Path(orig + Time.now());
 }
 
 // move to current trash
 fs.rename(path, trashPath,
 Rename.TO_TRASH);
 LOG.info("Moved: '" + path + "' to trash at: " + trashPath);
 return true;
 } catch (IOException e) {
 cause = e;
 }

{code}
 when run the following code,  the other thread deletes the existsFilePath 
simultaneously,  the results doesn't meet expectation. 
{code:java}
Path existsFilePath = baseTrashPath;
while (!fs.exists(existsFilePath)) {
  existsFilePath = existsFilePath.getParent();
}{code}
According to current code, the result is:
{code:java}
there is /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b  //existFilePath

when delete /user/u_sunlisheng/b/a. if existsFilePath is deleted, the result is 
/user/u_sunlisheng/.Trash/Current/user/u_sunlisheng+timstamp/b/a

so when existsFilePath is deleted, don't modify baseTrashPath.    
{code}
Please correct me if i am wrong.


was (Author: leosun08):
Thanks for watching this issue.

The issue is a race condition in TrashPolicyDefault#moveToTrash.

 
try {
if (!fs.mkdirs(baseTrashPath, PERMISSION)) {  // create current
  LOG.warn("Can't create(mkdir) trash directory: " + baseTrashPath);
  return false;
}
  } catch (FileAlreadyExistsException e) {
// find the path which is not a directory, and modify baseTrashPath
// & trashPath, then mkdirs
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());
// retry, ignore current failure
--i;
continue;
  } catch (IOException e) {
LOG.warn("Can't create trash directory: " + baseTrashPath, e);
cause = e;
break;
  }
  try {
// if the target path in Trash already exists, then append with 
// a current time in millisecs.
String orig = trashPath.toString();

while(fs.exists(trashPath)) {
  trashPath = new Path(orig + Time.now());
}

// move to current trash
fs.rename(path, trashPath,
Rename.TO_TRASH);
LOG.info("Moved: '" + path + "' to trash at: " + trashPath);
return true;
  } catch (IOException e) {
cause = e;
  }
 

> Delete the baseTrashPath's subDir leads to don't modify baseTrashPath
> -
>
> Key: HADOOP-16112
> URL: https://issues.apache.org/jira/browse/HADOOP-16112
> Project: Hadoop Common
>  Issue Type: Bug
>  Components: common
>Affects Versions: 3.2.0
>Reporter: Lisheng Sun
>Priority: Major
> Attachments: HADOOP-16112.001.patch, HADOOP-16112.002.patch
>
>
> There is race condition in TrashPolicyDefault#moveToTrash
> try {
>  if (!fs.mkdirs(baseTrashPath, PERMISSION))
> { // create current LOG.warn("Can't create(mkdir) trash directory: " + 
> baseTrashPath); return false; }
> } catch (FileAlreadyExistsException e) {
>  // find the path which is not a directory, and modify baseTrashPath
>  // & trashPath, then mkdirs
>  Path existsFilePath = baseTrashPath;
>  while (!fs.exists(existsFilePath))
> { existsFilePath = existsFilePath.getParent(); }
> {color:#ff}// case{color}
> {color:#ff}  other thread deletes existsFilePath here ,the