From d177b9b9a20e8ed265a111f8efc0789508806226 Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Wed, 16 Apr 2014 16:35:56 +0000 Subject: [PATCH] HBASE-10995 Fix resource leak related to unclosed HBaseAdmin git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1587966 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/hadoop/hbase/util/HBaseFsck.java | 12 +++++++++++- .../java/org/apache/hadoop/hbase/util/HMerge.java | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index e59969ac97b..c73d8a3ba82 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -2722,11 +2722,21 @@ public class HBaseFsck extends Configured { HTableDescriptor[] getHTableDescriptors(List tableNames) { HTableDescriptor[] htd = new HTableDescriptor[0]; + HBaseAdmin admin = null; try { LOG.info("getHTableDescriptors == tableNames => " + tableNames); - htd = new HBaseAdmin(getConf()).getTableDescriptorsByTableName(tableNames); + admin = new HBaseAdmin(getConf()); + htd = admin.getTableDescriptorsByTableName(tableNames); } catch (IOException e) { LOG.debug("Exception getting table descriptors", e); + } finally { + if (admin != null) { + try { + admin.close(); + } catch (IOException e) { + LOG.debug("Exception closing HBaseAdmin", e); + } + } } return htd; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HMerge.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HMerge.java index 00c1c2b0936..80bf475a3bc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HMerge.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HMerge.java @@ -125,8 +125,12 @@ class HMerge { "HBase instance must be running to merge a normal table"); } HBaseAdmin admin = new HBaseAdmin(conf); - if (!admin.isTableDisabled(tableName)) { - throw new TableNotDisabledException(tableName); + try { + if (!admin.isTableDisabled(tableName)) { + throw new TableNotDisabledException(tableName); + } + } finally { + admin.close(); } new OnlineMerger(conf, fs, tableName).process(); }