Technology Sharing

Zookeeper-Data Structure

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

ZooKeeper's data model has characteristics similar to the file system tree structure, but it is designed specifically for distributed applications.

Following are the main features of ZooKeeper data structures:

  1. Hierarchical namespace:ZooKeeper provides a hierarchical namespace, similar to a file system. Each node has a unique path in the hierarchy.

  2. ZNode: Each data node in ZooKeeper is called a ZNode (similar to a file or directory in a file system). ZNode can have child nodes, forming a hierarchical structure.

    1. Persistent: Persistent nodes are the most common type of node. Once created, they will persist unless explicitly deleted by the client. Even if the ZooKeeper service is restarted, persistent nodes will not be lost.

    2. Persistent Sequential: Persistent sequential nodes are an extension of persistent nodes and are sequential. When created, ZooKeeper appends a sequence number maintained by the parent node to the end of the node name to ensure global uniqueness. This type of node is usually used to implement scenarios that require orderly arrangement, such as distributed queues.

    3. Ephemeral: The life cycle of a temporary node is bound to the client session. If the client session fails due to network problems or client crashes, ZooKeeper will automatically delete all temporary nodes created by the session. This feature makes temporary nodes very suitable for implementing locking mechanisms and leader elections.

    4. Ephemeral Sequential: Temporary sequence nodes combine the characteristics of temporary nodes and persistent sequence nodes. They have a limited life cycle and are assigned a sequence number when they are created. This makes them very useful for implementing distributed synchronization and coordination tasks, such as implementing locks or other synchronization primitives.

    5. Container: A container node is a special ZNode that does not store data but can contain child nodes. This type of node can be used to organize and structure data, similar to a directory in a file system.

    6. Interior Node: Internal nodes are parent nodes in ZooKeeper and can contain child nodes. They are different from leaf nodes because leaf nodes are usually used to store data, while internal nodes are used to maintain a hierarchical structure.

    7. Leaf Node: Leaf nodes are the end nodes of the ZNode hierarchy and are usually used to store data. They have no child nodes.

    8. TTL Node (Time To Live): TTL nodes are a new feature introduced in ZooKeeper 3.5.0 version, which allows nodes to set a survival time (TTL). When the TTL expires, if the node is a temporary node, it will be deleted; if it is a persistent node, it will become a temporary node and be deleted.

  3. ACL (Access Control List): ZNode can set different access permissions to control which users or user groups can read or modify the node.

  4. Watcher Mechanism:The client can set a Watcher on the ZNode. When a ZNode changes (such as data changes, child node additions and subtractions, etc.), all clients that have set a Watcher will receive a notification.

  5. Persistence: Nodes can be persistent, which means that even if the ZooKeeper server is restarted, the persistent node will still exist. If the node is ephemeral, it will be automatically deleted when the client session that created it ends.

  6. data storage:Each ZNode can store data, such as string values ​​or binary data. Clients can read and write this data.

  7. Sequential: When creating sequential nodes, ZooKeeper appends a number to the node name, starting at 0 and incrementing each time a new node is created. This ensures uniqueness of node names and can be used to implement FIFO ordering.

  8. version control: Each ZNode has a version number, which is incremented whenever the node's data is modified. This can be used to check if the node has been modified since it was read.