The cluster character

Zk cluster members are divided into three roles, respectively

  • Leader: provides write and read services and participates in the leader election.
  • Follower: provides read services and participates in the leader election.
  • Observer: Provides the read service

Leader and Follwer are clearly defined. In typical Master/Salver mode, the addition of Observer is mainly to improve the cluster read service capability without increasing the election consumption caused by the expansion of cluster scale.

The session

Client session: a long TCP connection between a client and a server. Through this session, clients can request services from ZK or listen for notifications of events on ZK.

ZNode

There are two definitions of nodes in ZK

  • Nodes that represent zK servers
  • ZNode represents each zK data node, for example, /conf/client1

A server node is, needless to say, every container in which zK services are deployed. Data node ZNode stores data content as child node content.

ZNode can be divided into two types according to the type of persistence

  • Persistent Nodes
  • Ephemeral

There is also a functional node

  • Sequential node: A sequence of numbers followed by a node to identify the sequence number.

Two categories can have four combinations

  • Persistent node
  • Persistent order node
  • Temporary node
  • Temporary sequence node

Each node stores the following fields

CZxid is Create ZXID, which indicates the transaction ID of the node when it is created. Ctime is Create Time, which indicates the creation Time of a node. MZxid is Modified ZXID, which indicates the transaction ID of the node when it was last Modified. Mtime is Modified Time, which indicates the Time when a node was last Modified. PZxid indicates the transaction ID of the node when the child node list was last modified. PZxid is updated only when the child list changes, not when the child content changes. Cversion Indicates the version number of a child node. Datspanning represents the content version number. AclVersion acl version ephemeralOwner indicates the session sessionID when the temporary node is created. If it is a persistent node, the value is 0. DataLength indicates the dataLength. NumChildren indicates the number of direct child nodes.Copy the code

version

Zk stores a version for each ZNode, including three versions

  • Version: indicates the current ZNode version
  • Cversion: indicates the version of a ZNode child node
  • Aversion: ACL version of ZNode

ZXID

Zk identifies the globally unique ID of a transaction. When a client triggers a transaction operation, ZK assigns it a global transaction ID named ZXID, which indicates the sequence of ZK transaction requests.

Watcher

Event listeners. When a client calls a ZK service, it can decide whether to register some Watcher services, so that it can be notified when related events occur, and the client can also perform additional operations at this point, such as competing for distributed locks.

ACL

Zk uses the ACL policy to control permissions, and the ZK provides five permissions

  • CREATE: permission to CREATE a node
  • READ: Retrieves node data and a list of child nodes
  • WRITE: Updates node data
  • DELETE: deletes the child node
  • ADMIN: Sets the ACL permission of a node