Watcher delta

19 views
Skip to first unread message

David Wood

unread,
Sep 9, 2020, 1:08:00 PM9/9/20
to python-zk

I had expected the watcher to return the change (add, delete) on an individual child, but it appears the watcher is sending me all the current children of the watched node.  Is there a way to only receive notifications of the changes?  If not, it seems that if I want to deliver only the changes to my users, then I need to replicate the data to the client and keep track myself.  Is this the case

As an example...

        zk = KazooClient(hosts='localhost:2181')
        zk.start()
        # Ensure a path, create if necessary
        zk.delete("/groups", recursive=True)
        zk.ensure_path("/groups")
     
        print("Creating callback")
        watcher = zk.ChildrenWatch(path="/groups", func=callback,allow_session_lost=True, send_event=True)
        # Create a node with data
        print("Adding g1")
        zk.create("/groups/g1", value=None, acl=None, ephemeral=False, sequence=False, makepath=True, include_data=False)
        time.sleep(1)
        print("Adding g2")
        zk.create("/groups/g2", b"a 2")
        time.sleep(1)
        print("Deleting g1")
        zk.delete("/groups/g1")
        time.sleep(1)
        print("Deleting g1")
        zk.delete("/groups/g2")
        time.sleep(1)

produces

Creating callback
CALLBACK:  ([], None)
Adding g1
CALLBACK:  (['g1'], WatchedEvent(type='CHILD', state='CONNECTED', path='/groups'))
Adding g2
CALLBACK:  (['g1', 'g2'], WatchedEvent(type='CHILD', state='CONNECTED', path='/groups'))
Deleting g1
CALLBACK:  (['g2'], WatchedEvent(type='CHILD', state='CONNECTED', path='/groups'))
Deleting g1
CALLBACK:  ([], WatchedEvent(type='CHILD', state='CONNECTED', path='/groups'))
There are 2 children with names ([], ZnodeStat(czxid=1763, mzxid=1763, ctime=1599670992500, mtime=1599670992500, version=0, cversion=4, aversion=0, ephemeralOwner=0, dataLength=0, numChildren=0, pzxid=1767))
There are 3 children with names ['groups', 'zookeeper', 'edgeai']
Reply all
Reply to author
Forward
0 new messages