Synchronization

11
Synchronization CSCI 4780/6780

description

Synchronization. CSCI 4780/6780. The Berkeley Algorithm. The time daemon asks all the other machines for their clock values The machines answer The time daemon tells everyone how to adjust their clock. Logical Clocks. - PowerPoint PPT Presentation

Transcript of Synchronization

Page 1: Synchronization

Synchronization

CSCI 4780/6780

Page 2: Synchronization

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

Page 3: Synchronization

Logical Clocks• For many applications it is sufficient if all machines

agree upon some time– Synchronization with UTC not needed

• Logical clocks

• Lamport showed that in many cases clock synchronization is not needed– What actually is needed is agreement with regards to

ordering of events– Example – Compilation occurred before file editing

Page 4: Synchronization

Concepts in Logical Clocks• Happens-before relation

• a->b if one of the following is true– a and b are events in same process and a occurs before b– If a is an event of sending a message and b is the event of

receiving the same message is another process a->b.• Implies that message cannot be received before it is sent

• Happens-before is transitive– If a->b and b->c then a->c

• If two events in x and y are in two processes that never exchange messages then x & y are concurrent

Page 5: Synchronization

Lamport’s Logical Clock

Three processes, each with its own clock. The clocks run at different rates.

Page 6: Synchronization

Lamport’s Algorithm

Page 7: Synchronization

Placement of Lamport’s Clocks in Dist. Systems

Page 8: Synchronization

Example: Totally-Ordered Multicasting

Updating a replicated database and leaving it in an inconsistent state.

Page 9: Synchronization

Problem with Lamport’s Clock• If a -> b then C(b) > C(a)

• But what can you infer by knowing C(e) > C(d)?

What can we infer about:

Trcv (m2) < Tsend (m3)

Trcv(m1) < Tsend (m2)

Lamport’s clock does not capture causality

Page 10: Synchronization

Vector Clock• Captures causality

– VC(a) < VC (b) implies a causally precedes b

• Each process maintains a vector (VCi for Pi)

– Size of vector is equal to number of processes in the system

– VCi[i] is the number of events that have occurred so far at Pi (VCi[i] is the logical clock at Pi)

– VCi[j] = k implies that Pi knows that k events have occurred at Pj (Pi’s knowledge of the local time at Pj)

Page 11: Synchronization

Maintaining Vector Clock• Vector timestamp algorithm

• Three step process

1. Before executing an event Pi increments VCi[i]

2. Any message sent from Pi (say, to Pj) will carry the current vector at Pi (VCi)

3. When Pj receives a message ma) Adjusts its own vector (VCj[k] = max (VCj[k], ts(m)

[k])

b) Executes step 1