Joke Collection Website - Public benefit messages - 4.ZAB algorithm core process

4.ZAB algorithm core process

lt; zookeepergt; The client-server communication source code is too complicated. I didn’t gain much from looking at the election-related source code before, so I am not going to look at this part of the source code now. I will make up for it when I have time in the future. The previous election process has already mentioned the communication between the client and the server, and the server handles it through CnxnChannelHandler. This article mainly summarizes how zookeeper ensures data consistency.

4. Follower receives the commit message and commits its own memory data

1. The transaction Proposal has a globally increasing unique ID, called transaction ID (ZXID), which is required by the ZAB protocol To ensure the order of transactions, each transaction must be sorted according to ZXID and then processed, mainly through message queue.

2. Only the Leader server can accept write requests. Even if the Follower server accepts the write request from the client, it will be forwarded to the Leader server for processing. The Follower can only process read requests.

ZAB defines 2 principles:

At the same time:

1. The lower 32 bits can be regarded as a simple incrementing counter, for each client For a transaction request, the Leader will generate a new transaction Proposal and operate the counter by 1.

2. The high 32 bits represent the ZXID of the largest transaction Proposal in the local log on the Leader server, and the corresponding epoch value (leader election cycle) is parsed from the ZXID. When a new round After the election, this value will be increased by one, and the transaction ID will increase from 0.