ZooKeeper data model and zookeeper Model
ZooKeeper has a hierarchical namespace, similar to a distributed file system. The only difference between them is that each node in the namespace can have data associations as their subnodes. This is like a file system that allows files to be used as file directories. The Node path is usually a standard absolute path separated by a slash. They do not have relative paths. Any unicode character contained in a path must comply with the following constraints:
1) null characters cannot be used as path names;
2) The following strings cannot be used. They are superior in poor display or can cause confusion (\ u0001-\ u001F and \ u007F-\ u009F)
3) The following strings are not allowed. (\ Ud800-uF8FF, \ uFFF0-uFFFF)
4) The "." character can be used as a part of the name, but "." and "." cannot exist separately to represent a Node path, because ZooKeeper does not use a relative path. The following example is invalid: "/a/B/./c" or "/a/B/./c"
5) reserved keywords for "zookeeper"
ZNodes
Each node in the ZooKeeper tree structure can be called znode. Znodes maintains a state data structure, including the data change version number, ACL change, and timestamp. The version number and timestamp allow ZooKeeper to perform cache token exchange and coordinated updates. Each time the data of a znode is changed, the version number is added. For example, when a client receives data, it also receives the version of the data. When the client performs an update or delete operation, it must provide the data version of The znode node being changed. If the version number provided by znode does not match the actual version number of the current data, the update will fail.
Note:
In a distributed application project, the word node can be considered as a single host, a server, a whole member, a client processor, and so on. In the ZooKeeper document, znodes is considered a data node. Servers are considered to be the hosts that constitute the ZooKeeper service. Quorum peers is considered to constitute a whole server, and clients is considered to be a host or a process that is using the ZooKeeper service.
Znodes is the main entity for programmers to access. They have many features worth understanding:
Watches (listener)
The client can listen on znodes. Znode changes will trigger this listener and clear it. When a listener is triggered, ZooKeeper sends a notification to the client.
Data Access)
In the namespace, data stored in znode is read or written by atoms. The read operation reads all data bytes associated with znode, And the write operation replaces all data. Each node has an Access Control List (ACL) data Access List to limit who can do what.
ZooKeeper is not designed for database or large object storage. Instead, it is used to manage and coordinate data. The data source can be configuration information, status information, region information, and so on. The common attribute of different forms of coordinated data is that they are relatively small and controlled in KB. Both the ZooKeeper client and the server have a rational check to ensure that znodes is less than 1 MB of data, but the data can be far smaller than the average value. Operations on relatively large data may take a long time and affect the delay of other operations, because this extra time requires data migration through the network or storage media. If the storage of big data is required, the data is usually processed in a large storage system, such as NFS or HDFS, and then stored in ZooKeeper as a pointer to the data storage location.
Ephemeral Nodes (temporary node)
ZooKeeper has the concept of a temporary node. As long as the session of the created node is still active, these nodes still exist. When the session is closed, these nodes will also be deleted. Because of this behavior, temporary nodes are not allowed to have subnodes.
Sequence Nodes -- Unique Naming (Sequence node-Unique name)
When creating a node, you can request ZooKeeper to add a monotonically increasing counter at the end of the path. This counter is unique to this parent node. The counter format is % 010d (fill with 0 in decimal system). format it for simple sorting. For example, "<path> 0000000001 ". Check the Queue Recipe. This feature is used in an example. Note: The counter used to store the next serial number is a signed int maintained by the parent node. This counter overflows when it increases by more than 2147483647 (the result should be "<path>-2147483647 ").