Vector clock

From HandWiki

A vector clock 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. A vector clock of a system of N processes is an array/vector of N logical clocks, one clock per process; a local "smallest possible values" copy of the global clock-array is kept in each process, with the following rules for clock updates:

Example of a system of vector clocks. Events in the blue region are the causes leading to event B4, whereas those in the red region are the effects of event B5
  • 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 sends a message, it increments its own logical clock in the vector by one (as in the bullet above, but not twice for the same event) and then sends a copy of its own vector.
  • 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 independently developed by Colin Fidge and Friedemann Mattern in 1988.[1][2]

Partial ordering property

Vector clocks allow for the partial causal ordering of events. Defining the following:

  • [math]\displaystyle{ VC(x) }[/math] denotes the vector clock of event [math]\displaystyle{ x }[/math], and [math]\displaystyle{ VC(x)_z }[/math] denotes the component of that clock for process [math]\displaystyle{ z }[/math].
  • [math]\displaystyle{ VC(x) \lt VC(y) \iff \forall z [VC(x)_z \le VC(y)_z] \land \exists z' [ VC(x)_{z'} \lt VC(y)_{z'} ] }[/math]
    • In English: [math]\displaystyle{ VC(x) }[/math] is less than [math]\displaystyle{ VC(y) }[/math], if and only if [math]\displaystyle{ VC(x)_z }[/math] is less than or equal to [math]\displaystyle{ VC(y)_z }[/math] for all process indices [math]\displaystyle{ z }[/math], and at least one of those relationships is strictly smaller (that is, [math]\displaystyle{ VC(x)_{z'} \lt VC(y)_{z'} }[/math]).
  • [math]\displaystyle{ x \to y\; }[/math] denotes that event [math]\displaystyle{ x }[/math] happened before event [math]\displaystyle{ y }[/math]. It is defined as: if [math]\displaystyle{ x \to y\; }[/math], then [math]\displaystyle{ VC(x) \lt VC(y) }[/math]

Properties:

  • Antisymmetry: if [math]\displaystyle{ VC(a) \lt VC(b) }[/math], then ¬[math]\displaystyle{ (VC(b) \lt VC(a)) }[/math]
  • Transitivity: if [math]\displaystyle{ VC(a) \lt VC(b) }[/math] and [math]\displaystyle{ VC(b) \lt VC(c) }[/math], then [math]\displaystyle{ VC(a) \lt VC(c) }[/math] or if [math]\displaystyle{ a \to b\; }[/math] and [math]\displaystyle{ b \to c\; }[/math], then [math]\displaystyle{ a \to c\; }[/math]

Relation with other orders:

  • Let [math]\displaystyle{ RT(x) }[/math] be the real time when event [math]\displaystyle{ x }[/math] occurs. If [math]\displaystyle{ VC(a) \lt VC(b) }[/math], then [math]\displaystyle{ RT(a) \lt RT(b) }[/math]
  • Let [math]\displaystyle{ C(x) }[/math] be the Lamport timestamp of event [math]\displaystyle{ x }[/math]. If [math]\displaystyle{ VC(a) \lt VC(b) }[/math], then [math]\displaystyle{ C(a) \lt C(b) }[/math]

Other mechanisms

  • In 1999, Torres-Rojas and Ahamad developed Plausible Clocks,[3] a mechanism that takes less space than vector clocks but that, in some cases, will totally order events that are causally concurrent.
  • In 2008, Almeida et al. introduced Interval Tree Clocks.[4][5][6] This mechanism generalizes Vector Clocks and allows operation in dynamic environments when the identities and number of processes in the computation is not known in advance.
  • In 2019, Lum Ramabaja developed Bloom Clocks, [7] a probabilistic data structure whose space complexity does not depend on the number of nodes in a system. If two clocks are not comparable, the bloom clock can always deduce it, i.e. false negatives are not possible. If two clocks are comparable, the bloom clock can calculate the confidence of that statement, i.e. it can compute the false positive rate between comparable pairs of clocks.

See also

References

  1. Colin J. Fidge (February 1988). "Timestamps in Message-Passing Systems That Preserve the Partial Ordering". in K. Raymond. Proc. of the 11th Australian Computer Science Conference (ACSC'88). pp. 56–66. http://zoo.cs.yale.edu/classes/cs426/2012/lab/bib/fidge88timestamps.pdf. Retrieved 2009-02-13. 
  2. Mattern, F. (October 1988), "Virtual Time and Global States of Distributed Systems", in Cosnard, M., Proc. Workshop on Parallel and Distributed Algorithms, Chateau de Bonas, France: Elsevier, pp. 215–226 
  3. Francisco Torres-Rojas; Mustaque Ahamad (1999), "Plausible clocks: constant size logical clocks for distributed systems", Distributed Computing 12 (4): 179–195, doi:10.1007/s004460050065, https://www.cc.gatech.edu/fac/Mustaque.Ahamad/pubs/plausible.ps 
  4. Almeida, Paulo; Baquero, Carlos; Fonte, Victor (2008), "Interval Tree Clocks: A Logical Clock for Dynamic Systems", in Baker, Theodore P.; Bui, Alain; Tixeuil, Sébastien, Principles of Distributed Systems, Lecture Notes in Computer Science, 5401, Springer-Verlag, Lecture Notes in Computer Science, pp. 259–274, doi:10.1007/978-3-540-92221-6, ISBN 978-3-540-92220-9, http://gsd.di.uminho.pt/members/cbm/ps/itc2008.pdf 
  5. Almeida, Paulo; Baquero, Carlos; Fonte, Victor (2008), "Interval Tree Clocks: A Logical Clock for Dynamic Systems", Interval Tree Clocks: A Logical Clock for Dynamic Systems, Lecture Notes in Computer Science, 5401, pp. 259, doi:10.1007/978-3-540-92221-6_18, ISBN 978-3-540-92220-9, https://www.researchgate.net/publication/235246938 
  6. Zhang, Yi (2014), "Background Preliminaries: Interval Tree Clock Results", Background Preliminaries: Interval Tree Clock Results, https://cs.uwaterloo.ca/~mkarsten/cs755-F14/presentations/ITC.pdf 
  7. Lum Ramabaja (2019), The Bloom Clock, https://arxiv.org/abs/1905.13064 

External links