Skip to content

Commit 938d2a0

Browse files
author
Srikanth Srungarapu
committed
HBASE-14394 Properly close the connection after reading records from table.
1 parent f51c790 commit 938d2a0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/MultiTableInputFormatBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@ public RecordReader<ImmutableBytesWritable, Result> createRecordReader(
107107
sc.setStopRow(tSplit.getEndRow());
108108
trr.setScan(sc);
109109
trr.setTable(table);
110+
trr.setConnection(connection);
110111
} catch (IOException ioe) {
111112
// If there is an exception make sure that all
112113
// resources are closed and released.
113-
connection.close();
114-
table.close();
115114
trr.close();
116115
throw ioe;
117116
}

hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableRecordReader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.hadoop.hbase.classification.InterfaceAudience;
2424
import org.apache.hadoop.hbase.classification.InterfaceStability;
25+
import org.apache.hadoop.hbase.client.Connection;
2526
import org.apache.hadoop.hbase.client.Result;
2627
import org.apache.hadoop.hbase.client.Scan;
2728
import org.apache.hadoop.hbase.client.Table;
@@ -40,6 +41,7 @@ public class TableRecordReader
4041
extends RecordReader<ImmutableBytesWritable, Result> {
4142

4243
private TableRecordReaderImpl recordReaderImpl = new TableRecordReaderImpl();
44+
private Connection connection = null;
4345

4446
/**
4547
* Restart from survivable exceptions by creating a new scanner.
@@ -85,8 +87,10 @@ public void setScan(Scan scan) {
8587
* @see org.apache.hadoop.mapreduce.RecordReader#close()
8688
*/
8789
@Override
88-
public void close() {
90+
public void close() throws IOException {
8991
this.recordReaderImpl.close();
92+
if (this.connection != null)
93+
this.connection.close();
9094
}
9195

9296
/**
@@ -157,4 +161,8 @@ public boolean nextKeyValue() throws IOException, InterruptedException {
157161
public float getProgress() {
158162
return this.recordReaderImpl.getProgress();
159163
}
164+
165+
public void setConnection(Connection connection) {
166+
this.connection = connection;
167+
}
160168
}

0 commit comments

Comments
 (0)