Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch set with get_children and include_data=True is never triggered #514

Closed
saffroy opened this issue Jul 17, 2018 · 1 comment
Closed

Comments

@saffroy
Copy link
Contributor

saffroy commented Jul 17, 2018

If I try this:

    zk = kazoo.client.KazooClient(hosts=ZK_HOSTS)
    zk.start()

    def foo(ev):
        ch = zk.get_children(PATH_MEMBERS, watch=foo)
        print('ch = {0}'.format(ch))

    def foo2(ev, x=None):
        ch, st = zk.get_children(PATH_MEMBERS, include_data=True, watch=foo2)
        print('ch2 = {0}'.format(ch))

    foo(None)
    foo2(None)

And then go add/remove nodes under PATH_MEMBERS, then only the first watch shows updates ("ch = ...").

It seems to work from zkCli.sh, assuming that "ls -sw" does the same operations:

[zk: localhost:2181(CONNECTED) 2] ls -sw /members
[]
cZxid = 0xa
ctime = Fri Jul 06 22:17:49 CEST 2018
mZxid = 0x2c7
mtime = Tue Jul 17 01:23:19 CEST 2018
pZxid = 0x34c
cversion = 176
dataVersion = 57
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 0

[zk: localhost:2181(CONNECTED) 3] create /members/foo

WATCHER::

WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/dlm/members
Created /dlm/members/foo

Observed with kazoo 2.5.0, python 3.4, Zookeeper 3.5.4.

@saffroy
Copy link
Contributor Author

saffroy commented Jul 17, 2018

This change seems to fix the issue:

diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py
index d37f7c7..3ab8991 100644
--- a/kazoo/protocol/connection.py
+++ b/kazoo/protocol/connection.py
@@ -22,6 +22,7 @@ from kazoo.protocol.serialization import (
     Connect,
     Exists,
     GetChildren,
+    GetChildren2,
     Ping,
     PingInstance,
     ReplyHeader,
@@ -380,7 +381,8 @@ class ConnectionHandler(object):
             # Determine if watchers should be registered
             watcher = getattr(request, 'watcher', None)
             if not client._stopped.is_set() and watcher:
-                if isinstance(request, GetChildren):
+                if (isinstance(request, GetChildren)
+                    or isinstance(request, GetChildren2)):
                     client._child_watchers[request.path].add(watcher)
                 else:
                     client._data_watchers[request.path].add(watcher)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant