Professional Documents
Culture Documents
DisSys Lec5
DisSys Lec5
• Physical timestamps: useful for many things, but may be inconsistent with
causality.
• As such, it has no direct relationship to physical time. On each node, time increases because the
integer is incremented on every event.
• When a message is sent over the network, the sender attaches its current Lamport timestamp to
that message.
• When the recipient receives a message, it moves its local Lamport clock forward to the timestamp
in the message plus one; if the recipient's clock is already ahead of the timestamp in the message,
it is only incremented.
Lamport clocks example
Lamport clocks example
end on
on request to send message 𝑚 at node 𝑁𝑖 do
𝑇[𝑖] ∶= 𝑇[𝑖] + 1; send (𝑇, 𝑚) via network
end on
on receiving (𝑇′, 𝑚) at node 𝑁𝑖 via the network do
𝑇[𝑗] ∶= max(𝑇 𝑗 , 𝑇′[𝑗]) for every 𝑗 ∈ {1, … , 𝑛}
𝑇[𝑖] ∶= 𝑇[𝑖] + 1; deliver 𝑚 to the application
end on
Vector clocks example
• Assuming the vector of nodes is 𝑁 = 𝐴, 𝐵, 𝐶
• The vector timestamp of an event 𝑒 represents a set of events, 𝑒 and its causal dependencies:
𝑒 ∪ 𝑎: 𝑎 → 𝑒
• For example, (2, 2, 0) represents the first two events from 𝐴, the first two events from 𝐵, and
no events from 𝐶.
Vector clocks ordering
• Define the following order on vector timestamps (in a system with n nodes):
Vector clocks ordering
• We then define a partial order over vector timestamps. We say that one vector is less than or
equal to another vector if every element of the first vector is less than or equal to the
corresponding element of the second vector.
• One vector is strictly less than another vector if they are less than or equal, and if they differ in at
least one element.
• However, two vectors are incomparable if one vector has a greater value in one element, and the
other has a greater value in a different element.
• For example, 𝑇 = (2,2,0) and 𝑇’ = (0,0,1) are incomparable because 𝑇[1] > 𝑇’[1] but 𝑇 3 <
𝑇’ 3 .
Vector clocks ordering
• The partial order over vector timestamps corresponds exactly to the partial order
defined by the happens-before relation.
• Thus, the vector clock algorithm provides us with a mechanism for computing the
happens-before relation in practice.