Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
179
第
10
章
领导者选举
同步的代价可能会非常大:如果算法的每一个步骤都需要联系其他参与者,那么结果一
定是产生相当显著的通信开销。在大型且地理分布的网络中尤其如此。为了减少同步开
销和达成决定所需消息的往返次数,一些算法依赖于
领导者
(有时称为
协调者
)进程的
存在,该进程负责执行或协调分布式算法的各个步骤。
一般来说,分布式系统中的进程是对等的,任何进程都可以接管领导者的角色。进程可
以长期担任领导者,但这不是一个永久的角色。通常情况下,进程可以一直担任领导者
直到崩溃为止。崩溃后,任何其他进程都可以开始新一轮的选举,如果其当选,就可以
担任领导者并继续执行上个领导者遗留的工作。
选举算法的
活动性
(liveness)保证了
大多数时候
会有一个领导者,选举最终会完成(即
系统不应该无限期地处于选举状态)。
理想情况下,我们也希望获得
安全性
,保证一次
最多只能有一个
领导者,并完全消除
脑
裂
(两个目的相同的领导者被选举出来,但彼此不知情)的可能性。然而在实践中,许
多领导者选举算法违反了这一协定。
可以使用领导者进程来实现广播中消息的全序。领导者收集并保存全局状态,接收消
息,并将消息分发给各个进程。它还可以用于协调发生在系统故障后、初始化期间或重
要状态变更时的系统重组。
系统初始化时将会触发选举,第一次选择领导者。当上一个领导者崩溃或通信失败时也
会触发选举。选举必须是确定性的:选举过程中必须只产生一个领导者。这一决定需要
对所有参与者都有效。
尽管领导者选举和分布式锁(即对共享资源的独占所有权)从理论角度看可能很相似
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787111655169