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

Zookeeper realizes the principle of master-slave structure

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "the principle of master-slave structure of zookeeper implementation". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "the principle of zookeeper master-slave structure".

(if you can't read it clearly, save it locally.) the following text is just an explanation of the sequence diagram. The key point is to understand the sequence diagram.

In order to avoid confusion between the master node / slave node and the node concept of zk, the following is called Master/Slave. # 1 Select Master after the system starts, all slave will try to create a / master node on the zk tree, and the successfully created node will become the Master role. However, Master may crash, so other slave will continue to monitor the / master node. When Master dies, slave re-elects a new Master (the election here is preemption). This requires that when the service node dies, the / master node is deleted so that other slave can be notified, so the master must be a temporary node.

2 preparation for Master

Create three parent nodes / works, / tasks, / assign. (it can also be built by a bootstrapper) these three parent nodes are permanent nodes, do not contain any data, and exist as directory nodes. Its child nodes are used to store available slave, task information, and assign tasks to slave nodes. After creation, Master monitors the / works and / tasks nodes so that it can sense which slave is currently available and that there are new tasks to be assigned.

3. Preparation of Slave

Slave registers his information with zk and asks zk to inform Master, "I'm online. I have a new task assigned to me!" Similarly, Master needs to know which slave is down in time, so slave must create temporary nodes in the / works directory. Slave then needs to create a node / work1 under the / assign directory and monitor this node for task assignment.

Create-e / assign/work1 "work1_ip" ls / assign/work1 true4 client submit task

The client creates a node under / assign that contains task information, that is, to publish a task. And monitor the node to get the completion of the task

Create-s / task/task- "cmd" ls / task/task-000 true5 Master assign tasks

After the task is published, the Master that monitors / assign will receive notification of the new task. Then Master looks at the available slave under / works and chooses one to assign to the task (add a task node in the slave directory)

Create-e / assign/work1/task-0006 Slave get to work

When slave receives the notification of a new task assignment, it begins to execute the task.

Ls / assign/work/task-000 / / View task information

Then, when finished, add the execution status and notify the client.

Create / tasks/task-000/status "done" # 7 customer acceptance result

The client views the task node information and the task status

Get / tasks/task-000

Above! It only describes the general principle of implementing the master-slave structure with zk.

Drawing is very tiring. Please explain the source of the reprint. I'd like the mailbox of the original picture. The content is sorted out from the book "O'REILLY Zookeeper" so far. I believe you have a deeper understanding of "the principle of master-slave structure of zookeeper implementation". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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