HBASE-24788: Fix the connection leaks on getting hbase admin from unclosed connection (#2170)
Rewrote the patch for branch-1 since master has significanly diverged. (cherry picked from commit dc5ef7af1f8b9e386495a73924c9442203f65a77) Co-authored-by: Bharath Vissapragada <bharathv@apache.org> Signed-off-by: Bharath Vissapragada <bharathv@apache.org> Signed-off-by: Sandeep Pal <50725353+sandeepvinayak@users.noreply.github.com> Co-authored-by: Sandeep Pal <50725353+sandeepvinayak@users.noreply.github.com>
This commit is contained in:
parent
daeccb1c46
commit
ac576d23e5
|
@ -173,8 +173,8 @@ implements Configurable {
|
||||||
@Override
|
@Override
|
||||||
public void checkOutputSpecs(JobContext context) throws IOException,
|
public void checkOutputSpecs(JobContext context) throws IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
|
try (Connection conn = ConnectionFactory.createConnection(getConf());
|
||||||
try (Admin admin = ConnectionFactory.createConnection(getConf()).getAdmin()) {
|
Admin admin = conn.getAdmin()) {
|
||||||
TableName tableName = TableName.valueOf(this.conf.get(OUTPUT_TABLE));
|
TableName tableName = TableName.valueOf(this.conf.get(OUTPUT_TABLE));
|
||||||
if (!admin.tableExists(tableName)) {
|
if (!admin.tableExists(tableName)) {
|
||||||
throw new TableNotFoundException("Can't write, table does not exist:" +
|
throw new TableNotFoundException("Can't write, table does not exist:" +
|
||||||
|
|
|
@ -145,12 +145,10 @@ public class TestReplicationBase {
|
||||||
table.addFamily(fam);
|
table.addFamily(fam);
|
||||||
fam = new HColumnDescriptor(noRepfamName);
|
fam = new HColumnDescriptor(noRepfamName);
|
||||||
table.addFamily(fam);
|
table.addFamily(fam);
|
||||||
Connection connection1 = ConnectionFactory.createConnection(conf1);
|
Connection connection1 = utility1.getConnection();
|
||||||
Connection connection2 = ConnectionFactory.createConnection(conf2);
|
Connection connection2 = utility2.getConnection();
|
||||||
try (Admin admin1 = connection1.getAdmin()) {
|
try (Admin admin1 = connection1.getAdmin(); Admin admin2 = connection2.getAdmin()) {
|
||||||
admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
||||||
}
|
|
||||||
try (Admin admin2 = connection2.getAdmin()) {
|
|
||||||
admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
||||||
}
|
}
|
||||||
utility1.waitUntilAllRegionsAssigned(tableName);
|
utility1.waitUntilAllRegionsAssigned(tableName);
|
||||||
|
|
|
@ -518,12 +518,10 @@ public class TestReplicationSmallTests extends TestReplicationBase {
|
||||||
fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
|
fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
|
||||||
table.addFamily(fam);
|
table.addFamily(fam);
|
||||||
|
|
||||||
Connection connection1 = ConnectionFactory.createConnection(conf1);
|
try (Admin admin1 = utility1.getConnection().getAdmin()) {
|
||||||
Connection connection2 = ConnectionFactory.createConnection(conf2);
|
|
||||||
try (Admin admin1 = connection1.getAdmin()) {
|
|
||||||
admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
admin1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
||||||
}
|
}
|
||||||
try (Admin admin2 = connection2.getAdmin()) {
|
try (Admin admin2 = utility2.getConnection().getAdmin()) {
|
||||||
admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
admin2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
|
||||||
}
|
}
|
||||||
utility1.waitUntilAllRegionsAssigned(tablename);
|
utility1.waitUntilAllRegionsAssigned(tablename);
|
||||||
|
|
|
@ -303,14 +303,9 @@ public class TestNamespaceCommands extends SecureTestUtil {
|
||||||
AccessTestAction listAction = new AccessTestAction() {
|
AccessTestAction listAction = new AccessTestAction() {
|
||||||
@Override
|
@Override
|
||||||
public Object run() throws Exception {
|
public Object run() throws Exception {
|
||||||
Connection unmanagedConnection =
|
try (Connection conn = ConnectionFactory.createConnection(UTIL.getConfiguration());
|
||||||
ConnectionFactory.createConnection(UTIL.getConfiguration());
|
Admin admin = conn.getAdmin()) {
|
||||||
Admin admin = unmanagedConnection.getAdmin();
|
|
||||||
try {
|
|
||||||
return Arrays.asList(admin.listNamespaceDescriptors());
|
return Arrays.asList(admin.listNamespaceDescriptors());
|
||||||
} finally {
|
|
||||||
admin.close();
|
|
||||||
unmanagedConnection.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue