Consensus in Distributed Systems
Course: Distributed Computing Faculty: Dr. Rajendra Prasath
Spring 2019
Consensus in Distributed Systems Course: Distributed Computing - - PowerPoint PPT Presentation
Consensus in Distributed Systems Course: Distributed Computing Faculty: Dr. Rajendra Prasath Spring 2019 About this topic This course covers various concepts in Consensus in Distributed Systems. We will also focus on the essential aspects of
Spring 2019
This course covers various concepts in Consensus in Distributed Systems. We will also focus on the essential aspects of consensus protocols in distributed systems.
2
Rajendra, IIIT Sri City
è Challenges in Message Passing systems è Distributed Sorting è Space-Time Diagram è Partial Ordering / Causal Ordering è Concurrent Events è Local Clocks and Vector Clocks è Distributed Snapshots è Termination Detection è Topology Abstraction and Overlays è Leader Election Problem in Rings è Message Ordering / Group Communications è Distributed Mutual Exclusion Algorithms
Rajendra, IIIT Sri City
3
Rajendra, IIIT Sri City
4
A system is self-stabilizing if and only if: è Convergence: Starting from any state, it is guaranteed that the system will eventually reach a correct state è Closure: Given that the system is in a correct state, it is guaranteed to stay in a correct state, provided that no fault happens è A system is said to be randomized self-stabilizing if and only if it is self-stabilizing and the expected number of rounds needed to reach a correct state is bounded by some constant k
5
Rajendra, IIIT Sri City
è For any machine:
è S – State of its own è L – State of the left neighbor and è R - State of the right neighbor on the ring
è The exceptional machine:
è If L = S then S = (S+1) mod K;
è All other machines:
è If L = S then S = L;
6
Rajendra, IIIT Sri City
è A Privilege of a machine is able to change its current state on a Boolean predicate that consists of its current state and the states of its neighbors è When a machine has a privilege, it is able to change its current state, which is referred to as a move.
è The bottom machine, machine 0:
è If (S+1) mod 3 = R then S = (S−1) mod 3;
è The top machine, machine n−1:
è If L = R and (L+1) mod 3 = S then S = (L+1) mod 3;
è The other machines:
è If (S+1) mod 3 = L then S = L;
7
Rajendra, IIIT Sri City
Let us explore distributed consensus algorithms in Distributed Systems
Rajendra, IIIT Sri City
8
Reaching agr Reaching agreement eement is a fundamental pr is a fundamental problem in
distributed computing distributed computing Examples: Examples:
è Leader election / Mutual Exclusion è Commit or Abort in distributed transactions è Reaching agreement about which process has failed è Clock phase synchronization è Air traffic control system: all aircrafts must have the same view
Rajendra, IIIT Sri City
9
u3 u2 u1 u0 v v v v
è Each process pi has an input value ui è These processes exchanges their inputs, so that the
even if one or more processes fail at any time è Output v must be equal to the value of at least one process
input
p0 p1 p2 p3
Rajendra, IIIT Sri City
10
Termination ermination Every non-faulty process must eventually decide. Agr Agreement eement The final decision of every non-faulty process must be identical. Validity alidity If every non-faulty process begins with the same initial value v, then their final decision must be v
Rajendra, IIIT Sri City
11
Rajendra, IIIT Sri City
12
Seven members of a busy household decided to to hir hire e a a cook cook, since they do not have time to prepare their own food Each member separ separately ately interviewed interviewed every applicant for the cook’s position. Depending on how it went, each member voted "yes" (means "yes" (means “hir hire”) or "no" (means "no" (means “don't hir don't hire”). These members will now have to communicate with one another to reach each a a uniform uniform final final decision decision about whether the applicant will be hired The process will be repeated with the next applicant, until someone is hired. Consider various modes of communication like shared memory or message passing Also assume that one process may crash at any time
Rajendra, IIIT Sri City
13
Theor heorem em:
Rajendra, IIIT Sri City
14
Rajendra, IIIT Sri City
15
Lemma: emma: Every consensus protocol must have a bivalent initial state bivalent initial state. Proof
by contr contradiction adiction: Suppose not. Then consider the following input patterns: n-1 2 1 0 s[0] 0 0 0 0 0 0 …0 0 0 {0-valent) There must be a j: 0 0 0 0 0 0 …0 0 1 s[j] is 0-valent 0 0 0 0 0 0 …0 1 1 s[j+1] is 1-valent … … … … s[n] 1 1 1 1 1 1 …1 1 1 {1-valent}
What if process j crashes at the first step?
Rajendra, IIIT Sri City
16
communication delays have upper bounds.
worst possible kind of failure
Rajendra, IIIT Sri City
17
to "attack" or to "retreat" during a particular phase of a war. The goal is to agr agree ee upon upon the the same plan of same plan of action action
"traitors" aitors" and therefore send either no input, or send conflicting inputs to prevent the "loyal" "loyal" gener generals als fr from
eaching an an agr agreement eement
eventually agrees upon the same plan, regardless
Rajendra, IIIT Sri City
18
3 2 1
Attack = 1 Attack=1 Retreat = 0 Retreat = 0 {1, 1, 0, 0} {1, 1, 0, 0}
Every general will broadcast his judgment to everyone else. These are inputs to the consensus protocol.
{1, 1, 0, 1} {1, 1, 0, 0}
traitor
The tr he traitor aitor may send may send
conflicting conflicting inputs inputs
Rajendra, IIIT Sri City
19
We need to devise a protocol so that every peer (call it a lieutenant lieutenant) receives eceives the same value the same value from any given general (call it a commander commander) Clearly, the lieutenants will have to use secondary secondary information information Note that the roles of the commander and the lieutenants will rotate among the generals
Rajendra, IIIT Sri City
20
IC1: IC1: Every loyal lieutenant receives the same same or
der from the commander IC2: IC2: If the commander is loyal, then every loyal lieutenant receives the
sends
commander commander
lieutenants
Rajendra, IIIT Sri City
21
Or Oral Messages (OM) al Messages (OM)
can be detected
detected), the receiver knows the identity of the sender (or the defaulter) OM(m) OM(m) represents an interactive consistency protocol in presence of at most m traitors.
Rajendra, IIIT Sri City
22
commander 0 commander 0 lieutenent 1 lieutenant 2 lieutenent 1 lieutenant 2 1 1 1 1 (a) (b)
Using oral messages, no solution no solution to the Byzantine Generals problem exists with thr three or fewer ee or fewer gener generals als and one tr
In (a), to satisfy IC2, lieutenant 1 must trust the commander, but in IC2, the same idea leads to the violation of IC1.
Rajendra, IIIT Sri City
23
Using oral messages, no no solution solution to to the the Byzantine Byzantine Gener Generals als pr problem
exists with 3m 3m or fewer generals and m traitors (m > 0 m > 0) The pr he proof
is by contradiction adiction: Assume that such a solution
generals each, such that all the traitors belong to one
generals and one traitor. We already know that such a solution does not exist. Note Note: Be always suspicious about such an informal reasoning (refer to Lamport’s original paper)
Rajendra, IIIT Sri City
24
Recursive algorithm
OM(m) OM(m-1) OM(m-2) OM(0)
OM(0) = Dir OM(0) = Direct br ect broadcast
Rajendra, IIIT Sri City
25
1. Commander i sends out a value v (0 or 1) 2. If m > 0 0, then every lieutenant j ≠ i, after receiving v , acts as a commander and initiates OM( OM(m-1) with everyone except i 3. Every lieutenant, collects (n-1)
à (n-2) values received from the lieutenants using OM( OM(m-1)
à one direct value from the commander Then he picks the the majority majority of
as the or
der from i
Rajendra, IIIT Sri City
26
1 1 (a) 1 2 2 3 2 3 3 1 1 2 1 1 1 1 1 1 1 1 2 2 3 2 3 3 1 1 2 1 1 1 1 (b) commander commander
Rajendra, IIIT Sri City
27
1 2 2 3 4 5 6 4 5 6 5 6 2 4 6 2 4 5 Commander
OM(2) OM(1) v v v v v v v v v v v v v v v v v v 5 6 2 6 2 5 OM(0) v v v v v v
OM(2) OM(2) OM(1) OM(1) OM(0) OM(0)
Rajendra, IIIT Sri City
28
Lemma: Let the commander be loyal, and n > 2m + k n > 2m + k, where m = maximum number of traitors. Then OM(k) OM(k) satisfies IC2 IC2
m traitors n-m-1 loyal lieutenants values received via OM(r) loyal commander
Rajendra, IIIT Sri City
29
Proof: If k=0, then the result trivially holds. Let it hold for k = r k = r (r > 0) i.e. i.e. OM(r) OM(r) satisfies IC2 satisfies IC2. We have to show that it holds for k = r + 1 k = r + 1 too. By definition, n > 2m+ r+1, so n-1 > 2m+ r So So OM(r) holds OM(r) holds for the lieutenants in the for the lieutenants in the bot bottom r tom row
Each loyal lieutenant collects n-m-1 n-m-1 identical good values and m bad values. So bad values are voted
n-m-1 > m+r m+r implies n-m-1 > m n-m-1 > m)
m traitors n-m-1 loyal lieutenants values received via OM(r) loyal commander
“OM(r) holds” means each loyal lieutenant receives identical values from every loyal commander
Rajendra, IIIT Sri City
30
Theor heorem em: If n > 3m n > 3m where m is the maximum number of traitors, then OM(m) OM(m) satisfies both IC1 IC1 and IC2 IC2 Proof:
Case 1 ase 1: Commander is loyal The theorem follows from the previous lemma (substitute k = m). Case 2 ase 2: Commander is a traitor We prove it by induction: Base case: m=0 trivial. (Induction hypothesis) Let the theorem hold for m = r We have to show that it holds for m = r+1 too.
Rajendra, IIIT Sri City
31
There are n > 3(r + 1) > 3(r + 1) generals and r + 1 r + 1 traitors Excluding the commander, there are > 3r+2 gener > 3r+2 generals als of which there are r tr r traitors
Since 3r+ 2 > 3r è OM(r) satisfies IC1 and IC2
> 2r+2 > 2r+2 r tr r traitors aitors
Rajendra, IIIT Sri City
32
In OM(r+1), a loyal lieutenant chooses the majority from (1) > 2r+1 values obtained from the loyal lieutenants via OM(r), (2) the r values from the traitors, and (3) the value directly from the commander.
> 2r+2 > 2r+2 r tr r traitors aitors
The set of values collected in part (1) & (3) are the same for all loyal lieutenants - it is the same set of values that these lieutenants received from the commander Also, by the induction hypothesis, in part (2) each loyal lieutenant receives identical values from each traitor. So every loyal lieutenant eventually collects the same set of values
Rajendra, IIIT Sri City
33
Rajendra, IIIT Sri City
34 The real world applications include
è Block Chain Transactions – Bit Coins è Clock Synchronization è PageRank è Opinion Formation è Smart Power Grids è State Estimation è Control of UAVs (and multiple robots / agents in general) è Load Balancing and many other domains è Block Chain
è Distributed Consensus is really important
è Dijkstra’s Algorithm (token rings) è Constructing a Breadth First Tree
è Stay tuned ... More to come up … !!
Rajendra, IIIT Sri City
35
rajendra [DOT] prasath [AT] iiits [DOT] in
è http://www.iiits.ac.in/FacPages/index- rajendra.html OR è http://rajendra.2power3.com 36
Rajendra, IIIT Sri City
and above)
and less than 8.5)
work will also be rewarded)
learning by helping the needy students
37
Rajendra, IIIT Sri City
Rajendra, IIIT Sri City
38