SlideShare a Scribd company logo
1 of 131
Download to read offline
Time, clocks and the ordering of events
Amir H. Payberah
amir@sics.se
Amirkabir University of Technology
(Tehran Polytechnic)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 1 / 67
What is a Distributed System?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 2 / 67
Distributed System
A distributed system is one in which the failure of a computer you
didn’t even know existed can render your own computer unusable.
- Leslie Lamport
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 3 / 67
What is a Distributed System?
A set of nodes, connected by a network, which appear to its users
as a single coherent system.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 4 / 67
Distributed Algorithms
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 5 / 67
Two Generals’ Problem (1/3)
Two generals need to coordinate an attack.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
Two Generals’ Problem (1/3)
Two generals need to coordinate an attack.
• Must agree on time to attack.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
Two Generals’ Problem (1/3)
Two generals need to coordinate an attack.
• Must agree on time to attack.
• They will win only if they attack simultaneously.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
Two Generals’ Problem (1/3)
Two generals need to coordinate an attack.
• Must agree on time to attack.
• They will win only if they attack simultaneously.
• Communicate through messengers.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
Two Generals’ Problem (1/3)
Two generals need to coordinate an attack.
• Must agree on time to attack.
• They will win only if they attack simultaneously.
• Communicate through messengers.
• Messengers may be killed on their way.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
• Solution: let g2 ack receipt of message.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
• Solution: let g2 ack receipt of message.
• Problem: how to ensure g1 received ack?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
• Solution: let g2 ack receipt of message.
• Problem: how to ensure g1 received ack?
• Solution: let g1 ack the receipt of the ack.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
• Solution: let g2 ack receipt of message.
• Problem: how to ensure g1 received ack?
• Solution: let g1 ack the receipt of the ack.
• ...
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (2/3)
Lets try to solve it for general g1 and g2.
g1 sends time of attack to g2.
• Problem: how to ensure g2 received message?
• Solution: let g2 ack receipt of message.
• Problem: how to ensure g1 received ack?
• Solution: let g1 ack the receipt of the ack.
• ...
This problem is impossible to solve!
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
Two Generals’ Problem (3/3)
Applicability to distributed systems:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
Two Generals’ Problem (3/3)
Applicability to distributed systems:
• Two nodes need to agree on a value.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
Two Generals’ Problem (3/3)
Applicability to distributed systems:
• Two nodes need to agree on a value.
• Communicate by messages using an unreliable channel.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
Two Generals’ Problem (3/3)
Applicability to distributed systems:
• Two nodes need to agree on a value.
• Communicate by messages using an unreliable channel.
Agreement is a core problem.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
Distributed Algorithms
Algorithms that are supposed to work in distributed networks or on
multiprocessors.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
Distributed Algorithms
Algorithms that are supposed to work in distributed networks or on
multiprocessors.
Accomplish tasks like:
• Data management
• Resource management
• Consensus
• ...
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
Distributed Algorithms
Algorithms that are supposed to work in distributed networks or on
multiprocessors.
Accomplish tasks like:
• Data management
• Resource management
• Consensus
• ...
Must work in difficult settings:
• Concurrency: uncertainty of timing, order of events and inputs.
• Fault-tolerance: failure and recovery of machines/processors, of
communication channels.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
Correctness of
Distributed Algorithms
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 10 / 67
Correctness
Always expressed in terms of
• Safety and Liveness
• B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
Correctness
Always expressed in terms of
• Safety and Liveness
• B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985
Safety
• Properties that state that nothing bad ever happens.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
Correctness
Always expressed in terms of
• Safety and Liveness
• B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985
Safety
• Properties that state that nothing bad ever happens.
Liveness
• Properties that state that something good eventually happens.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
Correctness Example (1/3)
Correctness of you in this course :)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
Correctness Example (1/3)
Correctness of you in this course :)
You should never fail the exam:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
Correctness Example (1/3)
Correctness of you in this course :)
You should never fail the exam: Safety
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
Correctness Example (1/3)
Correctness of you in this course :)
You should never fail the exam: Safety
You should eventually take the exam:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
Correctness Example (1/3)
Correctness of you in this course :)
You should never fail the exam: Safety
You should eventually take the exam: Liveness
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
Correctness Example (2/3)
Correctness of traffic lights at intersection.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
Correctness Example (2/3)
Correctness of traffic lights at intersection.
Only one direction should have a green
light:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
Correctness Example (2/3)
Correctness of traffic lights at intersection.
Only one direction should have a green
light: Safety
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
Correctness Example (2/3)
Correctness of traffic lights at intersection.
Only one direction should have a green
light: Safety
Every direction should eventually get a
green light:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
Correctness Example (2/3)
Correctness of traffic lights at intersection.
Only one direction should have a green
light: Safety
Every direction should eventually get a
green light: Liveness
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
Correctness Example (3/3)
Correctness of point-to-point message communication.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
Correctness Example (3/3)
Correctness of point-to-point message communication.
A message sent is delivered at most once:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
Correctness Example (3/3)
Correctness of point-to-point message communication.
A message sent is delivered at most once: Safety
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
Correctness Example (3/3)
Correctness of point-to-point message communication.
A message sent is delivered at most once: Safety
A message sent is delivered at least once:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
Correctness Example (3/3)
Correctness of point-to-point message communication.
A message sent is delivered at most once: Safety
A message sent is delivered at least once: Liveness
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
More on Safety and Liveness
Safety
• Often involves the word never, at most, cannot, ...
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 15 / 67
More on Safety and Liveness
Safety
• Often involves the word never, at most, cannot, ...
Liveness
• Often involves the word eventually: some point in future
• Liveness is often just termination
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 15 / 67
Modeling
Distributed Systems
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 16 / 67
What is a Model?
Abstraction of relevant system properties.
Real world is complex, model simplifies it.
Help solving problems.
Help analyze problems/solutions.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 17 / 67
Modeling Distributed Systems
What is a distributed system?
• Bunch of nodes/processes
• Sending messages over a network
• To solve a common goal (algorithm)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 18 / 67
Modeling Distributed Systems
What is a distributed system?
• Bunch of nodes/processes
• Sending messages over a network
• To solve a common goal (algorithm)
How do we model this?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 18 / 67
Modeling a Node
A single node has a bunch of neighbors.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
Modeling a Node
A single node has a bunch of neighbors.
Can send and receive messages.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
Modeling a Node
A single node has a bunch of neighbors.
Can send and receive messages.
Can do local computations.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
Modeling a Node
A single node has a bunch of neighbors.
Can send and receive messages.
Can do local computations.
Like a state machine: a node is in only one state at a time.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
Modeling a Node
A single node has a bunch of neighbors.
Can send and receive messages.
Can do local computations.
Like a state machine: a node is in only one state at a time.
The state of a node: input buffer, output buffer, and other data
relevant to algorithm
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
Single Node Perspective
This is how computers in a distributed system work:
1 Wait for message.
2 When received message, do some local computation, send some
messages.
3 Goto 1
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 20 / 67
Single Node to a Distributed System (1/3)
A configuration is a snapshot of state of all nodes.
• C = (s0, s1, · · · , sn−1) where si is state of process pi.
An initial configuration is a configuration where each si is an initial
state.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 21 / 67
Single Node to a Distributed System (2/3)
The system evolves through events:
• Computation event at node i: comp(i)
• Delivery event of msg m from i to j: del(i, j, m)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 22 / 67
Single Node to a Distributed System (2/3)
The system evolves through events:
• Computation event at node i: comp(i)
• Delivery event of msg m from i to j: del(i, j, m)
An execution is an infinite sequence of
• config0, event1, config1, event2, config2, ...
• config0 is an initial configuration.
• event could be comp or del.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 22 / 67
Single Node to a Distributed System (3/3)
Example execution
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 23 / 67
Synchronous Systems (1/2)
An execution partitioned into non-overlapping rounds.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
Synchronous Systems (1/2)
An execution partitioned into non-overlapping rounds.
Informally, in each round:
• Every process can send a message to each neighbor.
• All messages are delivered.
• Every process computes based on message received.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
Synchronous Systems (1/2)
An execution partitioned into non-overlapping rounds.
Informally, in each round:
• Every process can send a message to each neighbor.
• All messages are delivered.
• Every process computes based on message received.
Formally, rounds consist of:
• Deliver event for every message in all outbufs.
• One computation event on every process.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
Synchronous Systems (2/2)
Time variance is bounded.
Execution: bounded execution speed and time.
Communication: bounded transmission delay.
Clocks: bounded clock drift (and differences in clocks).
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 25 / 67
Asynchronous Systems
Time variance is not bounded.
Execution: different steps can have varying duration.
Communication: transmission delays vary widely.
Clocks: arbitrary clock drift.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 26 / 67
Time, Clock, and
Order of Events
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 27 / 67
Time
Global time
• Astronomical time (based on earth’s rotation)
• International Atomic Time (IAT)
• Coordinated Universal Time (UTC)
Local time
• Not synchronized to a global source
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 28 / 67
Computer Clocks
Computer clocks
• Crystal oscillates at known frequency
• Oscillations cause timer interrupts
• Timer interrupts update clock
Clock skew
• Crystals in different computers run at slightly different rates
• Clocks get out of sync
• Skew: instantaneous difference
• Drift: rate of change of skew
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 29 / 67
Synchronizing Computer Clocks
Internal synchronization
• Clocks synchronize locally
• Only synchronized with each other
• Berkeley algorithm
Time server
• Server that has the correct time
• Server that calculates the correct time
• Network Time Protocol (NTP)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 30 / 67
Logical Clock
Event ordering is more important than physical time.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
Logical Clock
Event ordering is more important than physical time.
Events (e.g., state changes) in a single process are ordered.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
Logical Clock
Event ordering is more important than physical time.
Events (e.g., state changes) in a single process are ordered.
Processes need to agree on ordering of causally related events (e.g.,
message send and receive).
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
Causal Order
→: causal order relation.
• Also called Leslie Lamport’s happened before relation.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
Causal Order
→: causal order relation.
• Also called Leslie Lamport’s happened before relation.
The relation → on the events of an execution is defined as follows:
• If a occurs before b on the same process, then a → b.
• If a produces (comp) m and b delivers m, then a → b.
• If a delivers m and b consumes (comp) m, then a → b.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
Causal Order
→: causal order relation.
• Also called Leslie Lamport’s happened before relation.
The relation → on the events of an execution is defined as follows:
• If a occurs before b on the same process, then a → b.
• If a produces (comp) m and b delivers m, then a → b.
• If a delivers m and b consumes (comp) m, then a → b.
Transitivity: if a → b and b → c, then a → c.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
Causal Order
→: causal order relation.
• Also called Leslie Lamport’s happened before relation.
The relation → on the events of an execution is defined as follows:
• If a occurs before b on the same process, then a → b.
• If a produces (comp) m and b delivers m, then a → b.
• If a delivers m and b consumes (comp) m, then a → b.
Transitivity: if a → b and b → c, then a → c.
concurrent events (a||b): if a → b and b → a.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
Causal Order Example
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 33 / 67
Causal Order Example
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 34 / 67
Equivalence of Executions
If two executions F and E have the same collection of events, and
their causal order is preserved, F and E are said to be similar exe-
cutions.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 35 / 67
Equivalence of Executions
If two executions F and E have the same collection of events, and
their causal order is preserved, F and E are said to be similar exe-
cutions.
F and E could have different permutation of events as long as
causality is preserved.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 35 / 67
Example of Similar Executions
Same color ∼ Causally related
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 36 / 67
So causality is all that matters ...
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 37 / 67
So causality is all that matters ...
... how to locally tell if two events are causally related?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 37 / 67
Lamport Clocks
Each process pi has a local logical clock ti.
• Initially ti = 0
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
Lamport Clocks
Each process pi has a local logical clock ti.
• Initially ti = 0
Before timestamping a local event pi executes ti := ti + 1.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
Lamport Clocks
Each process pi has a local logical clock ti.
• Initially ti = 0
Before timestamping a local event pi executes ti := ti + 1.
Whenever a message m is sent from pi to pj:
• pi executes ti := ti + 1 and sends ti with m.
• pj receives ti with m and executes tj := max(tj, ti) + 1.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
Example of Lamport Logical Clock
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 39 / 67
Lamport Clocks Properties
a → b implies t(a) < t(b), where t(a) is Lamport clock of event a.
t(a) < t(b) does not necessarily imply a → b
t(E31) < t(E13), but E31 → E13
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 40 / 67
Shortcoming of Lamport Clocks
Main shortcoming of Lamport’s clocks:
• t(a) < t(b) does not necessarily imply a → b
• We cannot deduce causal dependencies from time stamps.
Why?
• Clocks advance independently or via messages.
• There is no history as to where advances come from.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 41 / 67
Vector Clocks
At each process, maintain a clock for every other process.
• Each clock Vi is a vector of size N.
• Vi[j] contains process pis knowledge about process pj’s clock.
• Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
Vector Clocks
At each process, maintain a clock for every other process.
• Each clock Vi is a vector of size N.
• Vi[j] contains process pis knowledge about process pj’s clock.
• Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}.
Before pi timestamps an event: Vi[i] := Vi[i] + 1.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
Vector Clocks
At each process, maintain a clock for every other process.
• Each clock Vi is a vector of size N.
• Vi[j] contains process pis knowledge about process pj’s clock.
• Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}.
Before pi timestamps an event: Vi[i] := Vi[i] + 1.
Whenever a message m is sent from pi to pj:
• pi executes Vi[i] := Vi[i] + 1 and sends Vi with m.
• pj receives Vi with m and merges the vector clocks Vi and Vj:
Vj[k] =
max(Vj[k], Vi[k]) + 1 if j = k
max(Vj[k], Vi[k]) otherwise
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
Example of Vector Clock
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 43 / 67
Comparing Vector Clocks
V = V iff V [i] = V [i] for i ∈ {1, · · · , N}
V ≤ V iff V [i] ≤ V [i] for i ∈ {1, · · · , N}
V ||V iff V ≤ V ∧ V ≤ V
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 44 / 67
Vector Clocks Properties
a → b implies V (a) < V (b)
V (a) < V (b) implies a → b
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 45 / 67
Logical Clock vs. Vector Clock
Logical clock
• If a → b then t(a) < t(b)
Vector clock
• If a → b then V (a) < V (b)
• If V (a) < V (b) then a → b
• Sending extra information: vector with size N, for N processes.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 46 / 67
Global State
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 47 / 67
Global State
Determining global properties
Distributed checkpoint
• What is a correct state of the system to save?
Distributed garbage collection
• Do any references exist to a given object?
...
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 48 / 67
Local History
N processes pi, i ∈ {1, · · · , N}
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
Local History
N processes pi, i ∈ {1, · · · , N}
The local history of process pi is a sequence of events
hi = e0
i , e1
i , · · ·
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
Local History
N processes pi, i ∈ {1, · · · , N}
The local history of process pi is a sequence of events
hi = e0
i , e1
i , · · ·
May be finite or infinite.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
Local History
N processes pi, i ∈ {1, · · · , N}
The local history of process pi is a sequence of events
hi = e0
i , e1
i , · · ·
May be finite or infinite.
Each event ej
i is either a local event or a communication event.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
Local and Global State
sk
i denotes the local state of process pi after execution of event ek
i .
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
Local and Global State
sk
i denotes the local state of process pi after execution of event ek
i .
The local state sk
i records all events included in the history hk
i .
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
Local and Global State
sk
i denotes the local state of process pi after execution of event ek
i .
The local state sk
i records all events included in the history hk
i .
The global state, S, of a distributed computation is an N-tuple of
local states (s1, s2, · · · , sN ), one for each process.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
Cuts
hci
i is history of pi up to and including event eci
i , called partial
history.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
Cuts
hci
i is history of pi up to and including event eci
i , called partial
history.
A cut, C, of a distributed computation is the union of N partial
histories, one for each process: C = N
i=1 hci
i
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
Cuts
hci
i is history of pi up to and including event eci
i , called partial
history.
A cut, C, of a distributed computation is the union of N partial
histories, one for each process: C = N
i=1 hci
i
Each cut C has a corresponding global state: S = (s1, s2, · · · , sN ).
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
Consistent Cuts (1/2)
A cut C is consistent, if for all events e and e
(e ∈ C) ∧ (e → e ) ⇒ e ∈ C
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 52 / 67
Consistent Cuts (1/2)
A cut C is consistent, if for all events e and e
(e ∈ C) ∧ (e → e ) ⇒ e ∈ C
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 52 / 67
Consistent Cuts (2/2)
It can be written as two following conditions:
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
Consistent Cuts (2/2)
It can be written as two following conditions:
• Condition 1: any message that is sent by a process before recording
its snapshot, must be recorded in the cut.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
Consistent Cuts (2/2)
It can be written as two following conditions:
• Condition 1: any message that is sent by a process before recording
its snapshot, must be recorded in the cut.
• Condition 2: any message that is sent by a process after recording
its snapshot, must not be recorded in the cut.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
Consistent Cuts (2/2)
It can be written as two following conditions:
• Condition 1: any message that is sent by a process before recording
its snapshot, must be recorded in the cut.
• Condition 2: any message that is sent by a process after recording
its snapshot, must not be recorded in the cut.
A global state is consistent if it corresponds to a consistent cut.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
Possible Solutions
Coordinated blocking
Coordinated non-blocking
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 54 / 67
Coordinated Blocking
At barrier, all processes take their checkpoints.
Bulk-Synchronous Parallel (BSP)
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 55 / 67
Coordinated Non-Blocking
Processes must be coordinated, but do we really need to block?
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 56 / 67
Coordinated Non-Blocking
Processes must be coordinated, but do we really need to block?
Chandy and Lamport’s snapshot
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 56 / 67
Chandy and Lamport’s Snapshot
Determines a consistent global state.
Takes care of messages that are in transit.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 57 / 67
Model of a Distributed System
Process: one process initiates taking of global snapshot
Channels: directed, FIFO, reliable
Process graph: fixed topology, strongly connected component
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 58 / 67
Chandy and Lamport’s Snapshot Algorithm (1/3)
The algorithm can be initiated by any process by executing the
Marker Sending Rule, by which it records its local state and sends
a marker on each outgoing channel.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
Chandy and Lamport’s Snapshot Algorithm (1/3)
The algorithm can be initiated by any process by executing the
Marker Sending Rule, by which it records its local state and sends
a marker on each outgoing channel.
A process executes the Marker Receiving Rule on receiving a marker.
If the process has not yet recorded its local state, it records the state
of the channel on which the marker is received as empty and executes
the Marker Sending Rule to record its local state.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
Chandy and Lamport’s Snapshot Algorithm (1/3)
The algorithm can be initiated by any process by executing the
Marker Sending Rule, by which it records its local state and sends
a marker on each outgoing channel.
A process executes the Marker Receiving Rule on receiving a marker.
If the process has not yet recorded its local state, it records the state
of the channel on which the marker is received as empty and executes
the Marker Sending Rule to record its local state.
The algorithm terminates after each process has received a marker
on all of its incoming channels.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
Chandy and Lamport’s Snapshot Algorithm (1/3)
The algorithm can be initiated by any process by executing the
Marker Sending Rule, by which it records its local state and sends
a marker on each outgoing channel.
A process executes the Marker Receiving Rule on receiving a marker.
If the process has not yet recorded its local state, it records the state
of the channel on which the marker is received as empty and executes
the Marker Sending Rule to record its local state.
The algorithm terminates after each process has received a marker
on all of its incoming channels.
All the local snapshots get disseminated to all other processes and
all the processes can determine the global state.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
Chandy and Lamport’s Snapshot Algorithm (2/3)
Marker Sending Rule for process pi:
• Process pi records its state.
• For each outgoing channel c on which a marker has not been sent,
pi sends a marker along c before pi sends further messages along c.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 60 / 67
Chandy and Lamport’s Snapshot Algorithm (3/3)
Marker Receiving Rule for process pj on receiving a marker along
channel c:
• If pj has not recorded its state, it records the state of channel c as
the empty set, and follows the Marker Sending Rule.
• Otherwise, it records the state of c as the set of messages received
along c after pj’s state was recorded and before pj received the
marker along c.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 61 / 67
Correctness of the Algorithm (1/2)
Condition 1: any message that is sent by a process before recording
its snapshot, must be recorded in the cut.
When a process pj receives message mij from pi that precedes the
marker on channel cij, it acts as follows: if process pj has not
taken its snapshot yet, then it includes mij in its recorded snapshot.
Otherwise, it records mij in the state of the channel cij. Thus,
condition Condition 1 is satisfied.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 62 / 67
Correctness of the Algorithm (2/2)
Condition 2: any message that is sent by a process after recording
its snapshot, must not be recorded in the cut.
Due to FIFO property of channels, it follows that no message sent
after the marker on that channel is recorded in the channel state.
Thus, condition Condition 2 is satisfied.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 63 / 67
Summary
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 64 / 67
Summary
Correctness of distributed algorithms: safety + liveness
Casual order
Logical clock and Vector clock
Global state: Chandy and Lamport’s algorithm
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 65 / 67
References:
L. Lamport, Time, clocks, and the ordering of events in a distributed
system. ACM Communications, 1978
K.M. Chandy and L. Lamport, Distributed snapshots: determining
global states of distributed systems. ACM Transactions on Com-
puter Systems, 1985.
B. Alpern and F.B. Schneider, Defining Liveness. Technical Report,
1984.
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 66 / 67
Questions?
Acknowledgements
Some slides were derived from Seif Haridi slides (KTH University).
Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 67 / 67

