2.2分布式算法(2)-领导者选举

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Often, there is no owner or master that is automatically considered as coordinator


选举问题

Many distributed systems are client server based, with one server/coordinator (leader), and multiple clients
What happens if the leader fails?


Elect a new one

Cannot assume only one process detects the crash

The election should get all of the processes to agree that one node is a leader

Max identity and Min identity available (extreme values)
Remark



Processors are in one of three states: undecided, leader, lost Initially every process is in the undecided state When leaving the undecided state, a processor goes into a terminated state (leader or lost)
15
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
7
8
not allowed to initiate
9 6
2 5 3 1
not allowed to initiate
Initially only know myself
Send my id, and wait Repeat forwarding and collecting ids until we receive our id Termination: did we win or lose
Non-initiators just forward and lose
7
8
not allowed to initiate
9 6
2 5 3 1
initiator
not allowed to initiate
not allowed to initiate
initiator
not allowed to initiate
18
Example

Nodes are not allowed to initiate a message after they receive a token (example…)



Let every initiator send a token with their identity around the whole ring Nodes are not allowed to initiate after they receive a token (example…)
11
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
7
8 2 5
9 6
3
1
initiator
12
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
Fra Baidu bibliotek么是选举
“to start from a configuration where all processes are in the same state and arrive at a configuration where exactly one process is the leader”
Goal: to obtain low message complexity
2 5 3 1
initiator
not allowed to initiate
initiator
not allowed to initiate
17
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
分布协同计算基础
第二章:
分布式算法(2) ---领导者选举
张锡哲 副教授 计算机应用技术研究所 东北大学信息科学与工程学院
选举问题

If we are using one process as a coordinator for a shared resource … …how do we select that one process?


when a centralized algorithm is to be executed in a distributed system for instance, after a system crash when it is unknown which nodes are working
14
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
7
8 2 5
not allowed to initiate
9 6
3
1
initiator
not allowed to initiate

Fully asynchronous system

No global clock, transmission times arbitrary

Every process has a unique identity

Identities are totally ordered Because we have finite number of processes:
not allowed to initiate
8
not allowed to initiate
7
9 6
2 5 3 1
initiator
not allowed to initiate
not allowed to initiate
initiator
not allowed to initiate
19
LeLann’s ring election
Message Complexity

Worst case is every node is initiator (N)

Every initiator sends N messages

Gives a total of N2 messages
22
时间复杂度

Assume last initiator f starts at time N-1

It reaches a terminal configuration, and in each reachable terminal configuration one process is in state leader and the rest are in the state lost
假设
选举谁?

Basic idea:

If each process has a unique identity, and the identities are ordered

Elect the non-crashed node with minimum/maximum identity
选举算法的应用



When a node receives a token with larger id than itself, why should it keep forwarding it? It is a waste, we know that that id will never win! Lets drop tokens with larger ids than ourselves!

Whenever a node receives back its id, it has seen every other initiators id

Assuming FIFO channels

Let every node keep a list of every identifier seen (listp)

If node s token is dropped, it will anyway receive another token with lower id

In that case, s should set state=lost
26
Chang and Roberts Algo
Initiator sends its token While not leader, keep receiving tokens Otherwise, only forward if it’s lower id than me and lose
7
8 2 5
9 6
3
1
initiator
13
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
7
8 2 5
9 6
3
1
initiator
not allowed to initiate
initiator
not allowed to initiate
16
Example

Nodes are not allowed to initiate a message after they receive a token (example…)
7
8
not allowed to initiate
9 6
24
How to make it work


But if we drop a token with id s, node s will be waiting forever on its token to come back How do we solve that?
25
How to make it work

If non-initiator, state=lost immediately If initiator, when own id received:
state=leader if min{listp}=p state=lost otherwise

20
LeLann’s Algorithm

8 2 5
7
9 6
f terminates after its token has circulated the ring, N steps
3
1
last initiator
initiator

Time complexity 2N-1
23
Chang-Roberts 算法


Chang and Roberts came up with a small improvement Idea:
环网上的选举
单向环 双向环
LeLann 77, O(N2) Chang-Roberts 79 Ω(N2), Θ(NlogN) Hirshberg et al. 80 Ω(NlogN) Petersen/Dolev et al. 82 Ω(NlogN)
环网上的选举

The first ever election algorithm was done for rings by LeLann Simple idea:
选举算法的定义

Formally, an algorithm is an election algorithm iff:

Each process has the same local algorithm The algorithm is decentralized

It can be initiated by any number of processes in the system
相关文档
最新文档