Browse Source

HADOOP-270. Fix potential deadlock in datanode shutdown. Contributed by Hairong.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@411288 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 years ago
parent
commit
e29d298212
2 changed files with 12 additions and 6 deletions
  1. 3 1
      CHANGES.txt
  2. 9 5
      src/java/org/apache/hadoop/dfs/DataNode.java

+ 3 - 1
CHANGES.txt

@@ -97,8 +97,10 @@ Trunk (unreleased)
 
 26. HADOOP-265.  Tasktracker now fails to start if it does not have a
     writable local directory for temporary files.  In this case, it
-    logs a message to the JobTracker and exits. (Hairong Kuang via cutting)  
+    logs a message to the JobTracker and exits. (Hairong Kuang via cutting)
 
+27. HADOOP-270.  Fix potential deadlock in datanode shutdown.
+    (Hairong Kuang via cutting)
 
 Release 0.2.1 - 2006-05-12
 

+ 9 - 5
src/java/org/apache/hadoop/dfs/DataNode.java

@@ -146,7 +146,6 @@ public class DataNode implements FSConstants, Runnable {
       // initialize data node internal structure
       this.data = new FSDataset(datadir, conf);
       this.dataXceiveServer = new Daemon(new DataXceiveServer(ss));
-      this.dataXceiveServer.start();
 
       long blockReportIntervalBasis =
         conf.getLong("dfs.blockreport.intervalMsec", BLOCKREPORT_INTERVAL);
@@ -188,10 +187,6 @@ public class DataNode implements FSConstants, Runnable {
     void shutdown() {
         this.shouldRun = false;
         ((DataXceiveServer) this.dataXceiveServer.getRunnable()).kill();
-        try {
-            this.dataXceiveServer.join();
-        } catch (InterruptedException ie) {
-        }
         try {
           this.storage.close();
         } catch (IOException ie) {
@@ -213,6 +208,9 @@ public class DataNode implements FSConstants, Runnable {
      * forever calling remote NameNode functions.
      */
     public void offerService() throws Exception {
+      // start dataXceiveServer  
+      dataXceiveServer.start();
+      
       long lastHeartbeat = 0, lastBlockReport = 0;
       LOG.info("using BLOCKREPORT_INTERVAL of " + blockReportInterval + "msec");
 
@@ -329,6 +327,12 @@ public class DataNode implements FSConstants, Runnable {
       } catch(DiskErrorException e) {
         handleDiskError(e.getMessage());
       }
+      
+      // wait for dataXceiveServer to terminate
+      try {
+          this.dataXceiveServer.join();
+      } catch (InterruptedException ie) {
+      }
     } // offerService
 
     /**