You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by sy...@apache.org on 2016/06/17 05:01:56 UTC

[14/30] hbase git commit: HBASE-16017 HBase TableOutputFormat has connection leak in getRecordWriter (Zhan Zhang)

HBASE-16017 HBase TableOutputFormat has connection leak in getRecordWriter (Zhan Zhang)


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

Branch: refs/heads/hbase-12439
Commit: 6c60bc9f6cf0f62c8557296dcab9335b680951b5
Parents: db234bf
Author: tedyu <yu...@gmail.com>
Authored: Wed Jun 15 06:32:23 2016 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Wed Jun 15 06:32:23 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/mapred/TableOutputFormat.java  | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/6c60bc9f/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableOutputFormat.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableOutputFormat.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableOutputFormat.java
index dd72939..18b54da 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableOutputFormat.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableOutputFormat.java
@@ -53,7 +53,7 @@ public class TableOutputFormat extends FileOutputFormat<ImmutableBytesWritable,
    */
   protected static class TableRecordWriter implements RecordWriter<ImmutableBytesWritable, Put> {
     private BufferedMutator m_mutator;
-
+    private Connection connection;
     /**
      * Instantiate a TableRecordWriter with the HBase HClient for writing. Assumes control over the
      * lifecycle of {@code conn}.
@@ -62,8 +62,19 @@ public class TableOutputFormat extends FileOutputFormat<ImmutableBytesWritable,
       this.m_mutator = mutator;
     }
 
+    public TableRecordWriter(JobConf job) throws IOException {
+      // expecting exactly one path
+      TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));
+      connection = ConnectionFactory.createConnection(job);
+      m_mutator = connection.getBufferedMutator(tableName);
+    }
+
     public void close(Reporter reporter) throws IOException {
       this.m_mutator.close();
+      if (connection != null) {
+        connection.close();
+        connection = null;
+      }
     }
 
     public void write(ImmutableBytesWritable key, Put value) throws IOException {
@@ -90,14 +101,7 @@ public class TableOutputFormat extends FileOutputFormat<ImmutableBytesWritable,
   public RecordWriter getRecordWriter(FileSystem ignored, JobConf job, String name,
       Progressable progress)
   throws IOException {
-    // expecting exactly one path
-    TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));
-    BufferedMutator mutator =  null;
-    // Connection is not closed. Dies with JVM.  No possibility for cleanup.
-    Connection connection = ConnectionFactory.createConnection(job);
-    mutator = connection.getBufferedMutator(tableName);
-    // Clear write buffer on fail is true by default so no need to reset it.
-    return new TableRecordWriter(mutator);
+    return new TableRecordWriter(job);
   }
 
   @Override