Distributed algorithms - Chapter 7 : Failure Detectors...

93
1 Distributed Algorithms Master 2 IFI, CSSR Chapter 7 : Failure Detectors, Consensus, Self-Stabilization Francesco Bongiovanni INRIA Sophia Antipolis Research Center OASIS Team [email protected] Course web site : deptinfo.unice.fr/~baude/AlgoDist Nov. 2009

Transcript of Distributed algorithms - Chapter 7 : Failure Detectors...

Page 1: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

1

Distributed Algorithms

Master 2 IFI, CSSR

Chapter 7 : Failure Detectors, Consensus, Self-Stabilization

Francesco Bongiovanni INRIA Sophia Antipolis Research Center

OASIS Team

[email protected] web site :

deptinfo.unice.fr/~baude/AlgoDistNov. 2009

Page 2: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

2

Acknowledgement

The slides for this lecture are based on ideas and materials from the following sources:

Introduction to Reliable Distributed Programming Guerraoui, Rachid, Rodrigues, Luís, 2006, 300 p., ISBN: 3-540-28845-7 (+ teaching material)

ID2203 Distributed Systems Advanced Course by Prof. Seif Haridi from KTH – Royal Institute of Technology (Sweden)

CS5410/514: Fault-tolerant Distributed Computer Systems Course by Prof. Ken Birman from Cornell University

Distributed Systems : An Algorithmic Approach by Sukumar, Ghosh, 2006, 424 p.,ISBN:1-584-88564-5 (+teaching material)

Various research papers

Page 3: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

3

Outline 1. Failure Detectors

Definition Properties – completeness and accuracy Classes of FDs Two algorithms : PFD and EPFD Leader Election vs Failure Detector

2. Consensus Definition Properties Types of Consensus : regular and uniform Algorithm: hierarchical consensus

3. Self-stabilization Principle Example: Dijkstra's Token ring

Page 4: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

4

Failure detectors

Page 5: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

5

System models

synchronous distributed system each message is received within bounded time each step in a process takes lb < time < ub each local clock’s drift has a known bound

asynchronous distributed system no bounds on process execution no bounds on message transmission delays arbitrary clock drifts

the Internet is an asynchronous distributed system

Page 6: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

6

Arbitrary (Byzantine)

Crashes and recoveries

Omissions

Crashes

Failure model

First we must decide what do we mean by failure? Different types of failures

Crash-stop (fail-stop)

A process halts and

does not execute any

further operations Crash-recovery

A process halts, but then

recovers (reboots) after

a while

Crash-stop failures can be detected in synchronous systems

Next: detecting crash-stop failures in asynchronous systems

Page 7: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

7

What's a Failure Detector ?

Pi

Pj

Page 8: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

8

What's a Failure Detector ?

Pi

Pj

Crash failure

Page 9: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

9

What's a Failure Detector ?

Pi

Pj

Crash failure

Needs to know about PJ's failure

Page 10: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

10

1. Ping-ack protocol

Pi

Pj

Needs to know about PJ's failure

- Pi queries P

j once every T time units

- if Pj does not respond within T time units,

Pi marks p

j as failed

If pj fails, within T time units, p

i will

send it a ping message, and will time out within another T time units.

Detection time = 2T

ping

ack

- Pj replies

Page 11: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

11

2. Heart-beating protocol

Pi

Pj

Needs to know about PJ's failure

- if Pi has not received a new heartbeat for the past

T time units, Pi declares P

j as failed

If pj has sent x heartbeats until the time it fails, then p

i will

timeout within (x+1)*T time units in the worst case, and will detect pj as failed.

heartbeat

- Pj maintains a sequence

number

- Pj send P

i a heartbeat with

incremented seq. number after T' (=T) time units

Page 12: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

12

Failure Detectors

Abstracting time

FD provide information (not necessary fully accurate) about which processes have crashed

Use failure detectors to encapsulate timing assumptions Black box giving suspicions regarding node failures Accuracy of suspicions depends on model strength

Page 13: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

13

Failure Detectors

Basic properties

Completeness

Every crashed process is suspected

Accuracy

No correct process is suspected

Both properties comes in two flavours Strong and Weak

Page 14: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

14

Failure Detectors

Strong Completeness Every crashed process is eventually suspected by every correct process

Weak Completeness Every crashed process is eventually suspected by at least one correct process

Strong Accuracy No correct process is ever suspected

Weak Accuracy There is at least one correct process that is never suspected

Page 15: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

15

