You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Lisheng Sun (JIRA)" <ji...@apache.org> on 2019/06/10 08:16:00 UTC

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

    [ https://issues.apache.org/jira/browse/HADOOP-16112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=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:#ff0000}// case{color}
> {color:#ff0000}  other thread deletes existsFilePath here ,the results doesn't  meet expectation{color}
> {color:#ff0000} for example{color}
> {color:#ff0000}   there is /user/u_sunlisheng/.Trash/Current/user/u_sunlisheng/b{color}
> {color:#ff0000}   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:#ff0000}  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-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org