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

Support for SetWatches command, as well as watch restoration on ZK session reconnect #218

Closed
brianv0 opened this issue Jul 2, 2014 · 3 comments · Fixed by #305
Closed

Comments

@brianv0
Copy link

brianv0 commented Jul 2, 2014

I've hacked in SetWatches request into a local version of Kazoo for testing.

I'm not sure if this would be a feature that's relatively useful for people to expose as an API, but I think it could be useful in the case where a connection is dropped and removed from the server before a session expires, as can be the case in client restart.

Example: Client exits abnormally. The original connection is loss, the ZooKeeper server removes the connection, which removes all watches associated with that connection (as the ServerCnxn object itself is the watcher on the server side).

User had persisted KazooClient.client_id, as well as information about paths that were being watched, and KazooClient.last_zxid.

Upon reconnect, user supplies that information back to KazooClient.
User reconstructs watcher(s).

KazooClient starts, reconnecting with the previous session ID, restoring the previous session, and immediately sets watches.

If anything has changed since the relativeZxid, those events are immediately triggered (which is why client-side watch handlers should be to be set before this request).

Here is an example of the SetWatches for serialization.py:

class SetWatches(namedtuple('SetWatches', 'relativeZxid dataWatches existsWatches childWatches')):
    type = 101

    def serialize(self):
        b = bytearray()
        b.extend(long_struct.pack(self.relativeZxid))
        self.svector(b, self.dataWatches)
        self.svector(b, self.existsWatches)
        self.svector(b, self.childWatches)
        return b

    def svector(self, b, arr):
        b.extend(int_struct.pack(len(arr)))
        for elem in arr:
            b.extend(write_string(elem))

    # Not sure what we need for deserialization here
@bbangert
Copy link
Member

Yup, I've also been thinking about this issue as well. It was on my list of things to add, and I definitely want it in by 2.2.

@bbangert bbangert added this to the 2.2 milestone Sep 23, 2014
@rgs1
Copy link
Contributor

rgs1 commented Feb 3, 2015

fwiw, i have a branch with this https://github.com/rgs1/kazoo/tree/support-setwatches. i'll rebase it on master and add some tests

@bbangert
Copy link
Member

bbangert commented Feb 3, 2015

That would be fantastic!

rgs1 added a commit to rgs1/kazoo that referenced this issue Apr 3, 2015
Fixes python-zk#218

Signed-off-by: Raul Gutierrez S <rgs@itevenworks.net>
rgs1 added a commit to rgs1/kazoo that referenced this issue Apr 7, 2015
Fixes python-zk#218

Signed-off-by: Raul Gutierrez S <rgs@itevenworks.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants