Distributed Systems Principles and Paradigms
Distributed Systems Principles and Paradigms
Chapter 05
Synchronization
Communication & Synchronization
• Time
– Why is time important in DS?
– E.g. UNIX make utility (see Fig. 5-1)
• Clocks (Timer)
– Physical clocks
– Logical clocks (introduced by Leslie Lamport)
– Vector clocks (introduced by Collin Fidge)
• Clock Synchronization
– How do we synchronize clocks with real-world time?
– How do we synchronize clocks with each other?
Question: Does this solve all our problems? Don’t we now have
some global timing mechanism?
05 – 2 Distributed Algorithms/5.1 Clock
Physical Clocks (2/3)
Problem: Suppose we have a distributed system with a UTC-
receiver somewhere in it, we still have to distribute its time to each
machine.
Basic principle:
• Every machine has a timer that generates an interrupt H (typically
60) times per second.
• There is a clock in machine p that ticks on each timer interrupt.
Denote the value of that clock by Cp (t) , where t is UTC time.
• Ideally, we have that for each machine p, Cp (t) = t, or, in other
words, dC/ dt = 1
• Theoretically, a timer with H=60 should generate 216,000 ticks per
hour
• In practice, the relative error of modern timer chips is 10**-5 (or
between 215,998 and 216,002 ticks per hour)
05 – 3 Distributed Algorithms/5.1 Clock Synchronization
Physical Clocks (3/3)
Goal: Never let two clocks in any system differ by more than time units =>
synchronize at least every 2seconds.
Fig 5-7. (a) Three processes, each with its own clock. The clocks
run at different rates. (b) Lamport’s algorithm corrects the clocks
a e
j
b f k
c
g
d h l
i
a e
j
b f k
c
g
d h l
i
[1,0,0] 1 a [0,1,0] 1 e
1 j [0,0,1]
[2,0,0] 2
b f [3,2,0] 2 k [0,0,2]
3
[3,0,0] 3 c
[3,3,3] 4 g
[4,0,0] 4 d 5 h [3,4,3] 3 l [0,0,3]
6 i [5,5,3]
The above diagram shows both Lamport
timestamps (an integer value ) and Fidge
timestamps (a vector of integer values ) for
each event.
– Lamport clocks:
2 < 5 since b h,
3 < 4 but c g.
– Fidge clocks:
f h since 2 < 4 is true,
b h since 2 < 3 is true,
h a since 4 < 0 is false,
c h since (3 < 3) is false and (4 < 0) is false.
P1 P2 P3 P4
a
e j
m
b f k
c n
g
d h o
l
i
Assign the Lamport’s and Fidge’s logical clock values for all the events in the above
timing diagram. Assume that each process’s logical clock is set to 0 initially.
From the above timing diagram, what can you say
about the following events?
1. between b and n:
2. between b and o:
3. between m and g:
4. between c and h:
5. between c and l:
6. between j and g:
7. between k and i:
8. between j and h:
READING Reference:
• Colin Fidge, “Logical Time in Distributed
Computing Systems”, IEEE Computer, Vol.
24, No. 8, pp. 28-33, August 1991.
Global State (1/3)
• Classification of transactions
• Concurrency control
The Transaction Model (1)
Primitive Description
BEGIN_TRANSACTION BEGIN_TRANSACTION
reserve BOS -> JFK; reserve BOS -> JFK;
reserve JFK -> ICN; reserve JFK -> ICN;
reserve SEL -> KPO; reserve SEL -> KPO full =>
END_TRANSACTION ABORT_TRANSACTION
(a) (b)
• Atomic
To the outside world, the transaction happens indivisibly
• Consistent
The transaction does not violate system invariants
• Isolated
Concurrent transactions do not interfere with each other
• Durable
Once a transaction commits, the changes are permanent
Nested Transactions
• Constructed from a number of subtransactions
• The top-level transaction may create children that run in parallel with
one another to gain performance or simplify programming
• Each of these children is called a subtransaction and it may also have
one or more subtransactions
1. Private Workspace
• Gives a private workspace (i.e., all the data it has access to) to
a process when it begins a transaction
2. Writeahead Log
• Files are actually modified in place but before any block is
changed, a record is written to a log telling
which transaction is making the change
which file and block is being changed
what the old and new values are
• Only after the log has been written successfully, the change is
made to the file
(a) a transaction
(b) – (d) The log before each statement is executed
Concurrency Control (1)
• The goal of concurrency control is to allow multiple transactions
to be executed simultaneously
• Final result should be the same as if all transactions had run
sequentially
General organization of
managers for handling
distributed transactions.
Serializability (1)
BEGIN_TRANSACTION BEGIN_TRANSACTION BEGIN_TRANSACTION
x = 0; x = 0; x = 0;
x = x + 1; x = x + 2; x = x + 3;
END_TRANSACTION END_TRANSACTION END_TRANSACTION
Schedule 1 x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3 Legal
Schedule 2 x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3; Legal
Schedule 3 x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3; Illegal
(d)