Просмотр исходного кода

Merge -r 755034:755035 to move the change of HADOOP-5414 from main to branch 0.20.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20@755038 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 лет назад
Родитель
Сommit
7cf01f513c

+ 4 - 0
CHANGES.txt

@@ -731,6 +731,10 @@ Release 0.20.0 - Unreleased
     HADOOP-5505. Fix JspHelper initialization in the context of
     MiniDFSCluster. (Raghu Angadi)
 
+    HADOOP-5414. Fixes IO exception while executing hadoop fs -touchz fileName by
+    making sure that lease renewal thread exits before dfs client exits.
+    (hairong)
+
 Release 0.19.2 - Unreleased
 
   BUG FIXES

+ 17 - 6
src/hdfs/org/apache/hadoop/hdfs/DFSClient.java

@@ -208,6 +208,10 @@ public class DFSClient implements FSConstants, java.io.Closeable {
     if(clientRunning) {
       leasechecker.close();
       clientRunning = false;
+      try {
+        leasechecker.interruptAndJoin();
+      } catch (InterruptedException ie) {
+      }
   
       // close connections to the namenode
       RPC.stopProxy(rpcNamenode);
@@ -975,9 +979,18 @@ public class DFSClient implements FSConstants, java.io.Closeable {
       pendingCreates.remove(src);
     }
     
-    synchronized void interrupt() {
-      if (daemon != null) {
-        daemon.interrupt();
+    void interruptAndJoin() throws InterruptedException {
+      Daemon daemonCopy = null;
+      synchronized (this) {
+        if (daemon != null) {
+          daemon.interrupt();
+          daemonCopy = daemon;
+        }
+      }
+     
+      if (daemonCopy != null) {
+        LOG.debug("Wait for lease checker to terminate");
+        daemonCopy.join();
       }
     }
 
@@ -993,8 +1006,6 @@ public class DFSClient implements FSConstants, java.io.Closeable {
           }
         }
       }
-      
-      interrupt();
     }
 
     private void renew() throws IOException {
@@ -1012,7 +1023,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
      */
     public void run() {
       long lastRenewed = 0;
-      while (clientRunning) {
+      while (clientRunning && !Thread.interrupted()) {
         if (System.currentTimeMillis() - lastRenewed > (LEASE_SOFTLIMIT_PERIOD / 2)) {
           try {
             renew();

+ 2 - 2
src/test/org/apache/hadoop/hdfs/TestLeaseRecovery2.java

@@ -80,8 +80,8 @@ public class TestLeaseRecovery2 extends junit.framework.TestCase {
       // sync file
       AppendTestUtil.LOG.info("sync");
       stm.sync();
-      AppendTestUtil.LOG.info("leasechecker.interrupt()");
-      dfs.dfs.leasechecker.interrupt();
+      AppendTestUtil.LOG.info("leasechecker.interruptAndJoin()");
+      dfs.dfs.leasechecker.interruptAndJoin();
 
       // set the soft limit to be 1 second so that the
       // namenode triggers lease recovery on next attempt to write-for-open.