Sfoglia il codice sorgente

Merge -r 736425:736426 to move the change of HADOOP-5009 from main t0 branch 0.20.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20@736429 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 16 anni fa
parent
commit
f78a32e601

+ 3 - 0
CHANGES.txt

@@ -619,6 +619,9 @@ Release 0.19.1 - Unreleased
     HADOOP-4967. Fixes a race condition in the JvmManager to do with killing
     tasks. (ddas)
 
+    HADOOP-5009. DataNode#shutdown sometimes leaves data block scanner
+    verification log unclosed. (hairong)
+
 Release 0.19.0 - 2008-11-18
 
   INCOMPATIBLE CHANGES

+ 8 - 2
src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataBlockScanner.java

@@ -517,6 +517,7 @@ class DataBlockScanner implements Runnable {
       verificationLog.updateCurNumLines();
     }
     
+    try {
     // update verification times from the verificationLog.
     while (logReader != null && logReader.hasNext()) {
       if (!datanode.shouldRun || Thread.interrupted()) {
@@ -527,6 +528,9 @@ class DataBlockScanner implements Runnable {
         updateBlockInfo(entry);
       }
     }
+    } finally {
+      IOUtils.closeStream(logReader);
+    }
     
     /* Initially spread the block reads over half of 
      * MIN_SCAN_PERIOD so that we don't keep scanning the 
@@ -590,12 +594,12 @@ class DataBlockScanner implements Runnable {
           } catch (InterruptedException ignored) {}
         }
       }
-      shutdown();
     } catch (RuntimeException e) {
       LOG.warn("RuntimeException during DataBlockScanner.run() : " +
                StringUtils.stringifyException(e));
       throw e;
     } finally {
+      shutdown();
       LOG.info("Exiting DataBlockScanner thread.");
     }
   }
@@ -783,8 +787,9 @@ class DataBlockScanner implements Runnable {
     //This reads the current file and updates the count.
     void updateCurNumLines() {
       int count = 0;
+      Reader it = null;
       try {
-        for(Reader it = new Reader(true); it.hasNext(); count++) {
+        for(it = new Reader(true); it.hasNext(); count++) {
           it.next();
         }
       } catch (IOException e) {
@@ -793,6 +798,7 @@ class DataBlockScanner implements Runnable {
         synchronized (this) {
           curNumLines = count;
         }
+        IOUtils.closeStream(it);
       }
     }
     

+ 6 - 3
src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -599,10 +599,13 @@ public class DataNode extends Configured
     
     if(upgradeManager != null)
       upgradeManager.shutdownUpgrade();
-    if (blockScanner != null)
-      blockScanner.shutdown();
-    if (blockScannerThread != null) 
+    if (blockScannerThread != null) { 
       blockScannerThread.interrupt();
+      try {
+        blockScannerThread.join(3600000L); // wait for at most 1 hour
+      } catch (InterruptedException ie) {
+      }
+    }
     if (storage != null) {
       try {
         this.storage.unlockAll();