Zookeeper Monitoring (Watches) Introduction
The Declaration and description of the Zookeeper C API can be found in include/zookeeper.h, and most of the Zookeeper C API constants and struct declarations are also in Zookeeper.h if you are experiencing a problem where you are using C API , it's best to look at Zookeeper.h, or use Doxygen to generate zookeeper C API's help documentation.
The most distinctive and most difficult to understand Zookeeper is surveillance (Watches). Zookeeper all read operations-GetData (), GetChildren (), and exists () can be set up for monitoring (watch), and monitoring events can be understood as a one-time trigger, The official definition is as follows: A watch event is one-time trigger, sent to the client that set the watch, which occurs when the data for which the Watch was set changes. This needs to be understood as follows:
(disposable trigger) one-time trigger
When setting the monitored data changes, the monitoring event is sent to the client, for example, if the client calls GetData ("/znode1", true) and later the data on the/ZNODE1 node changes or is deleted, the client gets to/znode1 Monitored events that change, and if/znode1 changes again, the client will not receive an event notification unless the client again monitors the/ZNODE1 settings.
Sent to the client
The Zookeeper client and server are communicated through the socket, and because of a network failure, it is likely that the monitoring event will not reach the client successfully, the monitoring event is sent asynchronously to the Watcher, and the Zookeeper itself provides a sequence of guarantees (ordering Guarantee): That is, the client will only be aware of the changes to the znode that it has set up after it has seen the monitoring event (a-client would never see a-which it has set a watch until I T first sees the watch event). Network latency or other factors can cause different clients to perceive a monitoring event at different times, but it is a consistent sequence of everything that different clients see.
(Data of W Atch set) the data for which the watch is set
This means that the Znode node itself has different ways of changing. You can also imagine that Zookeeper maintained two watch lists: Data monitoring and child node monitoring (watches and watches) GetData () and exists () setting data monitoring, GetChildren () Setting child node monitoring 。 Alternatively, you can imagine that different monitoring Zookeeper settings return different data, GetData () and exists () return information about the Znode node, and GetChildren () returns a list of child nodes. Therefore, setData () triggers the setting of data monitoring set on a node (assuming the data is set up successfully), while a successful create () operation starts with the data monitoring set on the current node and the child node monitoring of the parent node. A successful delete () operation will trigger the current node's data monitoring and child node monitoring events, as well as the parent node of the node.
The monitoring in Zookeeper is lightweight and therefore easy to set up, maintain, and distribute. When the client loses contact with the Zookeeper server, the client does not receive notification of the monitoring event, which is usually transparent to the developer if, if necessary, previously registered monitoring is re-registered and triggered when the client is reconnected. There is only one situation that can cause a monitoring event to be lost, that is, the monitoring of a Znode node is set through exists (), but if a client loses contact with the zookeeper server during the time interval that the Znode node is created and deleted, the client even later reconnect Event notifications are not zookeeper after the server.
Zookeeper C API constants and partial structures (structs) describe ACL-related structures and constants:
The struct ID structure is:
struct ID { char * scheme; char * ID;};
The struct ACL structure is:
struct ACL { int32_t perms; struct ID ID;};
The struct Acl_vector structure is:
struct Acl_vector { int32_t count; struct ACL *data;};
Constants related to Znode access rights
Const int Zoo_perm_read; Allows the client to read the value of the Znode node and the list of child nodes.
Const int zoo_perm_write;//allows the client to set the value of the Znode node.
Const int Zoo_perm_create; Allows the client to create child nodes under the Znode node.
Const int zoo_perm_delete;//allows the client to delete child nodes.
Const int Zoo_perm_admin; Allows the client to execute Set_acl ().
Const int zoo_perm_all;//allows the client to perform all operations, equivalent to all flags above or (or).
Constants related to ACL IDs
struct Id Zoo_anyone_id_unsafe; (' World ', ' anyone ')
struct Id zoo_auth_ids;//(' AUTH ', ')
Three types of standard ACLs
struct Acl_vector Zoo_open_acl_unsafe; (Zoo_perm_all,zoo_anyone_id_unsafe)
struct Acl_vector zoo_read_acl_unsafe;//(Zoo_perm_read, Zoo_anyone_id_unsafe)
struct Acl_vector Zoo_creator_all_acl; (Zoo_perm_all,zoo_auth_ids)
Constants related to Interest:
Zookeeper_write,
Zookeeper_read
These two constants are used to identify the event of interest and to notify zookeeper of events that have occurred. Interest constants can be combined or (or) to identify multiple interests (multiple interests:write, read), which are typically used for zookeeper_interest () and zookeeper_process () Two functions in a function.
Constants related to node creation:
zoo_ephemeral,
zoo_sequence
The Zoo_create function flag,zoo_ephemeral , is used to identify the creation of a temporary node,zoo_sequence is used to identify the node named with an incrementing suffix ordinal (typically a 10-character ordinal after the node name, such as/ xyz0000000000,/xyz0000000001,/xyz0000000002, ...), similarly,zoo_ephemeral, zoo_sequence can be combined.
Constants related to connection status Stat
The following constants are related to the Zookeeper connection state, and they are typically used as parameters to the monitor callback function.
| zooapi const int < /td> |
zoo_expired_session_state |
| zooapi const int |
< Strong>zoo_auth_failed_state |
| ZOOAPI Co NST int |
zoo_connecting_state |
| zooapi const int |
zoo_associating_state |
| zooapi const int |
zoo_connected_state |
Constants related to monitoring type (watch Types)
The following constants identify the types of monitoring events that they typically use as the first parameter of a monitor callback function.
- Zoo_created_event; The node is created (previously the node does not exist) and is set up for monitoring by zoo_exists ().
- Zoo_deleted_event; The nodes are removed and monitored through zoo_exists () and Zoo_get () settings.
- Zoo_changed_event; nodes change, and monitoring is set up through Zoo_exists () and Zoo_get ().
- Zoo_child_event; Child node events, set up monitoring through Zoo_get_children () and Zoo_get_children2 ().
- Zoo_session_event; Session lost
- Zoo_notwatching_event; Monitoring is removed.
Zookeeper C API Error code Introduction zoo_errors
| Zok |
Normal return |
| Zsystemerror |
System or server-side error (Systems and server-side errors), the server does not throw the error, and the error is only used to identify the error range, which is greater than the error value, and less than Zapierror is a system error. |
| zruntimeinconsistency |
Run-time non-conformance error. |
| zdatainconsistency |
Data non-conformance error. |
| Zconnectionloss |
Zookeeper client loses connection to server side |
| Zmarshallingerror |
Error in marshalling and unmarshalling data (Error while marshalling or unmarshalling data) |
| zunimplemented |
The operation is not implemented (operation is unimplemented) |
| Zoperationtimeout |
The operation timed out (Operation timeout) |
| zbadarguments |
Illegal parameter error (Invalid arguments) |
| zinvalidstate |
Illegal handle status (Invliad zhandle state) |
| Zapierror |
API error (API errors), the server does not throw the error, the error is only used to identify the error range, the error value is greater than the value of the identity API error, and is less than the value of the identity zsystemerror. |
| Znonode |
Node does not exist (nodes does not exist) |
| Znoauth |
Not authorized (not authenticated) |
| zbadversion |
Versioning conflict (version conflict) |
| znochildrenforephemerals |
Temporary nodes cannot have child nodes (ephemeral nodes may not have children) |
| znodeexists |
Nodes already exist (the node already exists) |
| Znotempty |
The node has its own child nodes (the nodes have children) |
| zsessionexpired |
Session expires (the sessions have been expired by the server) |
| Zinvalidcallback |
Illegal callback function (Invalid callback specified) |
| Zinvalidacl |
Illegal ACL (Invalid ACL specified) |
| zauthfailed |
Client Authorization failed (authentication failed) |
| zclosing |
Zookeeper connection Off (Zookeeper is closing) |
| znothing |
Not an error, the client does not need to process the server's response (not error, no server responses to process) |
| zsessionmoved |
The session is moved to a different server, so the operation is ignored (session moved to another server, so operation is ignored) |
So far, most of the constants and structs in the Zookeeper C API have been introduced, and the next section, Zookeeper C API Guide III (callback function), describes the callback functions in the Zookeeper C API.
Zookeeper C API Guide One (GO)