HBASE-14394 Properly close the connection after reading records from table.

This commit is contained in:
Srikanth Srungarapu 2015-09-15 11:02:00 -07:00
parent f51c79076d
commit 938d2a0c9c
2 changed files with 10 additions and 3 deletions

View File

@ -107,11 +107,10 @@ public abstract class MultiTableInputFormatBase extends
sc.setStopRow(tSplit.getEndRow());
trr.setScan(sc);
trr.setTable(table);
trr.setConnection(connection);
} catch (IOException ioe) {
// If there is an exception make sure that all
// resources are closed and released.
connection.close();
table.close();
trr.close();
throw ioe;
}

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
@ -40,6 +41,7 @@ public class TableRecordReader
extends RecordReader<ImmutableBytesWritable, Result> {
private TableRecordReaderImpl recordReaderImpl = new TableRecordReaderImpl();
private Connection connection = null;
/**
* Restart from survivable exceptions by creating a new scanner.
@ -85,8 +87,10 @@ extends RecordReader<ImmutableBytesWritable, Result> {
* @see org.apache.hadoop.mapreduce.RecordReader#close()
*/
@Override
public void close() {
public void close() throws IOException {
this.recordReaderImpl.close();
if (this.connection != null)
this.connection.close();
}
/**
@ -157,4 +161,8 @@ extends RecordReader<ImmutableBytesWritable, Result> {
public float getProgress() {
return this.recordReaderImpl.getProgress();
}
public void setConnection(Connection connection) {
this.connection = connection;
}
}