Vector Clocks are used in a distributed systems to determine whether pairs of events are causally related.
Vector Clocks, timestamps are generated for each event in the system, and their causal relationship is
determined by comparing those timestamps.
Vector Clocks, the timestamp for an event is an n-tuple of integers, where n is the number of processes.
Each process assigns a timestamp to each event. The timestamp is composed of that process
logical time and the last known time of every other process.
1 Vector clocks
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 for a process to send a message, it must increment its own clock (as in the bullet above) and then send 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).