More Related Content

What's hot

System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed systemishapadhy
 
Distributed shared memory shyam soni
Distributed shared memory shyam soniDistributed shared memory shyam soni
Distributed shared memory shyam soniShyam Soni
 
Parallel programming model
Parallel programming modelParallel programming model
Parallel programming modeleasy notes
 
01 - Introduction to Distributed Systems
01 - Introduction to Distributed Systems01 - Introduction to Distributed Systems
01 - Introduction to Distributed SystemsDilum Bandara
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
 
message passing vs shared memory
message passing vs shared memorymessage passing vs shared memory
message passing vs shared memoryHamza Zahid
 
Diffie hellman key exchange algorithm
Diffie hellman key exchange algorithmDiffie hellman key exchange algorithm
Diffie hellman key exchange algorithmSunita Kharayat
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLjunnubabu
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)Haris Ahmed
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems Haitham Ahmed
 
Diffie Hellman Key Exchange
Diffie Hellman Key ExchangeDiffie Hellman Key Exchange
Diffie Hellman Key ExchangeSAURABHDHAGE6
 
Multicast Routing Protocols
Multicast Routing ProtocolsMulticast Routing Protocols
Multicast Routing ProtocolsRam Dutt Shukla
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDHIVYADEVAKI
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computingVajira Thambawita
 

