Repository: hadoop
Updated Branches:
  refs/heads/branch-2 4e0fcff8a -> f08e22767


HDFS-8870. Lease is leaked on write failure. Contributed by Kuhu Shukla.

(cherry picked from commit 4fcea8a0c8019d6d9a5e6f315c83659938b93a40)


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

Branch: refs/heads/branch-2
Commit: f08e2276714aaa604ea475d01cb42da61d142abb
Parents: 4e0fcff
Author: Kihwal Lee <kih...@apache.org>
Authored: Tue Nov 15 14:51:34 2016 -0600
Committer: Kihwal Lee <kih...@apache.org>
Committed: Tue Nov 15 14:51:34 2016 -0600

----------------------------------------------------------------------
 .../org/apache/hadoop/hdfs/DFSOutputStream.java  |  5 +----
 .../apache/hadoop/hdfs/TestDFSOutputStream.java  | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/f08e2276/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
index 8439dc8..1e549d9 100755
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java
@@ -726,8 +726,6 @@ public class DFSOutputStream extends FSOutputSummer
         b.add(e);
       }
     }
-
-    dfsClient.endFileLease(fileId);
     final IOException ioe = b.build();
     if (ioe != null) {
       throw ioe;
@@ -740,6 +738,7 @@ public class DFSOutputStream extends FSOutputSummer
 
   void setClosed() {
     closed = true;
+    dfsClient.endFileLease(fileId);
     getStreamer().release();
   }
 
@@ -773,8 +772,6 @@ public class DFSOutputStream extends FSOutputSummer
         b.add(e);
       }
     }
-
-    dfsClient.endFileLease(fileId);
     final IOException ioe = b.build();
     if (ioe != null) {
       throw ioe;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/f08e2276/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java
index d9df1ff..750103d 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java
@@ -50,6 +50,11 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyLong;
+import org.mockito.Mockito;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import org.mockito.internal.util.reflection.Whitebox;
 
 import static org.junit.Assert.assertEquals;
@@ -202,6 +207,20 @@ public class TestDFSOutputStream {
     assertEquals(1, 3 - numDataNodesWithData);
   }
 
+  @Test
+  public void testEndLeaseCall() throws Exception {
+    Configuration conf = new Configuration();
+    DFSClient client = new DFSClient(cluster.getNameNode(0)
+        .getNameNodeAddress(), conf);
+    DFSClient spyClient = Mockito.spy(client);
+    DFSOutputStream dfsOutputStream = spyClient.create("/file2",
+        FsPermission.getFileDefault(),
+        EnumSet.of(CreateFlag.CREATE), (short) 3, 1024, null , 1024, null);
+    DFSOutputStream spyDFSOutputStream = Mockito.spy(dfsOutputStream);
+    spyDFSOutputStream.closeThreads(anyBoolean());
+    verify(spyClient, times(1)).endFileLease(anyLong());
+  }
+
   @AfterClass
   public static void tearDown() {
     if (cluster != null) {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to