hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1356897 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
Date Tue, 03 Jul 2012 19:59:57 GMT
Author: daryn
Date: Tue Jul  3 19:59:56 2012
New Revision: 1356897

URL: http://svn.apache.org/viewvc?rev=1356897&view=rev
Log:
HADOOP-8110. Fix trash checkpoint collisions (Jason Lowe via daryn)

Modified:
    hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1356897&r1=1356896&r2=1356897&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Tue Jul  3 19:59:56
2012
@@ -167,6 +167,8 @@ Trunk (unreleased changes)
     HADOOP-8548. test-patch.sh shows an incorrect link in Jekins builds
     (Kihwal Lee via bobby)
 
+    HADOOP-8110. Fix trash checkpoint collisions (Jason Lowe via daryn)
+
   OPTIMIZATIONS
 
     HADOOP-7761. Improve the performance of raw comparisons. (todd)

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java?rev=1356897&r1=1356896&r2=1356897&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java
Tue Jul  3 19:59:56 2012
@@ -35,6 +35,7 @@ import org.apache.hadoop.classification.
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.fs.Options.Rename;
 import org.apache.hadoop.fs.permission.FsAction;
 import org.apache.hadoop.fs.permission.FsPermission;
 
@@ -148,21 +149,32 @@ public class TrashPolicyDefault extends 
       new IOException("Failed to move to trash: "+path).initCause(cause);
   }
 
+  @SuppressWarnings("deprecation")
   @Override
   public void createCheckpoint() throws IOException {
     if (!fs.exists(current))                     // no trash, no checkpoint
       return;
 
-    Path checkpoint;
+    Path checkpointBase;
     synchronized (CHECKPOINT) {
-      checkpoint = new Path(trash, CHECKPOINT.format(new Date()));
+      checkpointBase = new Path(trash, CHECKPOINT.format(new Date()));
     }
+    Path checkpoint = checkpointBase;
 
-    if (fs.rename(current, checkpoint)) {
-      LOG.info("Created trash checkpoint: "+checkpoint.toUri().getPath());
-    } else {
-      throw new IOException("Failed to checkpoint trash: "+checkpoint);
+    int attempt = 0;
+    while (true) {
+      try {
+        fs.rename(current, checkpoint, Rename.NONE);
+        break;
+      } catch (FileAlreadyExistsException e) {
+        if (++attempt > 1000) {
+          throw new IOException("Failed to checkpoint trash: "+checkpoint);
+        }
+        checkpoint = checkpointBase.suffix("-" + attempt);
+      }
     }
+
+    LOG.info("Created trash checkpoint: "+checkpoint.toUri().getPath());
   }
 
   @Override



Mime
View raw message