ZooKeeper (3) – internal principles

1. Node type

share picture

two. Stat structure

1) czxid-the transaction zxid that created the node

Every time you modify the ZooKeeper status, you will receive a timestamp in the form of zxid, which is the ZooKeeper transaction ID .

The transaction ID is the total sequence of all modifications in ZooKeeper. Each modification has a unique zxid, if zxid1 is less than zxid2, then zxid1 occurs before zxid2.

2) ctime-the number of milliseconds that the znode was created (since 1970)

3) mzxid-the last transaction zxid of the znode update

4) mtime -znode last modified number of milliseconds (since 1970)

5) pZxid-znode last updated child node zxid

6) cversion-znode child node change number, znode child Node modification times

7) dataversion-znode data change number

8) aclVersion-znode access control list change number

9) ephemeralOwner- if it is temporary Node, this is the session id of the znode owner. If it is not a temporary node, it is 0.

10) dataLength- data length of znode

11) numChildren-number of znode child nodes

Three. Listener principle

share picture

4. Election mechanism

< p>1. Half mechanism: More than half of the machines in the cluster survive and the cluster is available. So Zookeeper is suitable for installing an odd number of servers.

2. Although Zookeeper does not specify Master and Slave in the configuration file. However, when Zookeeper works, one node is Leader, and the others are Followers. Leaders are temporarily generated through an internal election mechanism.

3. Take a simple example to illustrate the entire election process.

Assume that there is a Zookeeper cluster composed of five servers, their ids are from 1-5, and they are all newly started, that is, there is no historical data, and the amount of data stored is the same. of. Assuming that these servers are started in order, let’s see what happens:

(1) Server 1 starts and initiates an election. Server 1 votes for itself. At this time, server 1 has one vote, which is less than half of the votes (3 votes). The election cannot be completed, and the status of server 1 remains LOOKING;

(2) Server 2 is started, and another election is initiated. Servers 1 and 2 respectively vote for themselves and exchange ballot information: At this time, server 1 finds that the ID of server 2 is larger than the one currently voted by (server 1), and changes the vote to recommend server 2. At this time, server 1 has 0 votes and server 2 has 2 votes. There is no more than half of the results. The election cannot be completed. Servers 1 and 2 remain in the state of LOOKING

(3) Server 3 is started and an election is initiated. At this time, both servers 1 and 2 will change their votes to server 3. The result of this poll: Server 1 has 0 votes, Server 2 has 0 votes, and Server 3 has 3 votes. At this time, server 3 has more than half of the votes, and server 3 is elected as the leader. Servers 1, 2 change their status to FOLLOWING, and server 3 changes their status to LEADING;

(4) Server 4 starts and initiates an election. At this time, servers 1, 2, and 3 are no longer in the LOOKING state, and the ballot information will not be changed. The result of the vote information exchange: Server 3 has 3 votes, and Server 4 has 1 vote. At this time, server 4 obeys the majority, changes the vote information to server 3, and changes the status to FOLLOWING;

(5) Server 5 starts, and acts as a kid like 4.

5. Data writing process

share picture

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4770 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.