You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2016/01/16 16:39:49 UTC

hadoop git commit: HDFS-9294. DFSClient deadlock when close file and failed to renew lease. Contributed by Brahma Reddy Battula

Repository: hadoop
Updated Branches:
  refs/heads/branch-2.6 cbc3288b5 -> b05bb4984


HDFS-9294. DFSClient deadlock when close file and failed to renew lease.  Contributed by Brahma Reddy Battula


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b05bb498
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b05bb498
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b05bb498

Branch: refs/heads/branch-2.6
Commit: b05bb4984dcbb8bc09ce294b586d866049bb2d2a
Parents: cbc3288
Author: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Authored: Sat Jan 16 23:39:08 2016 +0800
Committer: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Committed: Sat Jan 16 23:39:08 2016 +0800

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  3 +
 .../org/apache/hadoop/hdfs/DFSOutputStream.java | 73 +++++++++++---------
 2 files changed, 42 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b05bb498/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index f1a18e2..a5e04c4 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -38,6 +38,9 @@ Release 2.6.4 - UNRELEASED
     HDFS-8767. RawLocalFileSystem.listStatus() returns null for UNIX pipefile.
     (Kanaka Kumar Avvaru via wheat9)
 
+    HDFS-9294. DFSClient deadlock when close file and failed to renew lease.
+    (Brahma Reddy Battula via szetszwo)
+
 Release 2.6.3 - 2015-12-17
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b05bb498/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
----------------------------------------------------------------------
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 21e4d4e..942653c 100644
--- 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
@@ -2171,13 +2171,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 (closed) {
-      return;
+  void abort() throws IOException {
+    synchronized (this) {
+      if (closed) {
+        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);
   }
 
@@ -2204,39 +2206,42 @@ public class DFSOutputStream extends FSOutputSummer
    * resources associated with this stream.
    */
   @Override
-  public synchronized void close() throws IOException {
-    if (closed) {
-      IOException e = lastException.getAndSet(null);
-      if (e == null)
-        return;
-      else
-        throw e;
-    }
+  public void close() throws IOException {
+    synchronized (this) {
+      if (closed) {
+        IOException e = lastException.getAndSet(null);
+        if (e == null)
+          return;
+        else
+          throw e;
+      }
 
-    try {
-      flushBuffer();       // flush from all upper layers
+      try {
+        flushBuffer();       // flush from all upper layers
 
-      if (currentPacket != null) { 
-        waitAndQueueCurrentPacket();
-      }
+        if (currentPacket != null) {
+          waitAndQueueCurrentPacket();
+        }
 
-      if (bytesCurBlock != 0) {
-        // send an empty packet to mark the end of the block
-        currentPacket = createPacket(0, 0, bytesCurBlock, currentSeqno++);
-        currentPacket.lastPacketInBlock = true;
-        currentPacket.syncBlock = shouldSyncBlock;
-      }
+        if (bytesCurBlock != 0) {
+          // send an empty packet to mark the end of the block
+          currentPacket = createPacket(0, 0, bytesCurBlock, currentSeqno++);
+          currentPacket.lastPacketInBlock = true;
+          currentPacket.syncBlock = shouldSyncBlock;
+        }
 
-      flushInternal();             // flush all data to Datanodes
-      // get last block before destroying the streamer
-      ExtendedBlock lastBlock = streamer.getBlock();
-      closeThreads(false);
-      completeFile(lastBlock);
-      dfsClient.endFileLease(fileId);
-    } catch (ClosedChannelException e) {
-    } finally {
-      closed = true;
+        flushInternal();             // flush all data to Datanodes
+        // get last block before destroying the streamer
+        ExtendedBlock lastBlock = streamer.getBlock();
+        closeThreads(false);
+        completeFile(lastBlock);
+
+      } catch (ClosedChannelException e) {
+      } finally {
+        closed = true;
+      }
     }
+    dfsClient.endFileLease(fileId);
   }
 
   // should be called holding (this) lock since setTestFilename() may