Vector clocks

From Wikipedia, the free encyclopedia

Vector Clocks is an algorithm for generating a total ordering of events in a distributed system. Just as in Lamport timestamps, interprocess messages contain the state of the sending process's logical clock. Vector clock of a system of N processes is an array of N logical clocks, one per process, a local copy of which is kept in each process with the following rules for clock updates:

Example of a system of vector clocks
Enlarge
Example of a system of vector clocks
  • initially all clocks are zero
  • each time a process experiences an internal event, it increments its own logical clock in the vector by one
  • each time a process prepares to send a message, it increments its own logical clock in the vector by one and then sends its entire vector along with the message being sent
  • each time a process receives a message, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element).

The Vector clocks algorithm was developed by F. Mattern in 1989.

[edit] Total ordering property

Vector clocks allow for the total causal ordering of events because of an equivalence relation between the vector clock at a particular event and the physical time of the event. Specifically:

  • For any two events a and b, if VC(a) < VC(b), then time(a) < time(b).
  • Symmetrically: if time(a) < time(b), then VC(a) < VC(b)
  • Transitively: if ( VC(a) < VC(b) or time(a) < time(b) ) and ( VC(b) < VC(c) or time(b) < time(c) ), then VC(a) < VC(c) and time(a) < time(c)

Where:

  • VC(x) denote the vector clock of event x
  • time(x) denote the physical time occurrence
  • VC(x) < VC(y) \iff \forall z [VC(x)_z \le VC(y)_z] \and \exists z' [ VC(x)_{z'} < VC(y)_{z'} ]
    • In English: VC(x) is less than VC(y) if and only if VC(x)[z] is less than or equal to VC(y)[z] for all indices z and there exists an index z' such that VC(x)[z'] is strictly less than VC(y)[z'].

[edit] References

Mattern, F. Virtual Time and Global States of Distributed Systems. In Cosnard M. et al. (Eds).Proc. Workshop on Parallel and Distributed Algorithms (Chateau de Bonas, France, Oct. 1988), Elsevier, 1989, pp. 215-226

In other languages