What's hot (20)

System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed system
 
Distributed shared memory shyam soni
Distributed shared memory shyam soniDistributed shared memory shyam soni
Distributed shared memory shyam soni
 
Parallel programming model
Parallel programming modelParallel programming model
Parallel programming model
 
Distributed Systems Naming
Distributed Systems NamingDistributed Systems Naming
Distributed Systems Naming
 
01 - Introduction to Distributed Systems
01 - Introduction to Distributed Systems01 - Introduction to Distributed Systems
01 - Introduction to Distributed Systems
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
The CAP Theorem
The CAP Theorem The CAP Theorem
The CAP Theorem
 
Distributed Coordination-Based Systems
Distributed Coordination-Based SystemsDistributed Coordination-Based Systems
Distributed Coordination-Based Systems
 
message passing vs shared memory
message passing vs shared memorymessage passing vs shared memory
message passing vs shared memory
 
Wormhole attack
Wormhole attackWormhole attack
Wormhole attack
 
Diffie hellman key exchange algorithm
Diffie hellman key exchange algorithmDiffie hellman key exchange algorithm
Diffie hellman key exchange algorithm
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROL
 
models of distributed computing
models of distributed computingmodels of distributed computing
models of distributed computing
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems
 
Diffie Hellman Key Exchange
Diffie Hellman Key ExchangeDiffie Hellman Key Exchange
Diffie Hellman Key Exchange
 
