...

Open source softwares - Zookeeper

Back to Course

Lesson Description


Lession - #1098 Zookeeper Watches


All of the scan operations in ZooKeeper - getData(>
, getChildren(>
, and exists(>
- have the choice of setting a watch as a effect result. Here is ZooKeeper's definition of a watch: a watch event is one-time trigger, sent to the client that set the watch, that happens once the data that the watch was set changes. There are 3 key points to think about during this definition of a watch:

One-time trigger


One watch event are sent to the client once the data has modified. as an example, if a consumer will a getData("/znode1", true>
and later the information for /znode1 is modified or deleted, the client can get a watch event for /znode1. If /znode1 changes once more, no watch event are sent unless the client has done another read that sets a new watch.

Sent to the client


This implies that an event is on the way to the client, however might not reach the client before the in return code to the change operation reaches the client that initiated the modification. Watches are sent asynchronously to watchers. ZooKeeper provides associate ordering guarantee: a client can never see a modification that it's set a watch till it initial sees the watch event. Network delays or other factors might cause different|completely different} purchasers to envision watches and return codes from updates at different times. The key purpose is that everything seen by the various clients can have a consistent order.

The data that the watch was set


This refers to the various ways in which a node will modification. It helps to think about ZooKeeper as maintaining 2 lists of watches: data watches and kid watches. getData(>
and exists(>
set data watches. getChildren(>
sets kid watches. or else, it should help to think about watches being set according to the sort of data returned. getData(>
and exists(>
return data about the data of the node, whereas getChildren(>
returns a list of children. Thus, setData(>
can trigger data watches for the znode being set (assuming the set is successful>
. A in create(>
can trigger a data watch for the znode being created and a child watch for the parent znode. A in delete(>
can trigger each a data watch and a child watch (since there may be no more children>
for a znode being deleted still as a child watch for the parent znode.

Watches are maintained locally at the ZooKeeper server to that the client is connected. this enables watches to be light weight to set, maintain, and dispatch. once a client connects to a new server, the watch are triggered for any session events. Watches won't be received whereas disconnected from a server. once a client reconnects, any antecedently registered watches are reregistered and triggered if required. normally this all happens transparently. there's one case wherever a watch could also be missed: a watch for the existance of a znode not nonetheless created are missed if the znode is formed and deleted while disconnected.

What ZooKeeper Guarantees concerning Watches
With regard to watches, ZooKeeper maintains these guarantees:
  • Watches are ordered with respect to different events, different watches, and asynchronous replies. The ZooKeeper consumer libraries ensures that everything is sent so as.
  • A client can see a watch event for a znode it's looking before seeing the new data that corresponds to it znode.
  • The order of watch events from ZooKeeper corresponds to the order of the updates as seen by the ZooKeeper service.