You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Karthick Sankarachary (JIRA)" <ji...@apache.org> on 2011/08/19 22:06:27 UTC

[jira] [Commented] (HBASE-4167) Potential leak of HTable instances when using HTablePool with PoolType.ThreadLocal

    [ https://issues.apache.org/jira/browse/HBASE-4167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13087927#comment-13087927 ] 

Karthick Sankarachary commented on HBASE-4167:
----------------------------------------------

To address the leak described above, I feel that we should explicitly remove the {{HTableInstance}} to be released from the {{PoolMap}}. And, for good measure, we should clear the {{PoolMap}} when the {{HTablePool}} is closed. Please review the corresponding patch, which passes all unit tests.

> Potential leak of HTable instances when using HTablePool with PoolType.ThreadLocal
> ----------------------------------------------------------------------------------
>
>                 Key: HBASE-4167
>                 URL: https://issues.apache.org/jira/browse/HBASE-4167
>             Project: HBase
>          Issue Type: Bug
>          Components: client
>            Reporter: Gary Helmling
>             Fix For: 0.92.0
>
>         Attachments: HBASE-4167.patch
>
>
> (Initially discussed in HBASE-4150)
> In HTablePool, when obtaining a table:
> {code}
> private HTableInterface findOrCreateTable(String tableName) {
>     HTableInterface table = tables.get(tableName);
>     if (table == null) {
>       table = createHTable(tableName);
>     }
>     return table;
>   }
> {code}
> In the case of {{ThreadLocalPool}}, it seems like there's an exposure here between when the table is created initially and when {{ThreadLocalPool.put()}} is called to set the thread local variable (on {{PooledHTable.close()}}).
> Potential solution described by Karthick Sankarachary:
> For one thing, we might want to clear the tables variable when the {{HTablePool}} is closed (as shown below). For another, we should override ThreadLocalPool#get method so that it removes the resource, otherwise it might end up referencing a HTableInterface that's has been released.
> {code}
> 1 diff --git a/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java b/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java
>       2 index 952a3aa..c198f15 100755
>       3 --- a/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java
>       4 +++ b/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java
>      13 @@ -309,6 +310,7 @@ public class HTablePool implements Closeable {
>      14      for (String tableName : tables.keySet()) {
>      15        closeTablePool(tableName);
>      16      }
>      17 +    this.tables.clear();
>      18    }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira