110 likes | 187 Views
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.
E N D
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 • 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
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
Lamport’s Logical Clock • Three processes, each with its own clock. The clocks run at different rates.
Example: Totally-Ordered Multicasting • Updating a replicated database and leaving it in an inconsistent state.
Problem with Lamport’s Clock What can we infer about: Trcv (m2) < Tsend (m3) Trcv(m1) < Tsend (m2) Lamport’s clock does not capture causality • If a -> b then C(b) > C(a) • But what can you infer by knowing C(e) > C(d)?
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)
Maintaining Vector Clock • Vector timestamp algorithm • Three step process • Before executing an event Pi increments VCi[i] • Any message sent from Pi (say, to Pj) will carry the current vector at Pi (VCi) • When Pj receives a message m • Adjusts its own vector (VCj[k] = max (VCj[k], ts(m)[k]) • Executes step 1