Multicast Routing Protocols
Multicast Routing ProtocolsMulticast Routing Protocols
Multicast Routing Protocols
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computing
 

Viewers also liked

GoshawkDB: Making Time with Vector Clocks
GoshawkDB: Making Time with Vector ClocksGoshawkDB: Making Time with Vector Clocks
GoshawkDB: Making Time with Vector ClocksC4Media
 
CouchDB Day NYC 2017: Introduction to CouchDB 2.0
CouchDB Day NYC 2017: Introduction to CouchDB 2.0CouchDB Day NYC 2017: Introduction to CouchDB 2.0
CouchDB Day NYC 2017: Introduction to CouchDB 2.0IBM Cloud Data Services
 
Distributed Consensus: Making the Impossible Possible
Distributed Consensus: Making the Impossible PossibleDistributed Consensus: Making the Impossible Possible
Distributed Consensus: Making the Impossible PossibleC4Media
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rulesOleg Tsal-Tsalko
 
Block Chains and Consensus Algos
Block Chains and Consensus AlgosBlock Chains and Consensus Algos
Block Chains and Consensus AlgosJerry David Chan
 
Distributed Systems Theory for Mere Mortals
Distributed Systems Theory for Mere MortalsDistributed Systems Theory for Mere Mortals
Distributed Systems Theory for Mere MortalsEnsar Basri Kahveci
 
RESIGN REPUBLIC: An education technology platform by Ali. R. Khan
RESIGN REPUBLIC: An education technology platform by Ali. R. KhanRESIGN REPUBLIC: An education technology platform by Ali. R. Khan
RESIGN REPUBLIC: An education technology platform by Ali. R. KhanAli Rahman Khan
 
Replication and Synchronization Algorithms for Distributed Databases - Lena W...
Replication and Synchronization Algorithms for Distributed Databases - Lena W...Replication and Synchronization Algorithms for Distributed Databases - Lena W...
Replication and Synchronization Algorithms for Distributed Databases - Lena W...distributed matters
 
Distributed algorithms for big data @ GeeCon
Distributed algorithms for big data @ GeeConDistributed algorithms for big data @ GeeCon
Distributed algorithms for big data @ GeeConDuyhai Doan
 
Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Sri Prasanna
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems SHATHAN
 
Clock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsClock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsZbigniew Jerzak
 
Ciszewski internet credentials and case study eng
Ciszewski internet credentials and case study engCiszewski internet credentials and case study eng
Ciszewski internet credentials and case study engCiszewski MSL
 
Paisajes De Serge Motylev
Paisajes De Serge MotylevPaisajes De Serge Motylev
Paisajes De Serge Motylevalfcoltrane
 
OW2con'14 - Keynote from Microsoft
OW2con'14 - Keynote from MicrosoftOW2con'14 - Keynote from Microsoft
OW2con'14 - Keynote from MicrosoftOW2
 
What Do You Feel 2008
What Do You Feel 2008What Do You Feel 2008
What Do You Feel 2008renee22220
 
Petals BPM & the Cloud, OW2con11, Nov 24-25, Paris
Petals BPM & the Cloud, OW2con11, Nov 24-25, ParisPetals BPM & the Cloud, OW2con11, Nov 24-25, Paris
Petals BPM & the Cloud, OW2con11, Nov 24-25, ParisOW2
 

Viewers also liked (20)

GoshawkDB: Making Time with Vector Clocks
GoshawkDB: Making Time with Vector ClocksGoshawkDB: Making Time with Vector Clocks
GoshawkDB: Making Time with Vector Clocks
 
CouchDB Day NYC 2017: Introduction to CouchDB 2.0
CouchDB Day NYC 2017: Introduction to CouchDB 2.0CouchDB Day NYC 2017: Introduction to CouchDB 2.0
CouchDB Day NYC 2017: Introduction to CouchDB 2.0
 
Blockchain Hub Seminar
Blockchain Hub SeminarBlockchain Hub Seminar
Blockchain Hub Seminar
 
Distributed Consensus: Making the Impossible Possible
Distributed Consensus: Making the Impossible PossibleDistributed Consensus: Making the Impossible Possible
Distributed Consensus: Making the Impossible Possible
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rules
 
Block Chains and Consensus Algos
Block Chains and Consensus AlgosBlock Chains and Consensus Algos
Block Chains and Consensus Algos
 
Distributed Systems Theory for Mere Mortals
Distributed Systems Theory for Mere MortalsDistributed Systems Theory for Mere Mortals
Distributed Systems Theory for Mere Mortals
 
RESIGN REPUBLIC: An education technology platform by Ali. R. Khan
RESIGN REPUBLIC: An education technology platform by Ali. R. KhanRESIGN REPUBLIC: An education technology platform by Ali. R. Khan
RESIGN REPUBLIC: An education technology platform by Ali. R. Khan
 
