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

Hiroshi Ikeda commented on HBASE-15803:
---------------------------------------

That should work well except it is better to restore interruption by calling 
Thread.currentThread().interrupt(), and that is the most simple way to fix.

If we can do more changes, there is another way; createBaseZNodes() is well 
created so that it might be better to be explicitly called from outside the 
instance. In other words, create a static factory method with (or without) 
making the constructor private:

{code}
public static ZooKeeperWatcher open(...) {
   ....
   ZooKeeperWatcher zk = ...
   if (...) {
     try {
       zk.createBaseZNodes();
     } catch (Exception e) {
        zk.close();
        throw e;
     }
}
{code}

Or make createBaseZNodes() public and explicitly call it instead of passing the 
magic boolean argument canCreateBaseZNode to the ZooKeeperWatcher constructor. 
Also the condition of throwing IOException is icky, and it is preferable if we 
can separate the concern and make the constructor throw no exception, but more 
consideration and changes might be required.


> ZooKeeperWatcher's constructor can leak a ZooKeeper instance with throwing 
> ZooKeeperConnectionException when canCreateBaseZNode is true
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HBASE-15803
>                 URL: https://issues.apache.org/jira/browse/HBASE-15803
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Hiroshi Ikeda
>            Assignee: Ted Yu
>            Priority: Minor
>         Attachments: 15803.v1.txt
>
>
> {code}
>   public ZooKeeperWatcher(Configuration conf, String identifier,
>       Abortable abortable, boolean canCreateBaseZNode)
>   throws IOException, ZooKeeperConnectionException {
> ...skip...
>     this.recoverableZooKeeper = ZKUtil.connect(...
> ...skip...
>     if (canCreateBaseZNode) {
>       createBaseZNodes();
>     }
>   }
>   private void createBaseZNodes() throws ZooKeeperConnectionException {
> {code}
> The registered watcher doesn't seem to close the Zookeeper instance by watch 
> events, and the instance keeps alive when createBaseZNodes is failed.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to