You are on page 1of 23

Synchronization

Clock Synchronization
In a centralized system time is unambiguous.
In a distributed system agreement on time is not obvious.

When each machine has its own clock, an event that occurred after another event
may be assigned an earlier time.
Clock Synchronization Algorithms
If 1 dC/dt < 1 + maximum drift rate
Resynchronization interval maximum time difference

The relation between clock time and UTC when clocks tick at different rates.
Cristian's Algorithm
synchronization with a time server
Time must never run backward gradual changes
Non zero message propagation time
The Berkeley Algorithm
synchronization without time server

a) The machines answer


b) The time daemon asks all the other machines for their clock values
c) The time daemon tells everyone how to adjust their clock
no Universal Coordinated Time available
Centralized algorithms have disadvantages.
Decentralized algorithms can use averaging methods.
NTP (Network Time Protocol) provides an accuracy
of 1-50 msec using advanced algorithms.

For many purposes it is sufficient that all machines


agree on the same time.

Logical clocks
Lamport Timestamps
If a b C(a) < C(b)
If a sen., b rec. C(a) < C(b)
C(a) C(b)

If C(a) < C(b) C(a) = C(b)+1

We obtain a total ordering of all events in the system


Lamport timestamps dont capture causality

Vector timestamps
Global State
it is the local state of each process, together with the messages currently in transit

a distributed snapshot reflects a consistent global state


Global State
any process P may initiate the algorithm recording its local state.

Organization of a process and channels for a distributed snapshot


a) A process P sends a marker along each of its outgoing channels
Global State

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
A process has finished its part of the algorithm when it has received a
marker along each of its incoming channels, and processed each one.

Many snapshots may be in progress at the same time.


The Selecting
Bully aAlgorithm
coordinator

The bully election algorithm


a) Process 4 holds an election
b) Process 5 and 6 respond, telling 4 to stop
c) Now 5 and 6 each hold an election
d) Process 6 tells 5 to stop
e) Process 6 wins and tells everyone
Mutual Exclusion:
critical regions in distributed systems
A Centralized Algorithm

a) Process 1 asks the coordinator for permission to enter a critical region.


Permission is granted
b) Process 2 then asks permission to enter the same critical region. The
coordinator does not reply.
c) When process 1 exits the critical region, it tells the coordinator, which
then replies to 2
A Distributed Algorithm
requires a total ordering of all events in the system

a) Two processes (0,2) want to enter the same critical region at the same moment.
b) Process 0 has the lowest timestamp, so it wins.
c) When process 0 is done, it sends an OK also, so 2 can now enter the critical
region.
This algorithm is worse than the centralized one, but possible
A Toke Ring Algorithm

start

a) An unordered group of processes on a network.


b) A logical ring constructed in software.
Comparison

Messages per Delay before entry


Algorithm Problems
entry/exit (in message times)

Centralized 3 2 Coordinator crash

Crash of any
Distributed 2(n1) 2(n1)
process

Lost token,
Token ring 1 to 0 to n 1
process crash

A comparison of three mutual exclusion algorithms.


The Transaction Model
A transaction permits that a whole set of related instructions
would be successfully completed or none would be completed.
Special primitives are requested

Primitive Description

BEGIN_TRANSACTION Make the start of a transaction

END_TRANSACTION Terminate the transaction and try to commit

ABORT_TRANSACTION Kill the transaction and restore the old values

READ Read data from a file, a table, or otherwise

WRITE Write data to a file, a table, or otherwise

Examples of primitives for transactions.


The Transaction Model

Transactions are ACID:


Atomic : to outside, they happen indivisibly
Consistent : they dont violate system invariants
Isolated : concurrent transactions dont interfere
Durable : the changes are permanent
Distributed Transactions
a) A nested transaction (it follows a logical division of the work)
b) A distributed transaction (it is logically flat and operates on distributed
data)
Private Workspace

a) The file index and disk blocks for a three-block file


b) The situation after a transaction has modified block 0 and appended block 3
c) After committing
Writeahead Log
x = 0; Log Log Log
y = 0;
rollback
BEGIN_TRANSACTION;
x = x + 1; [x = 0 / 1] [x = 0 / 1] [x = 0 / 1]
y=y+2 [y = 0/2] [y = 0/2]
x = y * y; [x = 1/4]
END_TRANSACTION;
(a) (b) (c) (d)

a) A transaction
b) d) The log before each statement is executed

In distributed systems each machine keeps its own log of changes to its
local file system
Concurrency Control
allows several transaction to be executed simultaneously leaving data in a
consistent way

General organization of managers for handling transactions .


Concurrency Control
General organization of
managers for handling
distributed transactions.

You might also like