Beruflich Dokumente
Kultur Dokumente
Todays Roadmap
Chapter 7 Models and Clocks
Goal: Define time in a distributed system
Logical clock
Vector clock
Matrix clock
Assumptions
Process can perform three kinds of atomic actions/events
Local computation
Send a single message to a single process
Receive a single message from a single process
No atomic broadcast
Communication model
Point-to-point
Error-free, infinite buffer
Potentially out of order
Motivation
Many protocols need to impose an ordering among events
If two players open the same treasure chest almost at the same
time, who should get the treasure?
Physical clocks:
Seems to completely solve the problem
But what about theory of relativity?
Even without theory of relativity efficiency problems
Software Clocks
Software clocks can incur much lower overhead than maintaining
(sufficiently accurate) physical clocks
Allows a protocol to infer ordering among events
Goal of software clocks: Capture event ordering that are visible to users
But what orderings are visible to users without physical clocks?
A?D
B?D
A C (transitivity)
C?D
user1 (process1)
C
user2 (process2)
user3 (process3)
D
Happened-Before Relation
Happened-before relation captures the ordering that
is visible to users when there is no physical clock
A partial order among events
Process-order, send-receive order, transitivity
3 = max(1,2)+1
user1 (process1)
user2 (process2)
user3 (process3)
1
1
4 = max(3,3)+1
3
4
3
5
5
user1 (process1)
user2 (process2)
user3 (process3)
1
1
3
3
4
4
5
5
10
Vector clock:
Event s happens before event t the vector clock value of s
is smaller than the vector clock value of t.
11
user1 (process1)
user2 (process2)
user3 (process3)
(1,0,0)
(0,1,0)
(0,0,1)
(2,0,0)
(0,2,2)
(0,0,2)
(3,0,0)
(2,3,2)
(2,3,3)
12
user1 (process1)
user2 (process2)
user3 (process3)
13
D2, (0,1,0)
D3, (0,0,1)
(0,2,2) D1
D3
(0,0,2)
(3,0,0)
(2,3,2)
D1, D2, D3
(2,3,3)
14
Matrix clock:
Each event has n vector clocks, one for each process
The i th vector on process i is called process i s principle vector
Principle vector is the same as vector clock before
Non-principle vectors are just piggybacked on messages to update knowledge
15
16
(1,0,0)
(0,0,0)
(0,0,0)
user2 (process2)
(0,0,0)
(0,1,0)
(0,0,0)
user3 (process3)
(0,0,0)
(0,0,0)
(0,0,1)
(2,0,0)
(0,0,0)
(0,0,0)
(0,0,0)
(0,2,2)
(0,0,2)
(0,0,0)
(0,0,0)
(0,0,2)
(3,0,0)
(0,0,0)
(0,0,0)
(2,0,0)
(2,3,2)
(0,0,2)
(2,0,0)
(2,3,2)
(2,3,3)
17
(2,0,0)
(0,0,0)
(0,0,0)
(3,0,0)
(0,0,0)
(0,0,0)
Theorem:
On any given
process, any
non-principle
vector is
smaller than
the principle
vector.
(0,0,0)
(0,1,0)
(0,0,0)
(0,0,0)
(0,0,0)
(0,0,1)
(0,0,0)
(0,2,2)
(0,0,2)
(0,0,0)
(0,0,0)
(0,0,2)
(2,0,0)
(2,3,2)
(0,0,2)
(2,0,0)
(2,3,2)
(2,3,3)
18
(1,0,0)
(0,0,0)
(0,0,0)
(2,0,0)
(0,0,0)
(0,0,0)
order D1 = (1,0,0)
user2 (process2)
order D2 = (0,1,0)
user3 (process3)
order D3 = (0,0,1)
(3,0,0)
(0,0,0)
(0,0,0)
D1
(0,0,0)
(0,1,0)
(0,0,0)
(0,0,0)
(0,0,0)
(0,0,1)
(0,0,0)
(0,2,2)
(0,0,2)
D3
(2,0,0)
(2,3,2)
(0,0,2)
D1, D2, D3
(0,0,0)
(0,0,0)
(0,0,2)
user3 now
knows
that all 3
users
have seen
D1
(2,0,0)
(2,3,2)
(2,3,3)
19
20
Summary
Chapter 7 Models and Clocks
Goal: Define time in a distributed system
Logical clock
happened before smaller clock value
Vector clock
happened before smaller clock value
Matrix clock
Gives a process knowledge about what other processes know
21
Homework Assignment
Prove the following:
If event s happens before t, then the logical clock value of s
is smaller than the logical clock value of t.
Page 126
Problem 7.2 give a counter-example
Problem 7.4
Problem 7.7 Prove that the solution satisfies the property
of logical clocks
22