Zookeeper

Function

1. Provide storage and management of a small amount of data (such as application configuration files, etc.)
2. Provide monitoring of data nodes

How Zookeeper works

Detailed Principle
  The core of Zookeeper is atomic broadcast, which ensures synchronization between servers. The protocol that implements this mechanism is called the Zab protocol. Zab protocol has two modes, they are recovery mode and broadcast mode . When the server starts or after the leader crashes, Zab enters the recovery mode, and then conducts an election. When the leader is elected, and most of the servers have completed the communication with the leader. After the state is synchronized, recovery mode ends. Synchronized state ensures that the leader and server have the same system state. Once the leader has synchronized the state with most of the followers, it enters the broadcast state, and starts to broadcast messages and then enters the broadcast mode. When a new node joins at this time, it will start in recovery mode, discover the leader, and synchronize state with the leader. After the synchronization ends, it also participates in message broadcasting, and the Zookeeper service remains in the broadcasting state until the leader crashes or the leader loses most of the follower support.
  Broadcast mode needs to ensure that proposals are processed in order, so zk uses an incremental transaction id number (zxid) to ensure that. All proposals are made with zxid added. In the implementation, zxid is a 64-bit number, and its high-order 32 bits are the epoch used to identify whether the leader relationship has changed. Every time a leader is elected, it will have a new epoch. The lower 32 bits are an increment count.
  When the leader crashes or the leader loses most of the followers, zk enters the recovery mode, and the recovery mode needs to re-elect a new leader to restore all servers to a correct state.

1. How to use zookeeper for election, drawing instructions

First, the two conditions for triggering the election are introduced: the server is initialized and started; the connection with the leader cannot be maintained during operation.

2. How to use zookeeper for task assignment (to be continued)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324730414&siteId=291194637