Browse Source

Fix HADOOP-162. Stop generating ConcurrentModificationExceptions when releasing file locks. Contributed by Owen O'Malley.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@396721 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 years ago
parent
commit
da3cf9a45d
2 changed files with 34 additions and 26 deletions
  1. 4 0
      CHANGES.txt
  2. 30 26
      src/java/org/apache/hadoop/dfs/FSNamesystem.java

+ 4 - 0
CHANGES.txt

@@ -83,6 +83,10 @@ Trunk (unreleased)
 22. Fix HADOOP-150.  Improved task names that include job
     names. (omalley via cutting)
 
+23. Fix HADOOP-162.  Fix ConcurrentModificationException when
+    releasing file locks. (omalley via cutting)
+
+
 Release 0.1.1 - 2006-04-08
 
  1. Added CHANGES.txt, logging all significant changes to Hadoop.  (cutting)

+ 30 - 26
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -37,6 +37,10 @@ import java.util.logging.*;
  ***************************************************/
 class FSNamesystem implements FSConstants {
     public static final Logger LOG = LogFormatter.getLogger("org.apache.hadoop.fs.FSNamesystem");
+    static {
+      // for debugging the pending Creates problems
+      LOG.setLevel(Level.FINE);
+    }
 
     //
     // Stores the correct file name hierarchy
@@ -391,7 +395,22 @@ class FSNamesystem implements FSConstants {
                                                    ) throws IOException {
       LOG.info("abandoning file in progress on " + src.toString());
       synchronized (leases) {
-        internalReleaseCreate(src, holder);
+        // find the lease
+        Lease lease = (Lease) leases.get(holder);
+        if (lease != null) {
+          // remove the file from the lease
+          if (lease.completedCreate(src)) {
+            // if we found the file in the lease, remove it from pendingCreates
+            internalReleaseCreate(src, holder);
+          } else {
+            LOG.info("Attempt by " + holder.toString() + 
+                " to release someone else's create lock on " + 
+                src.toString());
+          }
+        } else {
+          LOG.info("Attempt to release a lock from an unknown lease holder "
+              + holder.toString() + " for " + src.toString());
+        }
       }
     }
 
@@ -818,33 +837,18 @@ class FSNamesystem implements FSConstants {
      * @param holder The datanode that was creating the file
      */
     private void internalReleaseCreate(UTF8 src, UTF8 holder) {
-      // find the lease
-      Lease lease = (Lease) leases.get(holder);
-      if (lease != null) {
-        // remove the file from the lease
-        if (lease.completedCreate(src)) {
-          // if we found the file in the lease, remove it from pendingCreates
-          FileUnderConstruction v = 
-            (FileUnderConstruction) pendingCreates.remove(src);
-          if (v != null) {
-            LOG.info("Removing " + src + " from pendingCreates for " + 
-                     holder + " (failure)");
-            for (Iterator it2 = v.getBlocks().iterator(); it2.hasNext(); ) {
-              Block b = (Block) it2.next();
-              pendingCreateBlocks.remove(b);
-            }
-          } else {
-            LOG.info("Attempt to release a create lock on " + src.toString() +
-                     " that was not in pendingCreates");
-          }
-        } else {
-          LOG.info("Attempt by " + holder.toString() + 
-                   " to release someone else's create lock on " + 
-                   src.toString());
+      FileUnderConstruction v = 
+        (FileUnderConstruction) pendingCreates.remove(src);
+      if (v != null) {
+        LOG.info("Removing " + src + " from pendingCreates for " + 
+            holder + " (failure)");
+        for (Iterator it2 = v.getBlocks().iterator(); it2.hasNext(); ) {
+          Block b = (Block) it2.next();
+          pendingCreateBlocks.remove(b);
         }
       } else {
-        LOG.info("Attempt to release a lock from an unknown lease holder "
-                 + holder.toString() + " for " + src.toString());
+        LOG.info("Attempt to release a create lock on " + src.toString()
+                 + " that was not in pendingCreates");
       }
     }