Failure Detectors

Accuracy

CompletenessWeak

Weak Strong Eventually Weak

EventuallyStrong

W Q Eventual Weak◊W

◊Q

Strong

StrongS

PerfectP

Eventual Strong

◊S

Eventually Perfect

◊P

Classes of FDs

Synchronous Systems Asynchronous Systems

Page 16: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

16

Perfect Failure Detector (P)

Page 17: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

17

Perfect Failure Detector (P)

Page 18: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

18

Correctness of P PFD1 (strong completeness)

A crashed node doesn’t send <heartbeat> Eventually every node will notice the absence of <heartbeat>

PFD2 (strong accuracy) Assuming local computation is negligible Maximum time between 2 heartbeats

γ + δ time units

If alive, all nodes will recv hb in time No inaccuracy

Page 19: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

19

Eventually Perfect Failure Detector

Page 20: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

20

Eventually Perfect Failure Detector

Page 21: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

21

Correctness of EPFD

PFD1 (strong completeness) Same as before

PFD2 (eventual strong accuracy) Each time p is inaccurately suspected by a correct q

Timeout T is increased at q Eventually system becomes synchronous, and T becomes larger than the unknown

bound δ (T>γ +δ)

q will receive HB on time, and never suspect p again

Page 22: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

22

Leader Election

Page 23: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

23

Leader Election vs Failure Detection

Failure detection captures failure behavior Detect failed nodes

Leader election (LE) also captures failure behavior Detect correct nodes (a single & same for all)

Formally, leader election is an FD Always suspects all nodes except one (leader) Ensures some properties regarding that node

Page 24: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

24

Leader Election vs Failure Detection

We’ll define two leader election algorithm

Leader election (LE) which “matches” P Eventual leader election (Ω) which “matches” eventual P

Page 25: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

25

Matching LE and P P’s properties

P always eventually detects failures (strong completeness) P never suspects correct nodes (strong accuracy)

Completeness of LE Informally: eventually ditch crashed leaders Formally: eventually every correct node trusts some correct node

Accuracy of LE Informally: never ditch a correct leader Formally: No two correct nodes trust different correct nodes

Is this really accuracy? Yes! Assume two nodes trust different correct nodes One of them must eventually switch, i.e. leaving a correct node

Page 26: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

26

LE desirable properties LE always eventually detects failures

Eventually every correct node trusts some correct node

LE is always accurate No two correct nodes trust different correct nodes

But the above two permit the following

But P1 is “inaccurately” leaving a correct leader

Page 27: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

27

LE desirable properties To avoid “inaccuracy” we add

Local Accuracy: If a node is elected leader by p

i, all previously elected leaders

by pi have crashed

Not allowed, as P1 is

correct

Page 28: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

28

Leader election - interface

Page 29: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

29

Leader election - algorithm

Page 30: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

30

Matching Ω and EPFD Eventual P weakens P by only providing eventual accuracy

Weaken LE to Ω by only guaranteeing eventual agreement

LE Properties:

LE1 (eventual completeness). Eventually every correct node trusts some correct node

LE2 (agreement). No two correct nodes trust different correct nodes

LE3 (local accuracy).If a node is elected leader by pi,

all previously elected leaders by pi have crashed

eventual

Page 31: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

31

Eventual Leader election - interface

Page 32: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

32

Eventual Leader election - algorithm

See in the book...

Page 33: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

33

Consensus (agreement)

Page 34: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

34

Consensus In the consensus problem, the processes propose values and have

to agree on one among these values

Solving consensus is key to solving many problems in distributed computing (e.g., total order broadcast, atomic commit, terminating reliable broadcast)

BA

C

Page 35: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

35

Consensus – cannonical application

a set of servers implement a distributed database

a subset of servers participate in a particular transaction some of the servers may fail the remaining servers must agree on whether to install the

results of the transaction to the database or discard them

Page 36: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

36

Consensus – cannonical application

Page 37: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

37

Consensus – cannonical application

Page 38: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

38

Consensus – basic properties

Termination Every correct node eventually decides

Agreement No two correct processes decide differently

Validity Any value decided is a value proposed

Integrity: A node decides at most once

Page 39: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

39

FLP impossibility result Consensus in Asynchronous System

Impossibility of consensus in the fail-silent model

FPL (Fischer, Lynch and Peterson 1985) : consensus is impossible in the fail-silent model with deterministic processes, even if only one process crashes

No way to satisfy agreement (safety) and termination (liveness) together

Page 40: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

