vector clock
{{Short description|Algorithm for partial ordering of events and detecting causality in distributed systems}}
{{distinguish|Version vector}}
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 an array/vector of N logical clocks, one clock per process; a local "largest possible values" copy of the global clock-array is kept in each process.
Denote as the vector clock maintained by process , the clock updates proceed as follows:{{Cite web|title=Distributed Systems 3rd edition (2017)|url=https://www.distributed-systems.net/index.php/books/ds3/|access-date=2021-03-21|website=DISTRIBUTED-SYSTEMS.NET|language=en-US}}
- 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 , it updates .
- 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 receives a message from , it first increments its own logical clock in the vector by one and then updates its entire vector by setting .
History
Lamport originated the idea of logical Lamport clocks in 1978.{{Cite journal | last1 = Lamport | first1 = L. |authorlink1=Leslie Lamport| title = Time, clocks, and the ordering of events in a distributed system | doi = 10.1145/359545.359563 | journal = Communications of the ACM | volume = 21 | issue = 7 | pages = 558–565| year = 1978 | s2cid = 215822405 | url=http://research.microsoft.com/users/lamport/pubs/time-clocks.pdf}} 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.{{cite journal |last1=Schwarz |first1=Reinhard |last2=Mattern |first2=Friedemann |title=Detecting causal relationships in distributed computations: In search of the holy grail |journal=Distributed Computing |date=March 1994 |volume=7 |issue=3 |pages=149–174 |doi=10.1007/BF02277859|s2cid=3065996 |url=https://nbn-resolving.org/urn:nbn:de:hbz:386-kluedo-4006 }} At least 6 papers contain the concept.
- {{cite book |last1=Fischer |first1=Michael J. |last2=Michael |first2=Alan |title=Proceedings of the 1st ACM SIGACT-SIGMOD symposium on Principles of database systems - PODS '82 |chapter=Sacrificing serializability to attain high availability of data in an unreliable network |date=1982 |pages=70 |doi=10.1145/588111.588124|isbn=0897910702 |s2cid=8774876 }}
- {{cite journal |last1=Parker |first1=D.S. |last2=Popek |first2=G.J. |last3=Rudisin |first3=G. |last4=Stoughton |first4=A. |last5=Walker |first5=B.J. |last6=Walton |first6=E. |last7=Chow |first7=J.M. |last8=Edwards |first8=D. |last9=Kiser |first9=S. |last10=Kline |first10=C. |title=Detection of Mutual Inconsistency in Distributed Systems |journal=IEEE Transactions on Software Engineering |date=May 1983 |volume=SE-9 |issue=3 |pages=240–247 |doi=10.1109/TSE.1983.236733|s2cid=2483222 }}
- {{cite book |last1=Wuu |first1=Gene T.J. |last2=Bernstein |first2=Arthur J. |title=Proceedings of the third annual ACM symposium on Principles of distributed computing - PODC '84 |chapter=Efficient solutions to the replicated log and dictionary problems |date=1984 |pages=233–242 |doi=10.1145/800222.806750|isbn=0897911431 |s2cid=2384672 }}
- {{cite journal |last1=Strom |first1=Rob |last2=Yemini |first2=Shaula |title=Optimistic recovery in distributed systems |journal=ACM Transactions on Computer Systems |date=August 1985 |volume=3 |issue=3 |pages=204–226 |doi=10.1145/3959.3962|s2cid=1941122 |doi-access=free }}
- {{cite tech report |last1=Schmuck |first1=Frank B. |title=Software clocks and the order of events in a distributed system |date=November 1985 |type=unpublished }}
- {{cite book |last1=Liskov |first1=Barbara |last2=Ladin |first2=Rivka |title=Proceedings of the fifth annual ACM symposium on Principles of distributed computing - PODC '86 |chapter=Highly available distributed services and fault-tolerant distributed garbage collection |date=1986 |pages=29–39 |doi=10.1145/10590.10593|isbn=0897911989 |s2cid=16148617 }}
- {{cite journal |last1=Raynal |first1=Michel |title=A distributed algorithm to prevent mutual drift between n logical clocks |journal=Information Processing Letters |date=February 1987 |volume=24 |issue=3 |pages=199–202 |doi=10.1016/0020-0190(87)90186-4}}
The papers canonically cited in reference to vector clocks are Colin Fidge’s and Friedemann Mattern’s 1988 works,
| access-date = 2009-02-13}}{{cite conference|title=Virtual Time and Global States of Distributed systems|book-title=Proc. Workshop on Parallel and Distributed Algorithms|first=Friedemann|last=Mattern | editor-last=Cosnard | editor-first=M.
| place=Chateau de Bonas, France |date=October 1988 |publisher=Elsevier
| pages=215–226}} as they (independently) established the name "vector clock" and the mathematical properties of vector clocks.
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:
- 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
Other mechanisms
{{Incomplete list|date=June 2023}}
- In 1999, Torres-Rojas and Ahamad developed Plausible Clocks,{{Citation |author1=Francisco Torres-Rojas |author2=Mustaque Ahamad
|title=Plausible clocks: constant size logical clocks for distributed systems |journal=Distributed Computing |volume=12 |issue=4 |year=1999 |pages=179–195 |doi=10.1007/s004460050065 |s2cid=2936350
|url=https://www.cc.gatech.edu/fac/Mustaque.Ahamad/pubs/plausible.ps}} 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,{{cite book |last1=Agarwal |first1=Anurag |last2=Garg |first2=Vijay K. |title=Proceedings of the twenty-fourth annual ACM symposium on Principles of distributed computing |chapter=Efficient dependency tracking for relevant events in shared-memory systems |date=17 July 2005 |pages=19–28 |doi=10.1145/1073814.1073818 |chapter-url=http://users.ece.utexas.edu/~garg/dist/agarwal-garg-DC.pdf |access-date=21 April 2021 |publisher=Association for Computing Machinery|isbn=1-58113-994-2 |s2cid=11779779 }} 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.{{Citation |
last1=Almeida | first1=Paulo | last2=Baquero | first2=Carlos | last3=Fonte | first3=Victor |
contribution=Interval Tree Clocks: A Logical Clock for Dynamic Systems |
title=Principles of Distributed Systems |
volume=5401 |
publisher=Springer-Verlag, Lecture Notes in Computer Science |
year=2008 | doi=10.1007/978-3-540-92221-6 |
url=http://gsd.di.uminho.pt/members/cbm/ps/itc2008.pdf |
pages=259–274 |
series=Lecture Notes in Computer Science | bibcode=2008LNCS.5401.....B |
editor1-last=Baker |
editor1-first=Theodore P. |
editor2-last=Bui |
editor2-first=Alain |
editor3-last=Tixeuil |
editor3-first=Sébastien |
isbn=978-3-540-92220-9 }}{{Citation | last1=Almeida | first1=Paulo | last2=Baquero | first2=Carlos | last3=Fonte | first3=Victor | title=Interval Tree Clocks: A Logical Clock for Dynamic Systems | volume=5401 | pages=259 | contribution=Interval Tree Clocks: A Logical Clock for Dynamic Systems | year=2008 | doi=10.1007/978-3-540-92221-6_18 | url=https://www.researchgate.net/publication/235246938 | series=Lecture Notes in Computer Science | isbn=978-3-540-92220-9 | hdl=1822/37748 | hdl-access=free }}{{Citation | last1=Zhang | first1=Yi | title=Background Preliminaries: Interval Tree Clock Results | contribution=Background Preliminaries: Interval Tree Clock Results | year=2014 | url=https://cs.uwaterloo.ca/~mkarsten/cs755-F14/presentations/ITC.pdf }} 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.{{cite journal |last1=Pozzetti |first1=Tommaso |last2=Kshemkalyani |first2=Ajay D. |title=Resettable Encoded Vector Clock for Causality Analysis With an Application to Dynamic Race Detection |journal=IEEE Transactions on Parallel and Distributed Systems |date=1 April 2021 |volume=32 |issue=4 |pages=772–785 |doi=10.1109/TPDS.2020.3032293|s2cid=220362525 |doi-access=free }}{{Citation |author1=Lum Ramabaja |title=The Bloom Clock |year=2019 |arxiv=1905.13064 |bibcode=2019arXiv190513064R }}{{cite book |last1=Kulkarni |first1=Sandeep S |last2=Appleton |first2=Gabe |last3=Nguyen |first3=Duong |title=Proceedings of the 23rd International Conference on Distributed Computing and Networking |chapter=Achieving Causality with Physical Clocks |date=4 January 2022 |pages=97–106 |doi=10.1145/3491003.3491009|arxiv=2104.15099 |isbn=9781450395601 |s2cid=233476293 }} 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
{{Reflist|30em}}
External links
- [http://queue.acm.org/detail.cfm?id=2917756 Why Logical Clocks are Easy (Compares Causal Histories, Vector Clocks and Version Vectors)]
- [http://basho.com/why-vector-clocks-are-easy/ Explanation of Vector clocks]
- [https://github.com/cliffmoon/dynomite/blob/master/elibs/vector_clock.erl Timestamp-based vector clock implementation in Erlang]
- [https://github.com/jeremytregunna/JVectorClock Vector clock implementation in Objective-C]
- [https://github.com/basho/riak_core/blob/master/src/vclock.erl Vector clock implementation in Erlang]
- [http://basho.com/why-vector-clocks-are-hard/ Why Vector Clocks are Hard]
- [http://www.datastax.com/dev/blog/why-cassandra-doesnt-need-vector-clocks Why Cassandra doesn’t need vector clocks]
{{DEFAULTSORT:Vector Clock}}