Zookeeper components
- Data model
- Data node ZNode
-
- There are four types of zNodes
- Data node Data structure of zNode
- Release version
- Permission control ACL
- The event listener watcher
- Session session
Data model
-
Zookeeper data model adopts hierarchical multi-cross structure:
- The uppermost root node is represented by /, and each node can have N child nodes
- Data can be stored on each node, and the data type can be numbers, strings, and binary sequences
- Each node, called a ZNode, is the smallest unit of data in Zookeeper, and each ZNode has a unique path identifier
-
Note:
- Zookeeper is used to coordinate services, not store service data
- Znode cannot store large amounts of data
- A Zookeeper node can store a maximum of 1 MB data
Data node ZNode
- Each data node in Zookeeper is called a ZNode, which is the smallest data unit in Zookeeper
There are four types of zNodes
- PERSISTENT nodes: Once a node zNode is created, it persists forever. Even if Zookeeper goes down, it will not disappear until the ZNode is deleted
- EPHEMERAL: The life cycle of the temporary zNode is EPHEMERAL and is tied to the client session. When the session disappears, the zNode disappears. The temporary zNode can only be used as a leaf node and cannot create child nodes
- PERSISTENT_SEQUENTIAL node: In addition to being PERSISTENT, the name of the node znode is sequential
- EPHEMERAL_SEQUENTIAL node: In addition to being EPHEMERAL, the name of the node Znode is also sequential
Data node Data structure of zNode
-
Each ZNode consists of two parts:
- Data: data stored on a node
- Stat: indicates the node status
-
Description of status information in STAT:
The stat values | instructions |
---|---|
cZxid | Create ZXID Transaction ID when the data node is created |
ctime | Create Time Time when a data node is created |
mZxid | Modified ZXID Transaction ID when the data node was last updated |
mtime | Modified Time Time when the data node was last updated |
pZxid | The transaction ID of the last modified child node list of a data node will be updated only when the child node list changes. The pZxid will not be updated when the content of the child node changes |
cversion | Child node Version The value of the child node of the current data node increases by 1 each time it changes |
dataVersion | Data node content Version The value is 0 when the data node is created and increases by 1 each time the update data node content operation is invoked |
aclVersion | ACL version number of a data node Indicates the number of ACL changes on the node |
ephemeralOwner | EphemeralOwner =0 sessionId of the client session that created the current temporary node if the current node is persistent |
dataLength | Data Node Data length |
numChildren | Number of current nodes |
- Example:
get /dubbo
#Data. The data information associated with the data node is empty
null
# stat. Indicates the status of the data nodecZxid = 0x2 ctime = Thu Jan 28 09:35:57 CST 2021 mZxid = 0x2 mtime = Thu Jan 28 09:35:57 CST 2021 pZxid = 0x3 cversion = 1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 0 numChildren = 1Copy the code
Release version
-
The stat of Znode in Zookeeper records the following version information:
- The version number of the child node of the current node is cversion
- The data content version number of the current node is DatSpanning
- The ACL version of the current node is aclVersion
Permission control ACL
-
Zookeeper uses AccessControlLists (acls) to control permissions, similar to the permission control of UNIX file systems
-
Operations on data node ZNode have the following five permissions:
-
CREATE: Creates a child node
-
READ: Reads data from a node and lists its children
-
WRITE: Updates node data
-
DELETE: deletes the child node
-
ADMIN: Sets the ACL permission of a node
- The permissions for CREATE and DELETE here are for child nodes
-
-
Zookeeper provides the following identity authentication modes:
- World: default. All users have unconditional access
- IP: Users with a specified IP address can access the IP address
- Auth: Authenticated users can access the system
- Digest: the username username and password are used to authenticate the access
The event listener watcher
-
Event listener Watcher:
- An important feature in Zookeeper
- Zookeeper allows users to register some Watcher on a specific zNode, and when certain events are triggered,Zookeeper notifies listening clients of the events
- The event listening mechanism isZookeeperImplementing important features of distributed coordination services
Session session
-
Session Session:
-
Session Session is a TCP long connection between the Zookeeper server and the customer
-
Through this Session, the client can communicate with the Zookeeper server:
- Maintains a valid session with the server through heartbeat detection
- Sends a request to the Zookeeper server and receives the response
- Ability to receive Watcher event notifications from the server over a connection
-
-
SessionTimeout sessionTimeout:
- If the client is disconnected due to excessive server pressure, network faults, or active client disconnection, the Session is still valid as long as any server in the cluster can be reconnected within the specified Session timeout period
-
SessionID sessionID:
- Before creating a client session, the server assigns a sessionID to each client
- The sessionID is an important id of a Zookeeper session, and all session-related operating mechanisms in Zookeeper are based on the sessionID. Therefore, the sessionID assigned by the server to clients in the entire cluster must be globally unique in the entire cluster