Introduction to Self-Stabilization
Maria Potop-Butucaru, Franck Petit and Sébastien Tixeuil
LiP6/UPMC
Self-stabilization 101
Example
U
0= a
U
n+1=
U2nif U
nis even
U
n+1=
3Un2+1if U
nis odd
Example
U
0= a
U
n+1=
U2nif U
nis even
U
n+1=
3Un2+1if U
nis odd
n U
n0 1 2 3 4 5 6 7 8 9 10 11 12
7 11 17 26 13 20 10 5 8 4 2 1 2
Example
U
0= a
U
n+1=
U2nif U
nis even
U
n+1=
3Un2+1if U
nis odd
16
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
27
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Iterations
Values
"Correct"
Example
Self-stabilization
Time
Configurations
"Correct"
Time
Configurations
"Correct"
Stabilization Time
Time
Configurations
"Correct"
Stabilization Time Stabilized
Self-stabilization
Arbitrary Legitimate
f1 f2
f1
Self-stabilization
Distributed Systems
a b
c d
l
i
h
j
e
f
g
k
Distributed Systems
a b
c d
l
i
h
j
e
f
g
k
Distributed Systems
6 4
5 3
4
6
1
1
4
6
3
4
Distributed Systems
• Locality of time
• Locality of information
• Non-determinism
Distributed Systems
• Configuration: product of the local states of system components
• Execution: interleaving of the local
executions of the system components
Distributed Systems
• Classical: Starting from a particular initial configuration, the system immediately
exhibits correct behavior
• Self-stabilizing: Starting from any initial configuration, the system eventually reaches a configuration from which its behavior is
correct
Distributed Systems
• Self-stabilizing: Starting from any initial configuration, the system eventually reaches a configuration from which its behavior is
correct
• Defined by Dijkstra in 1974
• Advocated by Lamport in 1984 to address
fault-tolerant issues
Configurations
Self-stabilization Hypothesis Composition Proof Techniques Conclusion
Memory Corruption
I
Example of a sequential program:
int x = 0;
...
if( x == 0 ) {
// code assuming x equals 0 }
else {
// code assuming x does not equal 0
}
Configurations
i j
i j
Configurations
a b
c d
l
i
h
j
e
f
g
k
Hypotheses
Atomicity
• A «stabilizing» sequential program
Self-stabilization Hypothesis Composition Proof Techniques Conclusion
Atomicity
I Example of “stabilizing” sequential program
int x = 0;
...
while( x == x ) { x = 0;
// code assuming x equals 0
}
Atomicity
• A «stabilizing» sequential program
Self-stabilization Hypothesis Composition Proof Techniques Conclusion
Atomicity
I
Example of “stabilizing” sequential program
0 iconst_0 1 istore_1 2 goto 7
5 iconst_0 6 istore_1 7 iload_1 8 iload_1
9 if_icmpeq 5
Problem
Communications
a b
c e
e
Communications
a b
c e
e
Communications
a b
c e
e
Example
• Shared memory: in one atomic step, read the state of all neighbors and write own state
• Guarded command
Guard ! Action
Predicate on the states of the neighborhood
Executed if
Guard is true
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
TR1
TR2
TR2
top
TR2
TR2 TR2
TR2
TR2
TR1
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Self-
stabilizing?
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR2
TR2
TR2
TR2 TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
TR2
TR2 TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
TR2
TR2 TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
TR2 TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
TR2
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
TR2
TR2
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2 TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
TR2
TR2 TR2
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR1
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
TR2
TR2 TR2
TR2
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process
gets the token infinitely often
top
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
TR2
TR2
TR2 TR2
TR2
TR2
Idem configuration initiale
Token Ring
Specification
Safety : At most one token in the system
Liveness : Each process lets the token infinitely often
p = top
TR1 : (vp =vl) → vp:=vl⊕1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Exercice : Montrer qu'il se produit la même chose avec un
nombre impair de
processeurs.
Token Ring
top
Algorithme Auto-stabilisant de circulation de jeton de Dijkstra
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
7 5 2
8 3
1 4 6
TR2TR2 TR2 TR2
TR2 TR2
TR2
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
2 5 5
3 1
4 6 7
TR2TR2 TR2 TR2
TR2
TR2
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
5 5 5
1 4
6 7 2
TR2TR2 TR2 TR2
TR2
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
5 5 5
4 6
7 2 5
TR2 TR2 TR2
TR2
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 5 5
6 7
2 5 5
TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 5 5
7 2
5 5 5
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 5 5
2 5
5 5 5
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 5 5
5 5
5 5 5
TR1
Valeur de k ?
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 0 6
0 1
2 3 4
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
6 1 0
1 2
3 4 5
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
0 2 1
2 3
4 5 6
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
1 3 2
3 4
5 6 0
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
2 4 3
4 5
6 0 1
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
3 5 4
5 6
0 1 2
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
4 6 5
6 0
1 2 3
TR2TR2 TR2 TR2
TR2
TR1
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
5 7 6
0 1
2 3 4
TR2TR2 TR2 TR2
TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
6 7 7
1 2
3 4 5
TR2TR2 TR2 TR2
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
2 3
4 5 6
TR2TR2 TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
3 4
5 6 7
TR2 TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
4 5
6 7 7
TR2 TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
5 6
7 7 7
TR2
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
6 7
7 7 7
TR2
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
Token Ring
top Algorithme Auto-stabilisant de
circulation de jeton de Dijkstra
7 7 7
7 7
7 7 7
TR1
Temps de Stabilisation : O(n)
p = top
TR1 : (vp =vl) → vp:=vl⊕k1 p ≠ top
TR2 : (vp ≠ vl) → vp:=vl
[Dijkstra 74]
B T
Bottom
Top
Middle
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
[Dijkstra 74]
B T
Bottom
Top
Middle
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Bottom
Top
Middle
[Dijkstra 74]
Bottom Top Middle
B T
Auto-stabilisation ?
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Stabilisé !
Bottom
Top
Middle
[Dijkstra 74]
B T
Bottom Top Middle
Stabilisé !
Temps de stabilisation = O(n)
R0 : (Lp≠n) et (Lp≠LF+1) et (LF ≠n) → Lp := LF+1;
R1 : (Lp≠n) et (LF=n) → Lp := n;
R2 : Soit q un voisin de p tel que :
(Lp=n) et (Lq<n-1) → Lp := Lq+1; F:=q;
Construction d’arbre couvrant auto-stabilisante
r
010 9
2 4
13 1
11 12
4
7 1
1
5
(n=14)
R0
R0 R0
R0 R0
R0 R0 R0
R0 R0
R0 R0
BFS
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
3 3
2 1
2
2
r
1
2
2
1
3
BFS
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
3 4
2 2
2
8
r
1
2
7
1
3
BFS
3 4
2 2
3
8
r
1
2
7
1
3
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
BFS
3 4
2 1
3
1
r
1
2
7
1
3
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
BFS
3 4
2 1
2
1
r
1
2
2
1
3
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
BFS
3 3
2 1
2
1
r
1
2
2
1
3
true ! Distance
i:= M in
j2N eighborsi{ Distance
j+ 1 }
Scheduling
• Scheduler (a.k.a. Daemon): the daemon chooses among activatable processes those that will execute their actions
• can be seen as an adversary whose role is
to prevent stabilization
Spatial Scheduling
true ! color
i:= M in \ { color
j| j 2 N eighbors
i}
=
a b
d
c e
f
a b
a d
c e
f
a b
Temporal Scheduling
token ! pass token to left neighbor with probability 1
token = no token = 2
Temporal Scheduling
token ! pass token to left neighbor with probability 1
token = no token = 2
Composition Schemes
Fair Composition
• Basic idea
• Compose several self-stabilizing
algorithms such that their results can be resused by
• can not detect whether algorithms have stabilized, but behaves as if
A
1, A
2, . . . , A
kA
k+1A
k+1Fair Composition
• Example with k=2
• Two simple algorithms server and client
are combined to obtain a more complex algorithm
• The server algorithm ensure that some
properties (used by the client) will be
eventually satisfied
Fair composition
• Definition: is a fair composition of and if, in , every process alternatively executes actions of and
A A
1A
2A
A
1A
2Fair Composition
• Theorem: If is self-stabilizing for
given , and if is self-stabilizing for , then the fair composition of and is self-stabilizing for
A
1A
2T
2T
1T
1A
1A
2T
2A
1T
1A
2T
2Example
• We are given two self-stabilizing
algorithms, one for constructing a tree in a general network, one for mutual exclusion on a unidirectional ring
3 3
2 1 2
1
r
1
2
2
1
3
3 3
2 1 2
1
r
1
2
2
1
3
a b
c d
l
i
r
j
e
f
g
k
Example
d
c a c b c d e
d r g
f k f
g r
j r
i
l
i
r
a b
c d
l
i
r
j
e
f
g
k
Crossover Composition
• Basic idea
• Algorithm is correct under daemon
• Algorithm is correct under daemon
• is more restrictive than
• We want to run under
• produces , and is executed when produces activation
A
1A
2D
1D
2D
2D
1A
2D
1A
1D
2A
2A
1Example
• Uniform unidirectionnal ring
• Each node has a variable
• Each node has a token if
• Each node passes a token by executing v
iv
i6 = v
i 1mod SND
nv
i:= v
i 1+ 1 mod SND
n(SND
n: smallest non divisor of n)
Example
0
0 1
0 1
Changes
to 0 0
0 0
0 1
Changes
0 to 1
1 0
0 1
Changes to 1
1
1 0
0
1
Example
• Algorithm 1
• A node with a token is activatable
• An activated node always transmits the token
• Algorithm 1 solves the token passing
problem with arbitrary daemon
Example
• Algorithm 2
• A node with a token is activatable
• An activated node transmits the token with probability 1/2
• Algorithm 2 solves mutual exclusion if
daemon is bounded (in time)
Example
• Crossover Composition
• A node may have up to two tokens (one deterministic and one probabilistic)
• A node with a deterministic token is activatable
• An activated node passes the deterministic token and (if it has it) the probabilistic
token with probability 1/2
Example
Probabilistic Deterministic
Example
• Algorithm 2 composed with Algorithm 1 solves mutual exclusion with an arbitrary daemon
• The solved problem does not change, but
the daemon is less restrictive
Proof Techniques
Transfer function
• Basic idea
• Used to prove convergence
• Convenient to compute stabilization time
Self-stabilization Hypothesis Composition Proof Techniques Conclusion
Transfer Function
Basic Idea
I
c
1! c
2! c
3! c
4! · · · ! c
iI
FP ( c
1) > FP ( c
2) > FP ( c
3) > . . . > FP ( c
i) = bound
I
Used to prove convergence
I
Can be used to compute the number of steps to reach
a legitimate configuration
Transfer Function
Time
Configurations
"Correct"
Stabilization Time Stabilized
Time
Configurations
"Correct"
Stabilization Time Stabilized
Attractors
Arbitrary Attractor
Legitimate
d
Attractors
Arbitrary Legitimate
f1 f2
f1
Attractors
Arbitrary
Attractor
Legitimate
f
f f
f f
f
f f
f f
f f f
f f
f f