40

How to solve consensus in asynchronous systems with crashes ?

How to solve consensus in the presence of crashes ?

Either we relaxed our system model, that is, we assume partial synchrony

Either we modify the specifications Constraining the set of inputs Change the termination property: terminates with some

probability

Or...

Page 41: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

41

How to solve consensus in asynchronous systems with crashes ?

Intuitively consensus is impossible to solve because : 1) the decision depends on one process 2) we have no idea if this process is alive (we have to wait for its

message) or dead.

Thus we add to the asynchronous system what it needs in order to solve the consensus: Failure detectors

Page 42: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

42

(regular) Consensus

Page 43: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

43

(regular) Consensus

Sample execution

Question : does it satisfy consensus ?

Page 44: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

44

Uniform consensus

Page 45: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

45

Uniform consensus

Question: Does it satisfy uniform consensus ?

Page 46: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

46

Hierarchical consensus

Use perfect fd (P) and best-effort bcast (BEB)

Each node stores its proposal in proposal Possible to adopt another proposal by changing proposal Store identity of last adopted proposer in lastprop

Loop through rounds 1 to N In round i

node i is leader and broadcasts proposal v, and decides proposal v

other nodes adopt i’s proposal v and remember lastprop i or detect crash of i

Page 47: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

47

Hierarchical consensus idea

Basic idea of hierarchical consensus There must be a first correct leader p,

P decides its value v and bcasts v BEB ensures all correct nodes get v

Every correct node adopts v Future rounds will only propose v

Page 48: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

48

Problem with orphan messages...

Only adopt from node i if i>lastProp?

Page 49: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

49

Invariant to avoid orphans

Leader in round r might crash, but much later affect some node in round>r

Invariant adopt if proposer p is ranked lower than lastprop otherwise p has crashed and should be ignored

Page 50: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

50

Execution without failure...

Page 51: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

51

Execution with failure...

Is it uniform ?

Page 52: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

52

Hierarchical consensus Impl. (1)

Last adopted proposal and Last adopted proposer id

Page 53: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

53

Hierarchical consensus Impl. (2)

set node’s initial proposal,unless it has alreadyadopted another node’s

If I am leader

Trigger onceper round

Trigger if I have proposal

Permanently decide

Next round ifdeliver or crash

Invariant: only adopt “newer” than what you have

Page 54: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

54

Correctness Validity

Always decide own proposal or adopted value

Integrity Rounds increase monotonically A node only decide once in the round it is leader

Termination Every correct node makes it to the round it is leader in

If some leader fails, completeness of P ensures progress

If leader correct, validity of BEB ensures delivery

Page 55: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

55

Correctness (2) Agreement

No two correct nodes decide differently

Take correct leader with minimum id i By termination it will decide v It will BEB v

Every correct node gets v and adopts it

No older proposals can override the adoption

All future proposals and decisions will be v

How many failures can it tolerate? N-1

Page 56: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

56

Self-stabilization

Page 57: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

57

Recall

Main challenges in distributed systems: Failures Concurrency

In presence of (permanent) failures, a robust algorithm guarantees Liveness properties are eventually achieved Safety properties are never violated

Page 58: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

58

Self-Stabilization

Self-stabilization is a different approach to fault tolerance

it considers transient (temporary) failures it is more optimistic

If bad thing happen (safety is violated), the system will recover within a finite time, and will behave nicely afterwards.

Page 59: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

59

Definition

“A system is self-stabilizing when, regardless of its initial state, it is guaranteed to arrive at a legitimate state in a finite number of steps.” 1

Edsger W. Dijkstra

[1] Edsger W. Dijkstra, Self-stabilizing systems in spite of distributed control, Communications of the ACM, v.17 n.11, p.643644,Nov. 1974

Page 60: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

60

Self-Stabilization

System S is self-stabilizing with respect to predicate P that identifies the legitimate states, if:

Convergence Starting from any arbitrary configuration, S is guaranteed to

reach a configuration satisfying P, within a finite number of state transitions.

Closure P is closed under the execution of S. That is, once in a

legitimate state, it will stay in a legitimate state.

Page 61: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

61

Some advantages of Self-Stabilizing systems

No need for consistent initialization. Starting in any arbitrary state, the system will converge to a

legitimate state.

Possibility of sequential composition without the need for termination detection.

Page 62: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

62

A self-stabilizing algorithm:Dijkstra's Token ring

Page 63: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

63

Dijkstra's Token ring

