The principle and core introduction of Zookeeper

1.1 Introduction What is Zookeeper?

The official explanation given:

Zookeeper is an open source distributed Apache project that provides coordination services for distributed applications.

Zookeeper is understood from the perspective of design patterns: it is a distributed service management framework designed based on the observer pattern. It is responsible for storing and managing the data that everyone cares about, and then accepts the registration of observers. Once the state of these data changes, Zookeeper will It will be responsible for notifying those observers who have registered on Zookeeper to respond accordingly, so as to realize the similar Master/Slave management mode in the cluster.

From my own point of view, Zookeeper is a distributed coordination service framework, but it is more like a distributed small file storage system (stored files within 1M), and provides monitoring services, which is also the same as HDFS ( leader) from the (follower) way.

1.2 Why use Zookeeper?

Guarantee global data consistency When processing transactions, if multiple nodes process transaction requests (additions, deletions, and modifications) at the same time, will there be dirty reads, lost updates, and non-repeatable reads? At this time, we send all transaction requests to the leader for processing, execute them in an orderly manner on the leader, and then synchronize to the follower

1.3 Zookeeper's znode node type

The difference between storing data on zk and hdfs is that znode can be used as a file directory or as a file.

  • Permanent node: always exists, must be manually deleted to delete
  • Temporary node: The life cycle depends on the session technology, the temporary node disappears, and no child nodes can be created under the temporary node
  • Serialized nodes: nodes can have the same name
  • Non-serialized nodes: Nodes cannot have the same name

1.4 The role of Zookeeper

  • leader: the core of the zk cluster, which handles all transaction requests and maintains the health status of followers (heartbeat mechanism)
  • follower: Responsible for processing all non-transactional requests (mainly lookups) to participate in voting
  • observer: Responsible for processing all non-transactional requests, but does not participate in voting

1.5 Zookeeper's voting mechanism

The cluster of zk is generally an odd number of units
insert image description here

Guess you like

Origin blog.csdn.net/qq_40745994/article/details/107648923