hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-16017 HBase TableOutputFormat has connection leak in getRecordWriter (Zhan Zhang)
Date Wed, 15 Jun 2016 16:18:31 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 8a0e135a3 -> cc50bfcc7


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/cc50bfcc
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/cc50bfcc
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/cc50bfcc

Branch: refs/heads/branch-1
Commit: cc50bfcc726e0fb05b5c8364ae2b6c9a1f9bce53
Parents: 8a0e135
Author: tedyu <yuzhihong@gmail.com>
Authored: Wed Jun 15 09:18:18 2016 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Wed Jun 15 09:18:18 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/cc50bfcc/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 6e0d9e7..08af0d3 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 {
@@ -75,14 +86,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


Mime
View raw message