You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2020/07/29 17:55:21 UTC

[GitHub] [hbase] sandeepvinayak commented on a change in pull request #2162: HBASE-24788: Fix the connection leaks on getting hbase admin from unclosed connection

sandeepvinayak commented on a change in pull request #2162:
URL: https://github.com/apache/hbase/pull/2162#discussion_r462140532



##########
File path: hbase-server/src/main/java/org/apache/hadoop/hbase/util/ServerRegionReplicaUtil.java
##########
@@ -161,25 +162,24 @@ public static void setupRegionReplicaReplication(Configuration conf) throws IOEx
     if (!isRegionReplicaReplicationEnabled(conf)) {
       return;
     }
-    Admin admin = ConnectionFactory.createConnection(conf).getAdmin();
-    ReplicationPeerConfig peerConfig = null;
-    try {
+
+    try (Connection connection = ConnectionFactory.createConnection(conf);
+      Admin admin = connection.getAdmin()) {
+      ReplicationPeerConfig peerConfig = null;
       peerConfig = admin.getReplicationPeerConfig(REGION_REPLICA_REPLICATION_PEER);
-    } catch (ReplicationPeerNotFoundException e) {
-      LOG.warn("Region replica replication peer id=" + REGION_REPLICA_REPLICATION_PEER
-          + " not exist", e);
-    }
-    try {
+
       if (peerConfig == null) {
         LOG.info("Region replica replication peer id=" + REGION_REPLICA_REPLICATION_PEER
-            + " not exist. Creating...");
+          + " not exist. Creating...");
         peerConfig = new ReplicationPeerConfig();
         peerConfig.setClusterKey(ZKConfig.getZooKeeperClusterKey(conf));
         peerConfig.setReplicationEndpointImpl(RegionReplicaReplicationEndpoint.class.getName());
         admin.addReplicationPeer(REGION_REPLICA_REPLICATION_PEER, peerConfig);
       }
-    } finally {
-      admin.close();
+    } catch (ReplicationPeerNotFoundException e) {
+      LOG.warn(
+        "Region replica replication peer id=" + REGION_REPLICA_REPLICATION_PEER + " not exist",
+        e);

Review comment:
       yeah, I was about to submit the change for this.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org