L3: Happens-before recap; Partial orders; Total orders; Lamport clocks; Vector clocks
CSE138 (Distributed Systems) by Lindsey Kuper
What is covered in this lecture?
Recap of happens-before
Partial orders and total orders
Lamport clocks
Vector clocks
Where are the notes for revising happens-before?
Refer Lecture 2 Notes [Link]
Partial Order & Total Order
What is partial order?
A given set S and
a binary relation, often written as ≤, that lets you compare elements of S, and has the following properties
Reflexivity: for all a, b in S then a ≤ a
Anti-symmetry: for all a, b in S, a ≤ b and b ≤ a ⇒ a = b
Transitivity: for all a, b, c in S, a ≤ b and b ≤ c ⇒ a ≤ c
What is the set of events in case of happens-before relation?
Set of all events happened in a particular execution across machines/processes
Is the happens before relation transitive?
Yes, it's there in the definition of happen-before relationship
Is antisymmetry true for happens-before?
In case of happens-before anti-symmetry means an event A happened before B and also event B happened before A then A = B.
So, in this case we can say anti-symmetry is vacuously true
Is reflexivity true for happens-before?
In case of happens-before reflexivity means an event A happens before event A. It doesn't makes sense for an event to happen before itself.
Hence, reflexivity doesn't hold true.
Is happens-before a partial-order?
No, as reflexivity doesn't hold.
But it is referred as irreflexive partial order
In course, it happens-before might be referred as partial order but it actually means irreflexive partial order
What is a classic example of partial order (reflexive)?
Consider set s =
{ a, b, c }
Generate a set S with all possible subset of S =
{ {}, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }
Binary relation is "set containment" denoted by ⊂
All the properties defined above for partial order holds true for (S, ⊂)
[True] Reflexivity: {a} ⊂ {a}
[True] Anti-symmetric: {a, b} ⊂ {b, a} and other way around implies {a, b} = {b, a}
[True] Transitivity: {a} ⊂ {a, b} and {a, b} ⊂ {a, b, c} implies {a} ⊂ {a, b, c}
In above example, there will some elements which are not comparable with the given operator such as {a} and {b}.
What does incomparable pair means?
It means either "a operator b" or "b operator a" is not true
Because of incomparable pairs we have partial order
Why do we care about incomparable pairs within partial order?
These pairs are what we called earlier concurrent events
Concurrent event A and B are denoted by A || B
What is the total order?
Consider a natural number set and "less than equal to" as binary operator
For any two pair of numbers a and b either "a less than equal to b" or "b is less than equal to a" is applicable
Such order is called total order
Lamport Clocks
What is a Lamport clock?
A kind of logical clock
Assigning a number to an event in distributed environment
LC(A) = the Lamport clock of event A, it outputs a natural number
What is clock condition?
If A → B, then LC(A) < LC(B)
Lamport clocks are consistent with potential causality
Lamport clocks do not characterize causality
What do we mean by causality in A → B?
We can certainly say A happened before B
We can potentially say A caused B
What do we mean by "consistent with potential causality"?
A → B ⇒ Logical clock of A < Logical clock of B
Lamport clocks have this property
What do we mean by "characterizing causality"?
Logical clock of A < Logical clock of B ⇒ A → B
Lamport clocks do not have this property
What is Lamport clock algorithm?
Every process keeps a counter, initialized to 0
On every event on a process, that process is going to increment its counter by 1
When sending a message, a process includes its current counter
When receiving a message, a process sets its counter to the MAX(local, received ) + 1
What is an example of assigning LC numbers to events?
Following diagram demonstrates the execution of Lamport clock algorithm
In general, if we know LC(A) < LC(B) does it implies A happens-before B?
No, we can prove this with following example.
On Lamport diagram if you can reach to B from A by following lines then you know A happened before B else not.
What's the point of Lamport clocks? What useful information Lamport clocks provides?
Out of all the possible pairs they help rule out a set of relationships where "Event A has not cause event B"
How Lamport clocks help in exclusion scenario?
P ⇒ Q (P implies Q) also means NOT Q ⇒ NOT P (contrapositive)
A → B ⇒ LC(A) < LC(B), taking contrapositive, NOT (LC(A) < LC(B)) ⇒ NOT (A → B)
It means if LC(A) < LC(B) is not true then we can surely say A has not caused B
By passing just one number (low overhead for a request) this information is derived.
Vector Clocks
What is a Vector Clock?
Its a logical clock
Vector clocks are consistent with potential causality
Vector clocks also characterizes causality
A → B < = > VC(A) < VC(B), A happens-before B if and only if VC(A) is less than VC(B)
What is Vector Clock algorithm?
Every process keeps a vector (array) of natural numbers initialized to zeroes
Length of the vector = Number of processes e.g. for 3 processes vector initial vector will be [0, 0, 0]
On every event (send, receive, and internal), a process increments its own position in its vector clock
When sending a message, a process includes its current vector clock (after the increment from step (2) because sends are events)
When receiving a message, a process will update its vector clock to MAX(local, received) and also increment its own position because receives are events
What does MAX operation mean for vectors?
It performs element-wise maximum
For example, MAX([1, 12, 4], [7, 0, 2]) = [7, 12, 4]
How to interpret single entry such as [5, 0, 0] for [Alice, Bob, Carol] process?
The single needs to at particular person, let's say at Alice
So, we can say Alice has seen 5 events but don't know anything about events a Bob and Carol
In case of Lamport clocks if we will just know a number 5 - 5 events have happened but can't get more information like in Vector clocks
Next lecture will continue with example of Vector clocks.
***