Synchronization - PowerPoint PPT Presentation

About This Presentation
Title:

Synchronization

Description:

Clock synchronization ... How do we synchronize them with real-world clocks ... Synchronization between processes choose a coordinator election algorithms ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 38
Provided by: sfme
Category:

less

Transcript and Presenter's Notes

Title: Synchronization


1
Synchronization
  • Chapter 5

2
Contents
  • Clock Synchronization
  • Logical Clocks
  • Global State
  • Election Algorithms
  • Mutual Exclusion
  • Distributed Transactions
  • Conclusion
  • Critical Idea

3
Clock synchronization
  • A simple question Is it possible to synchronize
    all the clocks in a distributed system ?

4
Physical Clocks (1)
  • Some concept Timer counter, holding register
    clock tick clock skew.
  • Prob
  • How do we synchronize them with real-world clocks
  • How do we synchronize the clocks with each other
  • Mean solar second measuring a large numbers of
    day ? taking average ? dividing by 86400
  • TAI the mean number of sticks of the cesium 133
    clocks (since 1/1/1958) divided by 9,192,631,770

5
Physical Clocks (2)
  • TAI highly stable but late ? leap second
  • By the way raising their frequency from 60Hz or
    50Hz ? 61Hz or 51Hz

6
Cristians Algorithm
  • No more than d/2? each machine sends a message to
    the time server (which has a WWV receiver) asking
    for the current time
  • Probs time must never run backward and its take
    a nonzero amount of time for the time
    servers reply to get back to the sender

7
The Berkeley Algorithm
  • 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

8
Averaging Algorithms
  • At the beginning of each interval, every machine
    broadcasts the current time according to its
    clock.
  • Then it starts a local timer to collect all other
    broadcasts that arrive during some interval S.
  • The simplest algorithm is just to average the
    values from all other machines.
  • One of the most widely used algorithms in the
    Internet is the Network Time Protocol (NTP).

9
Assign time to dist. Sys.
  • If a happens before b in the same process,
    C(a) lt C(b).
  • If a and b represent the sending and receiving of
    a message, respectively, C(a) lt C(b).
  • For all distinctive events a and b, C(a) ? C(b).

10
Totally order Multicasting
  • ? Timestamp can be used to implement totally
    ordered multicast

11
Vector timestamps
  • VT(a) lt VT(b) ? a causally precede event b
  • Properties of vector timestamps
  • Vii is the number of events that have occurred
    so far at Pi
  • If Vij k then Pj knows that k events have
    occurred at Pj
  • Message r (from PJ) reaction of message a (PI)
  • PK process message r if
  • vt(r)j Vkj 1
  • vt(r)i Vki for all i?j

12
Global State (1)
  1. A consistent cut
  2. An inconsistent cut

13
Global State (2)
  1. Organization of a process and channels for a
    distributed snapshot

14
Global State (3)
  • Process Q receives a marker for the first time
    and records its local state
  • Q records all incoming message
  • Q receives a marker for its incoming channel and
    finishes recording the state of the incoming
    channel

15
Election Algorithms
  • Election algorithms algorithms for electing a
    coordinator (using this as a generic name for
    the special process).
  • Election algorithms attempt to locate the process
    with the highest process number and designate it
    as coordinator.
  • Goal to ensure that when an election starts, it
    concludes with all processes agreeing on who the
    new coordinator is to be.

16
The Bully Algorithm (1)
  • The bully election algorithm
  • Process 4 holds an election
  • Process 5 and 6 respond, telling 4 to stop
  • Now 5 and 6 each hold an election

17
The Bully Algorithm (2)
  1. Process 6 tells 5 to stop
  2. Process 6 wins and tells everyone

18
Ring Algorithm
19
Mutual ExclusionCentralized Algorithm
  1. Process 1 asks the coordinator for permission to
    enter a critical region. Permission is granted
  2. Process 2 then asks permission to enter the same
    critical region. The coordinator does not reply.
  3. When process 1 exits the critical region, it
    tells the coordinator, when then replies to 2

