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

Rakesh R commented on ZOOKEEPER-1910:
-------------------------------------

In server, its keeping single watcher reference against an znode. Now the 
difficulty here is server needs to decide when it can remove the watcher 
reference.
{code}
WatchManager.java

    private final HashMap<String, HashSet<Watcher>> watchTable =
        new HashMap<String, HashSet<Watcher>>();
{code}

For example: 

In my tests I have two watchers defined in the client side "/node1" - w1, w2. 
As we know in the server it will have only one 'watcher reference' for each 
client like, '/node1' vs zkClient1. Now if user call removeWatcher("/node1", 
w1), presently it is removing the 'watcher reference' from the server. Here w2 
is not taken into consideration at the server side and later the 'zkClient1' 
won't get any watch notifications.

Simple way to fix is, server shouldn't remove the 'watcher reference' on 
RemoveWatch request, remove it only when expiring or triggering time. But this 
will have the overhead of unnecessarily holding the refernce even after all the 
watchers are removed successfully for a path.

Second approach is to have a counter at the server side and which will decr it 
after every RemoveWatch request from the client. When it reaches zero, now 
server can do the cleanup like,
{code}
    private final HashMap<String, HashMap<Watcher, Integer>> watchTable =
        new HashMap<String, HashMap<Watcher, Integer>>();
{code}
Here I could see an over head of keeping one additional parameter and will 
increase the memory utilization.

> RemoveWatches wrongly removes the watcher if multiple watches exists on a path
> ------------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-1910
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1910
>             Project: ZooKeeper
>          Issue Type: Bug
>            Reporter: Rakesh R
>            Assignee: Rakesh R
>             Fix For: 3.5.0
>
>         Attachments: ZOOKEEPER-1910.patch
>
>
> Consider a case where zkclient has added 2 data watchers(say 'w1' and 'w2') 
> on '/node1'.
> Now user has removed w1, but this is deleting the 'CnxnWatcher' in ZK server 
> against the "/node1" path. This will affect other data watchers(if any) of 
> same client on same path. In our case 'w2' would not be notified.
> Note: please see the attached test case to understand more.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to