Database Reference
In-Depth Information
▪ A watch set on an
exists
operation will be triggered when the znode being
watched is created, deleted, or has its data updated.
▪ A watch set on a
getData
operation will be triggered when the znode being
watched is deleted or has its data updated. No trigger can occur on creation be-
cause the znode must already exist for the
getData
operation to succeed.
▪ A watch set on a
getChildren
operation will be triggered when a child of the
znode being watched is created or deleted, or when the znode itself is deleted.
You can tell whether the znode or its child was deleted by looking at the watch
event type:
NodeDeleted
shows the znode was deleted, and
NodeChil-
drenChanged
indicates that it was a child that was deleted.
The combinations are summarized in
Table 21-3
.
Table 21-3. Watch creation operations and their corresponding triggers
Watch trigger
Watch cre-
ation
create znode create child
delete znode delete child
setData
exists
NodeCreated
NodeDeleted
NodeDataChanged
getData
NodeDeleted
NodeDataChanged
getChildren
NodeChildrenChanged NodeDeleted NodeChildrenChanged
A watch event includes the path of the znode that was involved in the event, so for
NodeCreated
and
NodeDeleted
events, you can tell which node was created or de-
leted simply by inspecting the path. To discover which children have changed after a
NodeChildrenChanged
event, you need to call
getChildren
again to retrieve the
new list of children. Similarly, to discover the new data for a
NodeDataChanged
event,
you need to call
getData
. In both of these cases, the state of the znodes may have
changed between receiving the watch event and performing the read operation, so you
should bear this in mind when writing applications.
ACLs
A znode is created with a list of ACLs, which determine who can perform certain opera-
tions on it.
ACLs depend on authentication, the process by which the client identifies itself to
ZooKeeper. There are a few authentication schemes that ZooKeeper provides: