Vector Clocks is an
algorithm for generating a
partial ordering of events in a
distributed system and detecting
causality violations. 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:
- 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 Friedemann Mattern in 1988.
Partial ordering property
Vector clocks allow for the partial causal ordering of events. Defining the following:
- VC(x) denote the vector clock of event x
-
- 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'].
- x -> y denote event x happened before event y. It's defined as: if x -> y, then VC(x) < VC(y)
Properties:
- If VC(a) < VC(b), then a -> b
- Antisymmetry: if VC(a) < VC(b), then ¬ VC(b) < VC(a)
- Transitivity: if VC(a) < VC(b) and VC(b) < VC(c), then VC(a) < VC(c) or if a -> b and b -> c, then a -> c
See also
References