Преглед изворни кода

HDFS-9812. Streamer threads leak if failure happens when closing DFSOutputStream. Contributed by Lin Yiqun.

(cherry picked from commit 352d299cf8ebe330d24117df98d1e6a64ae38c26)
(cherry picked from commit fe0009a2bd17e26f9e9364ec3f772e9a3f138de8)
Akira Ajisaka пре 9 година
родитељ
комит
7f43eb9547

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -138,6 +138,9 @@ Release 2.7.3 - UNRELEASED
     HDFS-9865. TestBlockReplacement fails intermittently in trunk
     (Lin Yiqun via iwasakims)
 
+    HDFS-9812. Streamer threads leak if failure happens when closing
+    DFSOutputStream. (Lin Yiqun via aajisaka)
+
 Release 2.7.2 - 2016-01-25
 
   INCOMPATIBLE CHANGES

+ 6 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java

@@ -2262,7 +2262,6 @@ public class DFSOutputStream extends FSOutputSummer
       flushInternal();             // flush all data to Datanodes
       // get last block before destroying the streamer
       ExtendedBlock lastBlock = streamer.getBlock();
-      closeThreads(false);
       TraceScope scope = Trace.startSpan("completeFile", Sampler.NEVER);
       try {
         completeFile(lastBlock);
@@ -2271,7 +2270,12 @@ public class DFSOutputStream extends FSOutputSummer
       }
     } catch (ClosedChannelException e) {
     } finally {
-      setClosed();
+      // Failures may happen when flushing data.
+      // Streamers may keep waiting for the new block information.
+      // Thus need to force closing these threads.
+      // Don't need to call setClosed() because closeThreads(true)
+      // calls setClosed() in the finally block.
+      closeThreads(true);
     }
   }