zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "CHQ (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ZOOKEEPER-3014) watch can be added to non-existed path by exist command
Date Wed, 28 Mar 2018 15:11:00 GMT

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

CHQ commented on ZOOKEEPER-3014:
--------------------------------

Sorry, "periodically " may be misleading. May be some other cases, for example, there are
threads continually  to watcher one znode by calling exist(). And during this time, the
znode is removed, can these watchers  be added to a path which znode is not exist? 

I am using curator 2.1.0 and zk is 3.4.5. The follow code is my test code. After I run this
code ,i wish all the watchers at server should removed, but after all the znode are removed,
some watchers stll exist. 
{code:java}
for (int i = 0; i < threadCount; i++) {
    final InterProcessMutex ipm = new InterProcessMutex(this.client, "/locks");
    final int seq = i;
    es.submit(new Runnable() {

        @Override
        public void run() {
            boolean acquire = false;
            try {
                //only one can acquire the locker
                acquire = ipm.acquire(20, TimeUnit.SECONDS);
                if (acquire) {
                    LOG.info("i am thread No.:" + seq);
                    //waiting
                    TimeUnit.SECONDS.sleep(30);
                } else {
                    LOG.info("acquired failed!, number:" + seq);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (acquire) {
                        LOG.info("i am released, number:" + seq);
                        ipm.release();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

}
{code}
The following picture shows the watchers are not removed. 

!image-2018-03-28-22-51-33-751.png!

 

 

 

> watch can be added to non-existed path by exist command
> -------------------------------------------------------
>
>                 Key: ZOOKEEPER-3014
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3014
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: server
>    Affects Versions: 3.4.5, 3.4.6
>            Reporter: CHQ
>            Priority: Major
>             Fix For: 3.4.12
>
>         Attachments: image-2018-03-28-22-51-33-751.png
>
>
> We have client A which create a znode ,and its path is /zk/lock/100000.  Another client
B thread is acquiring for the lock, so it calls the exist command with watch periodically
to check if it is available. Then Client A has finished this work, and  delete this znode.
Client b still calls exist command with watch. Because the code doesn't check node existence,
when the  Watch add operation comes , it will add to non-exist node path.
> This problem may be cause by the follow code. 
> {code:java}
> public Stat statNode(String path, Watcher watcher)
> throws KeeperException.NoNodeException {
> Stat stat = new Stat();
> DataNode n = nodes.get(path);
> if (watcher != null) {
> dataWatches.addWatch(path, watcher);
> }
> if (n == null) {
> throw new KeeperException.NoNodeException();
> }
> synchronized (n) {
> n.copyStat(stat);
> return stat;
> }
> }
> {code}
> The zk version we use is 3.4.5. We meet a problem that is the zk client try to reestablish to
zk cluster failed after disconnect for some reason.We find it causes by ZOOKEEPER-706. But
we try to know why there are so many watches. Then we find this problem.
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message