A single token circulates over the ring and grants privilege to the process holding it.

N+1 processes: P0, P

2,….,P

n

Connected in a ring Predecessor of P

i

pred(Pi ) = P

(i-1) mod N+1

Successor of Pi

succ(Pi ) = P

(i+1) mod N+1

Page 64: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

64

Token Ring stabilization

Pi has a local variable X

i

Xi can take values from 0 to K-1

(K >= N) Each process, can read the value

of its predecessor (Shared Memory Model)

There is a scheduler, which selects a process at each step, in a random but fair manner.

Page 65: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

65

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Page 66: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

66

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

Page 67: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

67

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

Page 68: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

68

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

You have the token.

Page 69: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

69

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

You have the token.

Page 70: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

70

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

Fire: change your state.

Page 71: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

71

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

Fire: change your state.

Page 72: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

72

Token Ring stabilization

Transition rule for P1 to P

n

if Xi != X

i-1

Xi := X

i-1

Transition rule for P0

if X0= X

n

X0 := (X

0 + 1) mod K

Fire: change your state.

Page 73: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

73

Legitimate or illegitimate?

Page 74: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

74

Legitimate or illegitimate?

Page 75: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

75

Legitimate or illegitimate?

Page 76: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

76

Legitimate or illegitimate?

Page 77: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

77

Legitimate or illegitimate?

Page 78: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

78

Legitimate or illegitimate?

Page 79: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

79

Proof of closure

Page 80: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

80

Proof of closure

Page 81: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

81

Proof of closure

Page 82: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

82

Proof of closure

If there is only a single token in the ring, when the machine that owns the token fires, it loses the token and will give it to its successor, and to no one else.

This single token is handed over along the ring.

Page 83: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

83

Proof of convergence

Lemma 1. P0 eventually receives the token.

- assume it does not have the token, i.e. X0!= X

n

- let j be the minimum value such that Xj!= X

0

- for all i < j: Xi= X

0 → X

j!= X

j+1 → P

j is privileged

- Pj will fire, thus increasing j if j < N, or making X

0 = X

n

if j = N.

→ P0 will eventually receive the token.

Page 84: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

84

Proof of convergence

Initially all the process states are white.

Page 85: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

85

Proof of convergence

Initially all the process states are white.

Whenever P0 fires, we colour

its state.

Page 86: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

86

Proof of convergence

Initially all the process states are white.

Whenever P0 fires, we colour

its state. Whenever a state is copied

from a coloured state, it gets the colour

Page 87: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

87

Proof of convergence

Initially all the process states are white.

Whenever P0 fires, we colour

its state. Whenever a state is copied

from a coloured state, it gets the colour

Whenever a state is checked upon a coloured state it gets the colour.

Page 88: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

88

Proof of convergence

Initially all the process states are white.

Whenever P0 fires, we colour

its state. Whenever a state is copied

from a coloured state, it gets the colour

Whenever a state is checked upon a coloured state it gets the colour.

Page 89: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

89

Proof of convergence

Initially all the process states are white.

Whenever P0 fires, we colour

its state. Whenever a state is copied

from a coloured state, it gets the colour

Whenever a state is checked upon a coloured state it gets the colour.

Page 90: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

90

Proof of convergence

Lemma 2. At most after N firings at P0 , all the local

states are coloured.

- Assume h is the number of times that P0 fires when P

n is

white.

- For each firing, X0 has to be the same as X

n.

- So, Xn has taken h distinct values.

- These values can only be copied from other nodes in the ring.

- At the time of first firing, we can have at most N distinct values in the ring.

- Therefore, h is bounded to N.

Page 91: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

91

Proof of convergence

If P0 initially starts at state K-1, the first N firings of P

0 have

created states 0 to N-1. (K >= N)

When P0 is in state N-1,

All the nodes are coloured. Scanning from P

0 to P

n, the state of the nodes is in a non-

increasing order . next firing at P

0 will happen when X

0 = X

n = N-1.

→At the time of Nth firing of P0, all the states are N-1.

Page 92: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

92

Proof of convergence

Page 93: Distributed algorithms - Chapter 7 : Failure Detectors ...deptinfo.unice.fr/twiki/pub/Minfo/DistributedAlgo/Cours_Failures... · 1 Distributed Algorithms Master 2 IFI, CSSR Chapter

93

Proof of correctness

Starting in an arbitrary state, we ended up in a legitimate state.

=> Convergence

We also showed that, once in a legitimate state, we will remain in a legitimate state.

=> Closure