Replication and Synchronization Algorithms for Distributed Databases - Lena W...
Replication and Synchronization Algorithms for Distributed Databases - Lena W...Replication and Synchronization Algorithms for Distributed Databases - Lena W...
Replication and Synchronization Algorithms for Distributed Databases - Lena W...
 
Distributed algorithms for big data @ GeeCon
Distributed algorithms for big data @ GeeConDistributed algorithms for big data @ GeeCon
Distributed algorithms for big data @ GeeCon
 
Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)Logical Clocks (Distributed computing)
Logical Clocks (Distributed computing)
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
 
Clock Synchronization in Distributed Systems
Clock Synchronization in Distributed SystemsClock Synchronization in Distributed Systems
Clock Synchronization in Distributed Systems
 
Ciszewski internet credentials and case study eng
Ciszewski internet credentials and case study engCiszewski internet credentials and case study eng
Ciszewski internet credentials and case study eng
 
Paisajes De Serge Motylev
Paisajes De Serge MotylevPaisajes De Serge Motylev
Paisajes De Serge Motylev
 
OW2con'14 - Keynote from Microsoft
OW2con'14 - Keynote from MicrosoftOW2con'14 - Keynote from Microsoft
OW2con'14 - Keynote from Microsoft
 
What Do You Feel 2008
What Do You Feel 2008What Do You Feel 2008
What Do You Feel 2008
 
Tech talk: PHP
Tech talk: PHPTech talk: PHP
Tech talk: PHP
 
Petals BPM & the Cloud, OW2con11, Nov 24-25, Paris
Petals BPM & the Cloud, OW2con11, Nov 24-25, ParisPetals BPM & the Cloud, OW2con11, Nov 24-25, Paris
Petals BPM & the Cloud, OW2con11, Nov 24-25, Paris
 
Hello, social m edia
Hello, social m ediaHello, social m edia
Hello, social m edia
 

Similar to Time, clocks and the ordering of events

Gossip-based algorithms
Gossip-based algorithmsGossip-based algorithms
Gossip-based algorithmsAmir Payberah
 
Process Synchronization - Part2
Process Synchronization -  Part2Process Synchronization -  Part2
Process Synchronization - Part2Amir Payberah
 
Graph processing - Pregel
Graph processing - PregelGraph processing - Pregel
Graph processing - PregelAmir Payberah
 
Process Management - Part2
Process Management - Part2Process Management - Part2
Process Management - Part2Amir Payberah
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2Amir Payberah
 
Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Amir Payberah
 
Introduction to cloud computing and big data - part2
Introduction to cloud computing and big data - part2Introduction to cloud computing and big data - part2
Introduction to cloud computing and big data - part2Amir Payberah
 
Engineering physics
Engineering physicsEngineering physics
Engineering physicssakhi pathak
 

Similar to Time, clocks and the ordering of events (12)

Paxos
PaxosPaxos
Paxos
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Mesos and YARN
Mesos and YARNMesos and YARN
Mesos and YARN
 
Gossip-based algorithms
Gossip-based algorithmsGossip-based algorithms
Gossip-based algorithms
 
Process Synchronization - Part2
Process Synchronization -  Part2Process Synchronization -  Part2
Process Synchronization - Part2
 
Graph processing - Pregel
Graph processing - PregelGraph processing - Pregel
Graph processing - Pregel
 
Process Management - Part2
Process Management - Part2Process Management - Part2
Process Management - Part2
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2
 
Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1Introduction to Operating Systems - Part1
Introduction to Operating Systems - Part1
 
Introduction to cloud computing and big data - part2
Introduction to cloud computing and big data - part2Introduction to cloud computing and big data - part2
Introduction to cloud computing and big data - part2
 
PERT
PERTPERT
PERT
 
Engineering physics
Engineering physicsEngineering physics
Engineering physics
 

More from Amir Payberah

P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution NetworkAmir Payberah
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing FrameworksAmir Payberah
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformAmir Payberah
 
The Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformThe Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformAmir Payberah
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module ProgrammingAmir Payberah
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2Amir Payberah
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1Amir Payberah
 
File System Interface
File System InterfaceFile System Interface
File System InterfaceAmir Payberah
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1Amir Payberah
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2Amir Payberah
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1Amir Payberah
 
Process Synchronization - Part1
Process Synchronization -  Part1Process Synchronization -  Part1
Process Synchronization - Part1Amir Payberah
 

More from Amir Payberah (20)

P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution Network
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing Frameworks
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics Platform
 
The Spark Big Data Analytics Platform
The Spark Big Data Analytics PlatformThe Spark Big Data Analytics Platform
The Spark Big Data Analytics Platform
 
Security
SecuritySecurity
Security
 
Protection
ProtectionProtection
Protection
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module Programming
 
IO Systems
IO SystemsIO Systems
IO Systems
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 
Storage
StorageStorage
Storage
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1
 
Main Memory - Part2
Main Memory - Part2Main Memory - Part2
Main Memory - Part2
 
Main Memory - Part1
Main Memory - Part1Main Memory - Part1
Main Memory - Part1
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1
 
Process Synchronization - Part1
Process Synchronization -  Part1Process Synchronization -  Part1
Process Synchronization - Part1
 
Threads
ThreadsThreads
Threads
 

Recently uploaded

Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsHajira Mahmood
 
Welcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayWelcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayZachary Labe
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfSwapnil Therkar
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...lizamodels9
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Masticationvidulajaib
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |aasikanpl
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024AyushiRastogi48
 
Gas_Laws_powerpoint_notes.ppt for grade 10
Gas_Laws_powerpoint_notes.ppt for grade 10Gas_Laws_powerpoint_notes.ppt for grade 10
Gas_Laws_powerpoint_notes.ppt for grade 10ROLANARIBATO3
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxNandakishor Bhaurao Deshmukh
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsssuserddc89b
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 

Recently uploaded (20)

Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutions
 
Welcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work DayWelcome to GFDL for Take Your Child To Work Day
Welcome to GFDL for Take Your Child To Work Day
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Mastication
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
 
Volatile Oils Pharmacognosy And Phytochemistry -I
Volatile Oils Pharmacognosy And Phytochemistry -IVolatile Oils Pharmacognosy And Phytochemistry -I
Volatile Oils Pharmacognosy And Phytochemistry -I
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024
 
Gas_Laws_powerpoint_notes.ppt for grade 10
Gas_Laws_powerpoint_notes.ppt for grade 10Gas_Laws_powerpoint_notes.ppt for grade 10
Gas_Laws_powerpoint_notes.ppt for grade 10
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physics
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 