20
Distributed Algorithm
  1. Two processes want to enter the same critical
    region at the same moment.
  2. Process 0 has the lowest timestamp, so it wins.
  3. When process 0 is done, it sends an OK also, so 2
    can now enter the critical region.

21
Token Ring Algorithm
  1. An unordered group of processes on a network.
  2. A logical ring constructed in software.

22
Comparison
Algorithm Messages per entry/exit Delay before entry (in message times) Problems
Centralized 3 2 Coordinator crash
Distributed 2 ( n 1 ) 2 ( n 1 ) Crash of any process Group communication
Token ring 1 to ? 0 to n 1 Lost token, process crash
  • A comparison of three mutual exclusion algorithms.

23
The Transaction Model (1)
  • Updating a master tape is fault tolerant.

24
The Transaction Model (2)
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.

25
Four Characteristics
  • Atomicto 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

26
Limitations of Flat Transactions
  • Main limitation do not allow partial results to
    be committed or aborted
  • In the case of updating all of the hyperlinks to
    a webpage W, which moved to a new
    location

BEGIN_TRANSACTION reserve WP -gt JFK reserve JFK -gt Nairobi reserve Nairobi -gt MalindiEND_TRANSACTION (a) BEGIN_TRANSACTION reserve WP -gt JFK reserve JFK -gt Nairobi reserve Nairobi -gt Malindi full gtABORT_TRANSACTION (b)
27
Classification of Transactions
  1. A nested transaction
  2. A distributed transaction

28
ImplementationPrivate Workspace
  • A file is only for read not modify ? there is no
    need for a private copy

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 b) After committing
29
Writeahead Log
x 0 y 0 BEGIN_TRANSACTION x x 1 y y 2 x y y END_TRANSACTION (a) Log x 0 / 1 (b) Log x 0 / 1 y 0/2 (c) Log x 0 / 1 y 0/2 x 1/4 (d)
  • a) A transaction
  • b) d) The log before each statement is executed

30
Concurrency Control (1)
  • General organization of managers for handling
    transactions

31
Concurrency Control (2)
  • General organization of managers for handling
    distributed transactions

32
Serializability
  • The whole idea behind concurrency control is to
    properly schedule conflicting operations (two
    read operations never conflict )
  • Synchronization can take place either through
    mutual exclusion mechanisms on shared data (i.e
    locking)
  • Or explicitly ordering operations using
    timestamps

33
Two-phase locking
  • A transaction T is granted a lock if there is no
    conflict
  • The scheduler will never release a lock for data
    item x, until the data manager acknowledges it
    has performed the operation for which the lock
    was set
  • Once the scheduler has released a lock on behalf
    of a transaction T, it will never grant another
    lock on behalf of T

34
Strict two-phase locking
  • In centralized 2PL a single site is responsible
    for granting and releasing locks
  • In primary 2PL each data item is assigned a
    primary copy
  • In distributed 2PL the schedulers on each
    machine not only take care that locks are granted
    and released, but also that the operation is
    forwarded to the (local) data manager

35
Pessimistic Timestamp Ordering
  • Concurrency control using timestamps.

36
Conclusion
  • Lamport timestamps if a happen before b ?
    C(a) lt C(b).
  • Determining the global state can be done by
    synchronizing all processes so that each
    collects its own local state, along with the
    messages that are currently in transit.
  • Synchronization between processes ? choose a
    coordinator ? election algorithms
  • Mutual Exclusion algorithms can be centralized
    or distributed

37
Conclusion Critical Idea
  • A transaction consists of a series of operations
  • A transaction is durable, meaning that if it
    completes, its effects are permanent
  • Two-phase locking can lead to dead lock
  • Acquiring all locks in some canonical order to
    prevent hold-and-wait cycles
  • Using deadlock detection by maintaining an
    explicit graph for cycles
  • Inheritance Priority Protocol
Write a Comment
User Comments (0)
About PowerShow.com