From 4123650e92c5b2fee121fb33c1ed62da010174ef Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Wed, 2 Dec 2015 17:39:28 -0800 Subject: [PATCH] HDFS-9294. DFSClient deadlock when close file and failed to renew lease. Contributed by Brahma Reddy Battula --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../apache/hadoop/hdfs/DFSOutputStream.java | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6d902f3c2f5..074e7790612 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -123,6 +123,9 @@ Release 2.7.2 - UNRELEASED HDFS-9426. Rollingupgrade finalization is not backward compatible (Kihwal Lee via vinayakumarb) + HDFS-9294. DFSClient deadlock when close file and failed to renew lease. + (Brahma Reddy Battula via szetszwo) + Release 2.7.1 - 2015-07-06 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java index 3c8b2d39542..e8080eea61f 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java @@ -2174,13 +2174,15 @@ public class DFSOutputStream extends FSOutputSummer * Aborts this output stream and releases any system * resources associated with this stream. */ - synchronized void abort() throws IOException { - if (isClosed()) { - return; + void abort() throws IOException { + synchronized (this) { + if (isClosed()) { + return; + } + streamer.setLastException(new IOException("Lease timeout of " + + (dfsClient.getHdfsTimeout() / 1000) + " seconds expired.")); + closeThreads(true); } - streamer.setLastException(new IOException("Lease timeout of " - + (dfsClient.getHdfsTimeout()/1000) + " seconds expired.")); - closeThreads(true); dfsClient.endFileLease(fileId); } @@ -2226,14 +2228,17 @@ public class DFSOutputStream extends FSOutputSummer * resources associated with this stream. */ @Override - public synchronized void close() throws IOException { - TraceScope scope = - dfsClient.getPathTraceScope("DFSOutputStream#close", src); - try { - closeImpl(); - } finally { - scope.close(); + public void close() throws IOException { + synchronized (this) { + TraceScope scope = dfsClient.getPathTraceScope("DFSOutputStream#close", + src); + try { + closeImpl(); + } finally { + scope.close(); + } } + dfsClient.endFileLease(fileId); } private synchronized void closeImpl() throws IOException { @@ -2268,7 +2273,6 @@ public class DFSOutputStream extends FSOutputSummer } finally { scope.close(); } - dfsClient.endFileLease(fileId); } catch (ClosedChannelException e) { } finally { setClosed();