Does the ZooKeeper asynchronous api watcher callback arrive before the completion callback?

Viewed 6

I used zookpeer asynchronous api with c client to monitor my cluster, such as zwget. I found some confusing bugs when my app is running for a while.

The problem is:

  1. The Watcher of the asynchronous api is called first before completion callback.

And I have searched zookeeper offical docs,so the following passage hints that it is possible for the asynchronous API to notify Watcher before the completion callback, am I right?

Synchronous calls may not return in the correct order. For example, assume a client does the following processing: issues an asynchronous read of node /a with watch set to true, and then in the completion callback of the read it does a synchronous read of /a. (Maybe not good practice, but not illegal either, and it makes for a simple example.) Note that if there is a change to /a between the asynchronous read and the synchronous read, the client library will receive the watch event saying /a changed before the response for the synchronous read, but because the completion callback is blocking the event queue, the synchronous read will return with the new value of /a before the watch event is processed.

0 Answers
Related