hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r725521 - in /hadoop/core/branches/branch-0.18: CHANGES.txt src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java src/hdfs/org/apache/hadoop/dfs/LeaseManager.java
Date Thu, 11 Dec 2008 01:28:04 GMT
Author: szetszwo
Date: Wed Dec 10 17:28:03 2008
New Revision: 725521

URL: http://svn.apache.org/viewvc?rev=725521&view=rev
Log:
HADOOP-4795. Prevent lease monitor getting into an infinite loop when leases and the namespace
tree does not match. (szetszwo)

Modified:
    hadoop/core/branches/branch-0.18/CHANGES.txt
    hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
    hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/LeaseManager.java

Modified: hadoop/core/branches/branch-0.18/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/CHANGES.txt?rev=725521&r1=725520&r2=725521&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.18/CHANGES.txt Wed Dec 10 17:28:03 2008
@@ -91,6 +91,9 @@
     HADOOP-4806. HDFS rename should not use src path as a regular expression.
     (szetszwo)
 
+    HADOOP-4795. Prevent lease monitor getting into an infinite loop when
+    leases and the namespace tree does not match. (szetszwo)
+
 Release 0.18.2 - 2008-11-03
 
   BUG FIXES

Modified: hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java?rev=725521&r1=725520&r2=725521&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java Wed
Dec 10 17:28:03 2008
@@ -302,7 +302,7 @@
                             conf.getInt("dfs.replication.pending.timeout.sec", 
                                         -1) * 1000L);
     this.hbthread = new Daemon(new HeartbeatMonitor());
-    this.lmthread = new Daemon(leaseManager.createMonitor());
+    this.lmthread = new Daemon(leaseManager.new Monitor());
     this.replthread = new Daemon(new ReplicationMonitor());
     this.resthread = new Daemon(new ResolutionMonitor());
     hbthread.start();
@@ -1694,20 +1694,18 @@
 
     INodeFile iFile = dir.getFileINode(src);
     if (iFile == null) {
-      NameNode.stateChangeLog.warn("DIR* NameSystem.internalReleaseCreate: "
-                                   + "attempt to release a create lock on "
-                                   + src + " file does not exist.");
-      return;
+      final String message = "DIR* NameSystem.internalReleaseCreate: "
+        + "attempt to release a create lock on "
+        + src + " file does not exist.";
+      NameNode.stateChangeLog.warn(message);
+      throw new IOException(message);
     }
     if (!iFile.isUnderConstruction()) {
-      NameNode.stateChangeLog.warn("DIR* NameSystem.internalReleaseCreate: "
-                                   + "attempt to release a create lock on "
-                                   + src + " but file is already closed.");
-      return;
-    }
-    if (NameNode.stateChangeLog.isDebugEnabled()) {
-      NameNode.stateChangeLog.debug("DIR* NameSystem.internalReleaseCreate: "
-          + src + " does not being written in " + lease);
+      final String message = "DIR* NameSystem.internalReleaseCreate: "
+        + "attempt to release a create lock on "
+        + src + " but file is already closed.";
+      NameNode.stateChangeLog.warn(message);
+      throw new IOException(message);
     }
 
     INodeFileUnderConstruction pendingFile = (INodeFileUnderConstruction) iFile;

Modified: hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/LeaseManager.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/LeaseManager.java?rev=725521&r1=725520&r2=725521&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/LeaseManager.java (original)
+++ hadoop/core/branches/branch-0.18/src/hdfs/org/apache/hadoop/dfs/LeaseManager.java Wed
Dec 10 17:28:03 2008
@@ -332,43 +332,59 @@
     this.hardLimit = hardLimit; 
   }
   
-  Monitor createMonitor() {return new Monitor();}
-
   /******************************************************
    * Monitor checks for leases that have expired,
    * and disposes of them.
    ******************************************************/
   class Monitor implements Runnable {
+    final String name = getClass().getSimpleName();
+
+    /** Check leases periodically. */
     public void run() {
-      try {
-        while (fsnamesystem.isRunning()) {
-          synchronized (fsnamesystem) {
-            synchronized (LeaseManager.this) {
-              Lease top;
-              while ((sortedLeases.size() > 0) &&
-                     ((top = sortedLeases.first()) != null)) {
-                if (top.expiredHardLimit()) {
-                  LOG.info("Lease Monitor: Removing lease " + top
-                      + ", sortedLeases.size()=: " + sortedLeases.size());
-                  for(StringBytesWritable s : top.paths) {
-                    fsnamesystem.internalReleaseLease(top, s.getString());
-                  }
-                } else {
-                  break;
-                }
-              }
-            }
+      for(; fsnamesystem.isRunning(); ) {
+        synchronized(fsnamesystem) {
+          checkLeases();
+        }
+
+        try {
+          Thread.sleep(2000);
+        } catch(InterruptedException ie) {
+          if (LOG.isDebugEnabled()) {
+            LOG.debug(name + " is interrupted", ie);
           }
+        }
+      }
+    }
+
+    /** Check the leases beginning from the oldest. */
+    private synchronized void checkLeases() {
+      for(; sortedLeases.size() > 0; ) {
+        final Lease oldest = sortedLeases.first();
+        if (!oldest.expiredHardLimit()) {
+          return;
+        }
+
+        LOG.info(name + ": Lease " + oldest + " has expired hard limit");
+
+        final List<StringBytesWritable> removing = new ArrayList<StringBytesWritable>();
+        for(StringBytesWritable p : oldest.getPaths()) {
           try {
-            Thread.sleep(2000);
-          } catch(InterruptedException ie) {
-            if (LOG.isDebugEnabled()) {
-              LOG.debug(getClass().getName() + " is interrupted", ie);
-            }
+            fsnamesystem.internalReleaseLease(oldest, p.getString());
+          } catch (IOException e) {
+            LOG.error("In " + name + ", cannot release the path " + p
+                + " in the lease " + oldest, e);
+            removing.add(p);
+          }
+        }
+
+        for(StringBytesWritable p : removing) {
+          try {
+            removeLease(oldest, p.getString());
+          } catch (IOException e) {
+            LOG.error("In " + name + ", cannot removeLease: oldest="
+                + oldest + ", p=" + p, e);
           }
         }
-      } catch(Exception e) {
-        LOG.error("In " + getClass().getName(), e);
       }
     }
   }



Mime
View raw message