Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Fifth, the election mechanism, monitoring principle, data flow and node type of zookeeper cluster.

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Election mechanism of zk cluster:

Half mechanism: if more than half of the nodes in the zk cluster survive, zk can run normally, so it is better to have an odd number of nodes in the zk cluster. There is only one leader in the Zk cluster, and the rest are follower

Election mechanism: the first server with more than half of the votes will be elected leader.

Server1 server2 server3 server4 server5 (the big id will not vote for the small id, the small id will vote for the big id, and the server1-5 Magi id increases in turn) 5 machines: server1 starts to vote, server1 votes for himself, because server1 id is the smallest, so server1 has only one vote Server2:server2 will vote for himself, server1 will also vote for server2, server2 two votes Server3:server3 will vote for himself, server1 and server2 each vote server3, then server3 will vote three votes, three votes in more than half (a total of five machines) So choose server3 as leader, the latter server4 (4 votes) and server5 (5 votes) have more votes than server3, but server3 is the first one with more than half of the votes, so choose server3 as the monitoring principle of leaderZokeeper: (key point)

1) first, there must be a main () thread

2) create the client of zookeeper in the main () thread, and two threads will be created, one responsible for network connection communication (connect) and one responsible for listening (listen)

3) send registered listening events to zookeeper through the connect thread created by the client

4) add registered listeners to the list of registered listeners on the zookeeper server

5) when Zookeeper detects a change in data or path, it will send this message to the listen thread

6) the Listen thread calls the internal process () method, which is what to do after the data changes, which is developed by the programmer himself.

As shown in the figure:

The process of writing data in zk cluster

We, client, want to know how server writes when sending write requests, and how the data of each server is consistent.

Understanding: when client sends a write request to server, it will be forwarded to leader (the write request follower is not in charge, but the read request can be). Leader will send the write request to each server and write data. When each server data is written, it will inform leader in turn. When leader receives more than half of the server is written successfully, leader will think that the write operation is successful, and then leader will tell each server. The write operation is successful, and then the successful message is sent to the client for display, so that each server has a copy and the data is consistent.

Types of znode nodes in the Zk cluster

Persistent (Persistent): after the client and server are disconnected, the created links are not deleted

Transient (Epheneral): after the client server disconnects and understands, the created node deletes itself

Persistent nodes include:

(1) persistent directory node: after the client is disconnected by zk, the node still exists.

(2) persistence sequence numbering directory node: after the client is disconnected from zk, the node still exists, but zk numbers the node name sequentially.

The role of sequence numbers: in distributed systems, sequence numbers can be used to globally sort all events, so that clients can determine the order of events by sequence numbers

Transient nodes:

(1) temporary directory node: after the client is disconnected from the zk, delete the node, which is most suitable for dynamic nodes.

(2) temporary sequential numbering directory node: when the client is disconnected from zk, the node will be deleted, but a sequential number will be added when naming.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report