5) Concurrency Control
5) Concurrency Control
5) Concurrency Control
Clock synchronization
Logical clocks and global state
Election Algorithms
1
Clock Synchronization: Introduction
2
Clock Synchronization: Sources of Accurate Timing Signals
3
Clock Synchronization
Difficulties in clock synchronization in DS
– Not all sites have direct access to accurate time source
such as a GPS receivers due to the cost.
– Sites has to synchronize their local clocks with those
have more accurate time.
– Synchronization needs to be done periodically due to
clock drift: rate is change in the offset (difference in
reading) between the clock and a normal perfect
reference clock per unit of time measured (about 10 -6 or
1 sec. in 11.6 days).
If a site’s clock is ahead of the reference (time
server) to which it synchronizes to, it cannot be
simply set back.
4
Clock Synchronization
For process pi
– Ci(t) – software clock
– Hi(t) – Hardware clock, I.e., the time given by hardware clock
Thus: Ci(t) = H(t)+
Various notions of correctness for clocks have been suggested.
It is common to define a hardware clock H to be correct if its
drifts fall within a known bound > 0 (e.g. for real-time t’ and t,
t’>t).
The error in measuring the interval between real times t’ and t,
t’>t) is bounded:
(1- )(t’-t) ≤ H(t’) – H(t) ≤ (1+ )(t’-t)
5
External and Internal Clock Synchronization
External synchronization
– A computer’s clock Ci is synchronized with an external authoritative time
source S, so that:
– |S(t) - Ci(t)| < D for i = 1, 2, … N over an interval, I of real time
– The clocks Ci are accurate to within the bound D.
Internal synchronization
– The clocks of a pair of computers are synchronized with one another so
that:
– | Ci(t) - Cj(t)| < D for i = 1, 2, … N over an interval, I of real time
– The clocks Ci and Cj agree within the bound D.
Internally synchronized clocks are not necessarily externally
synchronized, as they may drift collectively.
if the set of processes P is synchronized externally within a bound
D, it is also internally synchronized with a bound of 2D.
6
Clock Synchronization: Cristian Algorithm
Client C requests time in Request message sent to time server S,
then it receives time value t in message CUTC from S. t is the current
time in S before sending back CUTC to C.
Let Ttrans be time taken for CUTC message from S to C, then C should
set its time to t + Ttrans .
Ttrans can be variant. You may say: Ttrans = min+x, x ≥ 0 and min = time
of message transmission if no interference of other process and no
other messages, but x is unknown!
Solution: (1) Record total round trip time as Tround (between sending
Request and receiving CUTC,, i.e., T1-T0) (2) If the time received in
Request message is t, then C can estimate its time as: t + Tround/2.
7
Clock Synchronization: Cristian Algorithm
8
Clock Synchronization: Berkeley Algorithm
In Berkeley UNIX, one of a group sites (computers) is chosen as
coordinator, (master or time server).
(1) The master (actually a time daemon in the master) periodically polls the
other sites (slaves) to ask what time it is there, by telling its own time (the time in
master) to these slaves.
(2) The slaves response with how far ahead or behind the time daemon they
are, that is, the difference between its time and the time in master.
(3) Based on the replies from the slaves, the master averages the time obtained
(including its own).
(4) The master sends time rate adjust value (+ or -) to slaves, requesting them
to adjust their time rate.
9
The Berkeley Algorithm: An Example
a) The time daemon asks all the other machines for their clock values
b) The machines answer
c) The time daemon tells everyone how to adjust their clock
10
Clock Synchronization: Network Time Protocol
(NTP)
11
Clock Synchronization: Network Time
Protocol
Synchronization clock: Network Time Protocol (NTP)
Stratum 1: Primary server (PS) sync directly with UTC sources.
Stratum 2: Secondary servers (SS) sync directly to PS.
Stratum 3: Lowest servers (LS) execute in user sites sync with SS.
Accuracy: the number of levers (strata).
2 2
3 3 3
12
Clock Synchronization: Network Time
Protocol
13
Logical Time and Logical Clock
14
Global State
a) A consistent cut
b) An inconsistent cut
16
Global State: Algorithm for Taking Snapshot I
b) Process Q receives a marker for the first time and records its local
state
c) Q records all incoming message
d) Q receives a marker for its incoming channel and finishes recording
the state of the incoming channel
20
Global State: Algorithm for Termination Detection I
22