src: thumbs.dreamstime.com
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:
- 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) 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.
Video Vector clock
Partial ordering property
Vector clocks allow for the partial causal ordering of events. Defining the following:
- denotes the vector clock of event , and denotes the component of that clock for process .
-
- In English: is less than , if and only if is less than or equal to for all process indices , and at least one of those relationships is strictly smaller (that is, ).
- denotes that event happened before event . It is defined as: if , then
Properties:
- If , then
- Antisymmetry: if , then ¬
- Transitivity: if and , then or if and , then
Relation with other orders:
- Let be the real time when event occurs. If , then
- Let be the Lamport timestamp of event . If , then
Maps Vector clock
Other mechanisms
- Almeida et al., introduced in 2008 Interval Tree Clocks. 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. You can find an implementation of ITC named itc4j here.
- Torres-Rojas and Ahamad, developed in 1999 Plausible Clocks, a mechanism that takes less space than vector clocks but that, in some cases, will totally order events that are causally concurrent.
src: previews.123rf.com
See also
- Lamport timestamps
- Matrix clocks
- Version vector
src: previews.123rf.com
References
src: www.featurepics.com
External links
- Why Logical Clocks are Easy (Compares Causal Histories, Vector Clocks and Version Vectors)
- Explanation of Vector clocks
- Timestamp-based vector clock implementation in Erlang
- Vector clock implementation in Objective-C
- Vector clock implementation in Erlang
- Why Vector Clocks are Hard
- Riak Vector Clocks
- Why Cassandra doesn't need vector clocks
Source of the article : Wikipedia