Time, clocks and the ordering of events

  • 1. Time, clocks and the ordering of events Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 1 / 67
  • 2. What is a Distributed System? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 2 / 67
  • 3. Distributed System A distributed system is one in which the failure of a computer you didn’t even know existed can render your own computer unusable. - Leslie Lamport Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 3 / 67
  • 4. What is a Distributed System? A set of nodes, connected by a network, which appear to its users as a single coherent system. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 4 / 67
  • 5. Distributed Algorithms Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 5 / 67
  • 6. Two Generals’ Problem (1/3) Two generals need to coordinate an attack. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
  • 7. Two Generals’ Problem (1/3) Two generals need to coordinate an attack. • Must agree on time to attack. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
  • 8. Two Generals’ Problem (1/3) Two generals need to coordinate an attack. • Must agree on time to attack. • They will win only if they attack simultaneously. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
  • 9. Two Generals’ Problem (1/3) Two generals need to coordinate an attack. • Must agree on time to attack. • They will win only if they attack simultaneously. • Communicate through messengers. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
  • 10. Two Generals’ Problem (1/3) Two generals need to coordinate an attack. • Must agree on time to attack. • They will win only if they attack simultaneously. • Communicate through messengers. • Messengers may be killed on their way. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 6 / 67
  • 11. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 12. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 13. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? • Solution: let g2 ack receipt of message. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 14. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? • Solution: let g2 ack receipt of message. • Problem: how to ensure g1 received ack? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 15. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? • Solution: let g2 ack receipt of message. • Problem: how to ensure g1 received ack? • Solution: let g1 ack the receipt of the ack. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 16. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? • Solution: let g2 ack receipt of message. • Problem: how to ensure g1 received ack? • Solution: let g1 ack the receipt of the ack. • ... Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 17. Two Generals’ Problem (2/3) Lets try to solve it for general g1 and g2. g1 sends time of attack to g2. • Problem: how to ensure g2 received message? • Solution: let g2 ack receipt of message. • Problem: how to ensure g1 received ack? • Solution: let g1 ack the receipt of the ack. • ... This problem is impossible to solve! Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 7 / 67
  • 18. Two Generals’ Problem (3/3) Applicability to distributed systems: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
  • 19. Two Generals’ Problem (3/3) Applicability to distributed systems: • Two nodes need to agree on a value. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
  • 20. Two Generals’ Problem (3/3) Applicability to distributed systems: • Two nodes need to agree on a value. • Communicate by messages using an unreliable channel. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
  • 21. Two Generals’ Problem (3/3) Applicability to distributed systems: • Two nodes need to agree on a value. • Communicate by messages using an unreliable channel. Agreement is a core problem. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 8 / 67
  • 22. Distributed Algorithms Algorithms that are supposed to work in distributed networks or on multiprocessors. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
  • 23. Distributed Algorithms Algorithms that are supposed to work in distributed networks or on multiprocessors. Accomplish tasks like: • Data management • Resource management • Consensus • ... Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
  • 24. Distributed Algorithms Algorithms that are supposed to work in distributed networks or on multiprocessors. Accomplish tasks like: • Data management • Resource management • Consensus • ... Must work in difficult settings: • Concurrency: uncertainty of timing, order of events and inputs. • Fault-tolerance: failure and recovery of machines/processors, of communication channels. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 9 / 67
  • 25. Correctness of Distributed Algorithms Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 10 / 67
  • 26. Correctness Always expressed in terms of • Safety and Liveness • B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985 Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
  • 27. Correctness Always expressed in terms of • Safety and Liveness • B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985 Safety • Properties that state that nothing bad ever happens. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
  • 28. Correctness Always expressed in terms of • Safety and Liveness • B. Alpern and F.B. Schneider, Defining Liveness, Technical Report, 1985 Safety • Properties that state that nothing bad ever happens. Liveness • Properties that state that something good eventually happens. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 11 / 67
  • 29. Correctness Example (1/3) Correctness of you in this course :) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
  • 30. Correctness Example (1/3) Correctness of you in this course :) You should never fail the exam: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
  • 31. Correctness Example (1/3) Correctness of you in this course :) You should never fail the exam: Safety Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
  • 32. Correctness Example (1/3) Correctness of you in this course :) You should never fail the exam: Safety You should eventually take the exam: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
  • 33. Correctness Example (1/3) Correctness of you in this course :) You should never fail the exam: Safety You should eventually take the exam: Liveness Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 12 / 67
  • 34. Correctness Example (2/3) Correctness of traffic lights at intersection. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
  • 35. Correctness Example (2/3) Correctness of traffic lights at intersection. Only one direction should have a green light: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
  • 36. Correctness Example (2/3) Correctness of traffic lights at intersection. Only one direction should have a green light: Safety Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
  • 37. Correctness Example (2/3) Correctness of traffic lights at intersection. Only one direction should have a green light: Safety Every direction should eventually get a green light: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
  • 38. Correctness Example (2/3) Correctness of traffic lights at intersection. Only one direction should have a green light: Safety Every direction should eventually get a green light: Liveness Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 13 / 67
  • 39. Correctness Example (3/3) Correctness of point-to-point message communication. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
  • 40. Correctness Example (3/3) Correctness of point-to-point message communication. A message sent is delivered at most once: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
  • 41. Correctness Example (3/3) Correctness of point-to-point message communication. A message sent is delivered at most once: Safety Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
  • 42. Correctness Example (3/3) Correctness of point-to-point message communication. A message sent is delivered at most once: Safety A message sent is delivered at least once: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
  • 43. Correctness Example (3/3) Correctness of point-to-point message communication. A message sent is delivered at most once: Safety A message sent is delivered at least once: Liveness Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 14 / 67
  • 44. More on Safety and Liveness Safety • Often involves the word never, at most, cannot, ... Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 15 / 67
  • 45. More on Safety and Liveness Safety • Often involves the word never, at most, cannot, ... Liveness • Often involves the word eventually: some point in future • Liveness is often just termination Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 15 / 67
  • 46. Modeling Distributed Systems Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 16 / 67
  • 47. What is a Model? Abstraction of relevant system properties. Real world is complex, model simplifies it. Help solving problems. Help analyze problems/solutions. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 17 / 67
  • 48. Modeling Distributed Systems What is a distributed system? • Bunch of nodes/processes • Sending messages over a network • To solve a common goal (algorithm) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 18 / 67
  • 49. Modeling Distributed Systems What is a distributed system? • Bunch of nodes/processes • Sending messages over a network • To solve a common goal (algorithm) How do we model this? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 18 / 67
  • 50. Modeling a Node A single node has a bunch of neighbors. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
  • 51. Modeling a Node A single node has a bunch of neighbors. Can send and receive messages. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
  • 52. Modeling a Node A single node has a bunch of neighbors. Can send and receive messages. Can do local computations. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
  • 53. Modeling a Node A single node has a bunch of neighbors. Can send and receive messages. Can do local computations. Like a state machine: a node is in only one state at a time. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
  • 54. Modeling a Node A single node has a bunch of neighbors. Can send and receive messages. Can do local computations. Like a state machine: a node is in only one state at a time. The state of a node: input buffer, output buffer, and other data relevant to algorithm Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 19 / 67
  • 55. Single Node Perspective This is how computers in a distributed system work: 1 Wait for message. 2 When received message, do some local computation, send some messages. 3 Goto 1 Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 20 / 67
  • 56. Single Node to a Distributed System (1/3) A configuration is a snapshot of state of all nodes. • C = (s0, s1, · · · , sn−1) where si is state of process pi. An initial configuration is a configuration where each si is an initial state. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 21 / 67
  • 57. Single Node to a Distributed System (2/3) The system evolves through events: • Computation event at node i: comp(i) • Delivery event of msg m from i to j: del(i, j, m) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 22 / 67
  • 58. Single Node to a Distributed System (2/3) The system evolves through events: • Computation event at node i: comp(i) • Delivery event of msg m from i to j: del(i, j, m) An execution is an infinite sequence of • config0, event1, config1, event2, config2, ... • config0 is an initial configuration. • event could be comp or del. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 22 / 67
  • 59. Single Node to a Distributed System (3/3) Example execution Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 23 / 67
  • 60. Synchronous Systems (1/2) An execution partitioned into non-overlapping rounds. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
  • 61. Synchronous Systems (1/2) An execution partitioned into non-overlapping rounds. Informally, in each round: • Every process can send a message to each neighbor. • All messages are delivered. • Every process computes based on message received. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
  • 62. Synchronous Systems (1/2) An execution partitioned into non-overlapping rounds. Informally, in each round: • Every process can send a message to each neighbor. • All messages are delivered. • Every process computes based on message received. Formally, rounds consist of: • Deliver event for every message in all outbufs. • One computation event on every process. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 24 / 67
  • 63. Synchronous Systems (2/2) Time variance is bounded. Execution: bounded execution speed and time. Communication: bounded transmission delay. Clocks: bounded clock drift (and differences in clocks). Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 25 / 67
  • 64. Asynchronous Systems Time variance is not bounded. Execution: different steps can have varying duration. Communication: transmission delays vary widely. Clocks: arbitrary clock drift. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 26 / 67
  • 65. Time, Clock, and Order of Events Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 27 / 67
  • 66. Time Global time • Astronomical time (based on earth’s rotation) • International Atomic Time (IAT) • Coordinated Universal Time (UTC) Local time • Not synchronized to a global source Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 28 / 67
  • 67. Computer Clocks Computer clocks • Crystal oscillates at known frequency • Oscillations cause timer interrupts • Timer interrupts update clock Clock skew • Crystals in different computers run at slightly different rates • Clocks get out of sync • Skew: instantaneous difference • Drift: rate of change of skew Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 29 / 67
  • 68. Synchronizing Computer Clocks Internal synchronization • Clocks synchronize locally • Only synchronized with each other • Berkeley algorithm Time server • Server that has the correct time • Server that calculates the correct time • Network Time Protocol (NTP) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 30 / 67
  • 69. Logical Clock Event ordering is more important than physical time. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
  • 70. Logical Clock Event ordering is more important than physical time. Events (e.g., state changes) in a single process are ordered. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
  • 71. Logical Clock Event ordering is more important than physical time. Events (e.g., state changes) in a single process are ordered. Processes need to agree on ordering of causally related events (e.g., message send and receive). Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 31 / 67
  • 72. Causal Order →: causal order relation. • Also called Leslie Lamport’s happened before relation. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
  • 73. Causal Order →: causal order relation. • Also called Leslie Lamport’s happened before relation. The relation → on the events of an execution is defined as follows: • If a occurs before b on the same process, then a → b. • If a produces (comp) m and b delivers m, then a → b. • If a delivers m and b consumes (comp) m, then a → b. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
  • 74. Causal Order →: causal order relation. • Also called Leslie Lamport’s happened before relation. The relation → on the events of an execution is defined as follows: • If a occurs before b on the same process, then a → b. • If a produces (comp) m and b delivers m, then a → b. • If a delivers m and b consumes (comp) m, then a → b. Transitivity: if a → b and b → c, then a → c. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
  • 75. Causal Order →: causal order relation. • Also called Leslie Lamport’s happened before relation. The relation → on the events of an execution is defined as follows: • If a occurs before b on the same process, then a → b. • If a produces (comp) m and b delivers m, then a → b. • If a delivers m and b consumes (comp) m, then a → b. Transitivity: if a → b and b → c, then a → c. concurrent events (a||b): if a → b and b → a. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 32 / 67
  • 76. Causal Order Example Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 33 / 67
  • 77. Causal Order Example Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 34 / 67
  • 78. Equivalence of Executions If two executions F and E have the same collection of events, and their causal order is preserved, F and E are said to be similar exe- cutions. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 35 / 67
  • 79. Equivalence of Executions If two executions F and E have the same collection of events, and their causal order is preserved, F and E are said to be similar exe- cutions. F and E could have different permutation of events as long as causality is preserved. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 35 / 67
  • 80. Example of Similar Executions Same color ∼ Causally related Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 36 / 67
  • 81. So causality is all that matters ... Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 37 / 67
  • 82. So causality is all that matters ... ... how to locally tell if two events are causally related? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 37 / 67
  • 83. Lamport Clocks Each process pi has a local logical clock ti. • Initially ti = 0 Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
  • 84. Lamport Clocks Each process pi has a local logical clock ti. • Initially ti = 0 Before timestamping a local event pi executes ti := ti + 1. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
  • 85. Lamport Clocks Each process pi has a local logical clock ti. • Initially ti = 0 Before timestamping a local event pi executes ti := ti + 1. Whenever a message m is sent from pi to pj: • pi executes ti := ti + 1 and sends ti with m. • pj receives ti with m and executes tj := max(tj, ti) + 1. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 38 / 67
  • 86. Example of Lamport Logical Clock Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 39 / 67
  • 87. Lamport Clocks Properties a → b implies t(a) < t(b), where t(a) is Lamport clock of event a. t(a) < t(b) does not necessarily imply a → b t(E31) < t(E13), but E31 → E13 Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 40 / 67
  • 88. Shortcoming of Lamport Clocks Main shortcoming of Lamport’s clocks: • t(a) < t(b) does not necessarily imply a → b • We cannot deduce causal dependencies from time stamps. Why? • Clocks advance independently or via messages. • There is no history as to where advances come from. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 41 / 67
  • 89. Vector Clocks At each process, maintain a clock for every other process. • Each clock Vi is a vector of size N. • Vi[j] contains process pis knowledge about process pj’s clock. • Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
  • 90. Vector Clocks At each process, maintain a clock for every other process. • Each clock Vi is a vector of size N. • Vi[j] contains process pis knowledge about process pj’s clock. • Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}. Before pi timestamps an event: Vi[i] := Vi[i] + 1. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
  • 91. Vector Clocks At each process, maintain a clock for every other process. • Each clock Vi is a vector of size N. • Vi[j] contains process pis knowledge about process pj’s clock. • Initially, Vi[j] := 0 for i, j ∈ {1, · · · , N}. Before pi timestamps an event: Vi[i] := Vi[i] + 1. Whenever a message m is sent from pi to pj: • pi executes Vi[i] := Vi[i] + 1 and sends Vi with m. • pj receives Vi with m and merges the vector clocks Vi and Vj: Vj[k] = max(Vj[k], Vi[k]) + 1 if j = k max(Vj[k], Vi[k]) otherwise Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 42 / 67
  • 92. Example of Vector Clock Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 43 / 67
  • 93. Comparing Vector Clocks V = V iff V [i] = V [i] for i ∈ {1, · · · , N} V ≤ V iff V [i] ≤ V [i] for i ∈ {1, · · · , N} V ||V iff V ≤ V ∧ V ≤ V Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 44 / 67
  • 94. Vector Clocks Properties a → b implies V (a) < V (b) V (a) < V (b) implies a → b Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 45 / 67
  • 95. Logical Clock vs. Vector Clock Logical clock • If a → b then t(a) < t(b) Vector clock • If a → b then V (a) < V (b) • If V (a) < V (b) then a → b • Sending extra information: vector with size N, for N processes. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 46 / 67
  • 96. Global State Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 47 / 67
  • 97. Global State Determining global properties Distributed checkpoint • What is a correct state of the system to save? Distributed garbage collection • Do any references exist to a given object? ... Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 48 / 67
  • 98. Local History N processes pi, i ∈ {1, · · · , N} Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
  • 99. Local History N processes pi, i ∈ {1, · · · , N} The local history of process pi is a sequence of events hi = e0 i , e1 i , · · · Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
  • 100. Local History N processes pi, i ∈ {1, · · · , N} The local history of process pi is a sequence of events hi = e0 i , e1 i , · · · May be finite or infinite. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
  • 101. Local History N processes pi, i ∈ {1, · · · , N} The local history of process pi is a sequence of events hi = e0 i , e1 i , · · · May be finite or infinite. Each event ej i is either a local event or a communication event. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 49 / 67
  • 102. Local and Global State sk i denotes the local state of process pi after execution of event ek i . Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
  • 103. Local and Global State sk i denotes the local state of process pi after execution of event ek i . The local state sk i records all events included in the history hk i . Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
  • 104. Local and Global State sk i denotes the local state of process pi after execution of event ek i . The local state sk i records all events included in the history hk i . The global state, S, of a distributed computation is an N-tuple of local states (s1, s2, · · · , sN ), one for each process. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 50 / 67
  • 105. Cuts hci i is history of pi up to and including event eci i , called partial history. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
  • 106. Cuts hci i is history of pi up to and including event eci i , called partial history. A cut, C, of a distributed computation is the union of N partial histories, one for each process: C = N i=1 hci i Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
  • 107. Cuts hci i is history of pi up to and including event eci i , called partial history. A cut, C, of a distributed computation is the union of N partial histories, one for each process: C = N i=1 hci i Each cut C has a corresponding global state: S = (s1, s2, · · · , sN ). Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 51 / 67
  • 108. Consistent Cuts (1/2) A cut C is consistent, if for all events e and e (e ∈ C) ∧ (e → e ) ⇒ e ∈ C Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 52 / 67
  • 109. Consistent Cuts (1/2) A cut C is consistent, if for all events e and e (e ∈ C) ∧ (e → e ) ⇒ e ∈ C Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 52 / 67
  • 110. Consistent Cuts (2/2) It can be written as two following conditions: Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
  • 111. Consistent Cuts (2/2) It can be written as two following conditions: • Condition 1: any message that is sent by a process before recording its snapshot, must be recorded in the cut. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
  • 112. Consistent Cuts (2/2) It can be written as two following conditions: • Condition 1: any message that is sent by a process before recording its snapshot, must be recorded in the cut. • Condition 2: any message that is sent by a process after recording its snapshot, must not be recorded in the cut. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
  • 113. Consistent Cuts (2/2) It can be written as two following conditions: • Condition 1: any message that is sent by a process before recording its snapshot, must be recorded in the cut. • Condition 2: any message that is sent by a process after recording its snapshot, must not be recorded in the cut. A global state is consistent if it corresponds to a consistent cut. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 53 / 67
  • 114. Possible Solutions Coordinated blocking Coordinated non-blocking Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 54 / 67
  • 115. Coordinated Blocking At barrier, all processes take their checkpoints. Bulk-Synchronous Parallel (BSP) Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 55 / 67
  • 116. Coordinated Non-Blocking Processes must be coordinated, but do we really need to block? Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 56 / 67
  • 117. Coordinated Non-Blocking Processes must be coordinated, but do we really need to block? Chandy and Lamport’s snapshot Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 56 / 67
  • 118. Chandy and Lamport’s Snapshot Determines a consistent global state. Takes care of messages that are in transit. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 57 / 67
  • 119. Model of a Distributed System Process: one process initiates taking of global snapshot Channels: directed, FIFO, reliable Process graph: fixed topology, strongly connected component Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 58 / 67
  • 120. Chandy and Lamport’s Snapshot Algorithm (1/3) The algorithm can be initiated by any process by executing the Marker Sending Rule, by which it records its local state and sends a marker on each outgoing channel. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
  • 121. Chandy and Lamport’s Snapshot Algorithm (1/3) The algorithm can be initiated by any process by executing the Marker Sending Rule, by which it records its local state and sends a marker on each outgoing channel. A process executes the Marker Receiving Rule on receiving a marker. If the process has not yet recorded its local state, it records the state of the channel on which the marker is received as empty and executes the Marker Sending Rule to record its local state. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
  • 122. Chandy and Lamport’s Snapshot Algorithm (1/3) The algorithm can be initiated by any process by executing the Marker Sending Rule, by which it records its local state and sends a marker on each outgoing channel. A process executes the Marker Receiving Rule on receiving a marker. If the process has not yet recorded its local state, it records the state of the channel on which the marker is received as empty and executes the Marker Sending Rule to record its local state. The algorithm terminates after each process has received a marker on all of its incoming channels. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
  • 123. Chandy and Lamport’s Snapshot Algorithm (1/3) The algorithm can be initiated by any process by executing the Marker Sending Rule, by which it records its local state and sends a marker on each outgoing channel. A process executes the Marker Receiving Rule on receiving a marker. If the process has not yet recorded its local state, it records the state of the channel on which the marker is received as empty and executes the Marker Sending Rule to record its local state. The algorithm terminates after each process has received a marker on all of its incoming channels. All the local snapshots get disseminated to all other processes and all the processes can determine the global state. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 59 / 67
  • 124. Chandy and Lamport’s Snapshot Algorithm (2/3) Marker Sending Rule for process pi: • Process pi records its state. • For each outgoing channel c on which a marker has not been sent, pi sends a marker along c before pi sends further messages along c. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 60 / 67
  • 125. Chandy and Lamport’s Snapshot Algorithm (3/3) Marker Receiving Rule for process pj on receiving a marker along channel c: • If pj has not recorded its state, it records the state of channel c as the empty set, and follows the Marker Sending Rule. • Otherwise, it records the state of c as the set of messages received along c after pj’s state was recorded and before pj received the marker along c. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 61 / 67
  • 126. Correctness of the Algorithm (1/2) Condition 1: any message that is sent by a process before recording its snapshot, must be recorded in the cut. When a process pj receives message mij from pi that precedes the marker on channel cij, it acts as follows: if process pj has not taken its snapshot yet, then it includes mij in its recorded snapshot. Otherwise, it records mij in the state of the channel cij. Thus, condition Condition 1 is satisfied. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 62 / 67
  • 127. Correctness of the Algorithm (2/2) Condition 2: any message that is sent by a process after recording its snapshot, must not be recorded in the cut. Due to FIFO property of channels, it follows that no message sent after the marker on that channel is recorded in the channel state. Thus, condition Condition 2 is satisfied. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 63 / 67
  • 128. Summary Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 64 / 67
  • 129. Summary Correctness of distributed algorithms: safety + liveness Casual order Logical clock and Vector clock Global state: Chandy and Lamport’s algorithm Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 65 / 67
  • 130. References: L. Lamport, Time, clocks, and the ordering of events in a distributed system. ACM Communications, 1978 K.M. Chandy and L. Lamport, Distributed snapshots: determining global states of distributed systems. ACM Transactions on Com- puter Systems, 1985. B. Alpern and F.B. Schneider, Defining Liveness. Technical Report, 1984. Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 66 / 67
  • 131. Questions? Acknowledgements Some slides were derived from Seif Haridi slides (KTH University). Amir H. Payberah (Tehran Polytechnic) Time, clocks and the ordering of events 1393/6/29 67 / 67