Vector clock
Template:Short description Template:Distinguish A vector clock is a data structure used for determining the partial ordering of events in a distributed system and detecting causality violations. Just as in Lamport timestamps, inter-process messages contain the state of the sending process's logical clock. A vector clock of a system of n processes is a vector (equivalently, a 1-dimensional array) of n logical clocks, one clock per process. Besides maintaining its own clock, every process also keeps track of the largest value of each of the other processes' clocks that it has so far been informed of.
The clock updates proceed as follows,[1] where <math>VC_i</math> denotes the value of the vector clock maintained by process <math>i</math>:
- Initially all clocks are zero.
- Each time a process experiences an internal event, it increments its own logical clock in the vector by one. For instance, upon an event at process <math>i</math>, it updates <math>VC_{i}[i] \leftarrow VC_{i}[i] + 1</math>.
- 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) then it pairs the message with a copy of its own vector and finally sends the pair.
- Each time a process receives a message-vector clock pair, 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 pair (for every element). For example, if process <math>P_i</math> receives a message <math>(m, VC_{j})</math> from <math>P_j</math>, it first increments its own logical clock in the vector by one <math>VC_{i}[i]\leftarrow VC_{i}[i]+1</math> and then updates its entire vector by setting <math>VC_{i}[k]\leftarrow \max(VC_{i}[k], VC_{j}[k]), \forall k</math>.
History
Lamport originated the idea of logical Lamport clocks in 1978.[2] However, the logical clocks in that paper were scalars, not vectors. The generalization to vector time was developed several times, apparently independently, by different authors in the early 1980s.[3] At least 6 papers contain the concept.[4] The papers canonically cited in reference to vector clocks are Colin Fidge’s and Friedemann Mattern’s 1988 works, [5][6] as they (independently) established the name "vector clock" and the mathematical properties of vector clocks.[3]
Partial ordering property
Vector clocks allow for the partial causal ordering of events. Defining the following:
- <math>VC(x)</math> denotes the vector clock of event <math>x</math>, and <math>VC(x)_z</math> denotes the component of that clock for process <math>z</math>.
- <math>VC(x) < VC(y) \iff \forall z [VC(x)_z \le VC(y)_z] \land \exists z' [ VC(x)_{z'} < VC(y)_{z'} ]</math>
- In English: <math>VC(x)</math> is less than <math>VC(y)</math>, if and only if <math>VC(x)_z</math> is less than or equal to <math>VC(y)_z</math> for all process indices <math>z</math>, and at least one of those relationships is strictly smaller (that is, <math>VC(x)_{z'} < VC(y)_{z'}</math>).
- <math>x \to y\;</math> denotes that event <math>x</math> happened before event <math>y</math>. It is defined as: if <math>x \to y\;</math>, then <math>VC(x) < VC(y)</math>
Properties:
- Asymmetry: if <math>VC(a) < VC(b)</math>, then ¬<math>(VC(b) < VC(a))</math>
- Transitivity: if <math>VC(a) < VC(b)</math> and <math>VC(b) < VC(c)</math>, then <math>VC(a) < VC(c)</math>; or, if <math>a \to b\;</math> and <math>b \to c\;</math>, then <math>a \to c\;</math>
Relation with other orders
- Let <math>RT(x)</math> be the real time when event <math>x</math> occurs. If <math>VC(a) < VC(b)</math>, then <math>RT(a) < RT(b)</math>
- Let <math>C(x)</math> be the Lamport timestamp of event <math>x</math>. If <math>VC(a) < VC(b)</math>, then <math>C(a) < C(b)</math>
Limitations under Byzantine failures
Vector clocks can reliably detect causality in distributed systems subject to crash failures. However, when processes behave arbitrarily or maliciously—as in the Byzantine failure model—causality detection becomes fundamentally impossible [7] , rendering vector clocks ineffective in such environments. This impossibility result holds for all variants of vector clocks, as it stems from core limitations inherent to the problem of causality detection under Byzantine faults.
Other mechanisms
{{ safesubst:#invoke:Unsubst||date=__DATE__ |$B=Template:AmboxTemplate:Main other }}
- In 1999, Torres-Rojas and Ahamad developed Plausible Clocks,[8] a mechanism that takes less space than vector clocks but that, in some cases, will totally order events that are causally concurrent.
- In 2005, Agarwal and Garg created Chain Clocks,[9] a system that tracks dependencies using vectors with size smaller than the number of processes and that adapts automatically to systems with dynamic number of processes.
- In 2008, Almeida et al. introduced Interval Tree Clocks.[10][11][12] 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 proposed Bloom Clocks, a probabilistic data structure based on Bloom filters.[13][14][15] Compared to a vector clock, the space used per node is fixed and does not depend on the number of nodes in a system. Comparing two clocks either produces a true negative (the clocks are not comparable), or else a suggestion that one clock precedes the other, with the possibility of a false positive where the two clocks are unrelated. The false positive rate decreases as more storage is allowed.
See also
References
External links
- Why Logical Clocks are Easy, Baquero & Preguiça, ACM Queue, April 12, 2016
- Timestamp-based vector clock implementation in Erlang, GitHub
- Vector clock implementation in Objective-C, GitHub
- Vector clock implementation in Erlang, GitHub
- Why Vector Clocks are Easy, Bryan Fink, Riak Blog, January 29, 2010
- Why Vector Clocks are Hard, Justin Sheehy, Riak Blog, April 5, 2010
- Why Cassandra doesn’t need vector clocks, Jonathan Ellis, DataStax Blog, September 1, 2013 (via archive.org)
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ Template:Cite journal
- ↑ 3.0 3.1 Template:Cite journal
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }} The papers are (in chronological order):
- ↑ Template:Cite conference
- ↑ Template:Cite conference
- ↑ Template:Cite conference
- ↑ Template:Citation
- ↑ Template:Cite book
- ↑ Template:Citation
- ↑ Template:Citation
- ↑ Template:Citation
- ↑ Template:Cite journal
- ↑ Template:Citation
- ↑ Template:Cite book