Regional Consecutive Leader Election In Mobile Ad-Hoc Networks
Leader Election
description
Transcript of Leader Election
![Page 1: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/1.jpg)
LEADER ELECTION
CS 271 1
![Page 2: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/2.jpg)
Election Algorithms• Many distributed algorithms need one process to
act as coordinator– Doesn’t matter which process does the job, just need
to pick one• Election algorithms: technique to pick a unique
coordinator (aka leader election)• Types of election algorithms: Bully and Ring
algorithms
CS 271 2
![Page 3: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/3.jpg)
Bully Algorithm• Each process has a unique numerical ID• Processes know Ids and address of all other
process• Communication is assumed reliable• Key Idea: select process with highest ID• Process initiates election if it just recovered from
failure or if coordinator failed• 3 message types: election, OK, I won• Processes can initiate elections simultaneously
– Need consistent result
CS 271 3
![Page 4: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/4.jpg)
Bully Algorithm Details• Any process P can initiate an election• P sends Election messages to all process with
higher Ids and awaits OK messages• If no OK messages, P becomes coordinator &
sends I won to all process with lower Ids• If it receives OK, it drops out & waits for I won• If a process receives Election msg, it returns OK
and starts an election• If a process receives I won then sender is
coordinator
CS 271 4
![Page 5: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/5.jpg)
Bully Algorithm Example
a) Process 4 holds an electionb) Process 5 and 6 respond, telling 4 to stopc) Now 5 and 6 each hold an election
CS 271 5
![Page 6: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/6.jpg)
Bully Algorithm Example
d) Process 6 tells 5 to stope) Process 6 wins and tells everyone
CS 271 6
![Page 7: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/7.jpg)
Simple Ring-based Election• Processes have unique Ids and arranged in a logical ring• Each process knows its neighbors • Select process with highest ID as leader• Begin election if just recovered or coordinator has failed• Send Election to closest downstream node that is alive
– Sequentially poll each successor until a live node is found• Each process tags its ID on the message• Initiator picks node with highest ID and sends a coordinator
message• Multiple elections can be in progress—no harm.
CS 271 7
![Page 8: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/8.jpg)
Ring Algorithm Example
CS 271
8
![Page 9: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/9.jpg)
Ring Algorithm Example
CS 271
9
![Page 10: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/10.jpg)
Comparison
• Assume n processes and one election in progress
• Bully algorithm– Worst case: initiator is node with lowest ID
• Triggers n-2 elections at higher ranked nodes: O(n2) msgs
– Best case: immediate election: n-2 messages• Ring
– 2 (n-1) messages always
CS 271 10
![Page 11: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/11.jpg)
Highlights of Leader Election
• Basic idea: each process has a unique process-id.
• Once leader is discovered died, elect process with highest (lowest) process-id.
CS 271 11
![Page 12: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/12.jpg)
BROADCAST PROTOCOLS
CS 271 12
![Page 13: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/13.jpg)
Broadcast Protocols
• Why Broadcast protocols?– Data replication– Highly available servers– Cluster management– Distributed logging– ……
• Sometimes, message is received, but delivered later to satisfy some order requirements.
CS 271 13
![Page 14: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/14.jpg)
Ordering properties: FIFO(Cornell)• Fifo or sender ordered multicast: fbcast
Messages are delivered in the order they were sent (by any single sender)
p
q
r
s
a e
CS 271 14
![Page 15: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/15.jpg)
Ordering properties: FIFO
p
q
r
s
a
b c d
e
delivery of c to p is delayed until after b is delivered
CS 271 15
![Page 16: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/16.jpg)
Limitations of FIFO Broadcast
Scenario:• User A broadcasts a message to a mailing list• B delivers that message• B broadcasts reply• C delivers B’s response without A´s original
message• and misinterprets the message
CS 271 16
![Page 17: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/17.jpg)
Ordering properties: Causal• Causal or happens-before ordering: cbcast
If send(a) send(b) then deliver(a) occurs before deliver(b) at common destinations
p
q
r
s
a
b
CS 271 17
![Page 18: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/18.jpg)
Ordering properties: Causal
p
q
r
s
a
b cdelivery of c to p is delayed until after b is delivered
CS 271 18
![Page 19: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/19.jpg)
Ordering properties: Causal
p
q
r
s
a
b c
e
delivery of c to p is delayed until after b is deliverede is sent (causally) after b
CS 271 19
![Page 20: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/20.jpg)
Ordering properties: Causal
p
q
r
s
a
b c d
e
delivery of c to p is delayed until after b is delivereddelivery of e to r is delayed until after b&c are delivered
CS 271 20
![Page 21: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/21.jpg)
Limitation of Causal Broadcast
Causal broadcast does not impose any order on unrelated messages.
Two replicas can deliver operations/request in different order.
CS 271 21
![Page 22: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/22.jpg)
Ordering properties: Total• Total or locally total multicast: atomic bcast
Messages are delivered in same order to all recipients (including the sender)
p
q
r
s
a
b c d
e
all deliver a, b, c, d, then e
CS 271 22
![Page 23: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/23.jpg)
Simple Causal broadcast protocol
• Each broadcast message carries all causally preceding messages
• Before delivery, ensure causality by delivering any missed causally preceding messages.
CS 271 23
![Page 24: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/24.jpg)
Isis Causal Broadcast
• Each process maintains a time vector of size n.• Initially VT[i] = 0.• When p sends a new message m: VT[p]++• Each message is piggybacked with VTm which
is the current VT of the sender.• When p delivers a message, p updates its
vector: for k in 1..n:– VTp[k] = max{ VTp[k], VTm[k] }.
CS 271 24
![Page 25: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/25.jpg)
Isis Causal Order
• Requirement for delivery at node j:– VTsender[sender] = VTreceiver[sender]+1
• This is the next message from sender
– VTsender[k] =< VTreceiver[k] for all k not sender• Receiver has received all causally preceding messages
sender recei
ver
VTsender VTreceiver
CS 271 25
![Page 26: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/26.jpg)
Total order
• Different classes of total order broadcast:– Fixed sequencer – Moving sequencer using Token– Dstributed agreement using Timestamp
CS 271 26
![Page 27: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/27.jpg)
Using Sequencer (Amoeba)• Delivery algorithm similar to FIFO except for using
a special “sequencer” to order messages• Sender attaches unique id i to each message m
and sends <m,i> to the sequencer as well as to all destinations
• Sequencer maintains sequence number S (consecutive and increasing) and broadcast <i, S> to all destinations.
• Message(k) is delivered – if all messages(j) (0 j < k) are received
CS 271 27
![Page 28: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/28.jpg)
Distributed Total Order Protocol (ISIS)• Processes collectively agree on sequence
numbers (priority) in three rounds• Sender sends message <m, id> to all receivers;• Receivers suggest priority (sequence number) and
reply to sender with proposed priority;• Sender collects all proposed priorities; decides on
final priority (breaking ties with process ids), and resends the agreed final priority for message m
• Receivers deliver message m according to decided final priority
CS 271 28
![Page 29: Leader Election](https://reader036.fdocuments.in/reader036/viewer/2022062411/56816733550346895ddbdfaa/html5/thumbnails/29.jpg)
ISIS algorithm for total ordering
2
1
1
2
2
1 Message
2 Proposed Seq
P2
P3
P1
P4
3 Agreed Seq
3
3
Group g: P1, P2, P3, P4
CS 271 29