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

(cherry picked from commit 352d299cf8)
(cherry picked from commit fe0009a2bd)
This commit is contained in:
Akira Ajisaka 2016-03-08 10:43:17 +09:00
parent 352d5a7e88
commit d84d54e26c
1 changed files with 7 additions and 2 deletions

View File

@ -774,14 +774,19 @@ public class DFSOutputStream extends FSOutputSummer
flushInternal(); // flush all data to Datanodes
// get last block before destroying the streamer
ExtendedBlock lastBlock = getStreamer().getBlock();
closeThreads(false);
try (TraceScope ignored =
dfsClient.getTracer().newScope("completeFile")) {
completeFile(lastBlock);
}
} catch (ClosedChannelException ignored) {
} 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);
}
}