Explaining vector clock rules and causality
Vector clocks track causality by maintaining a vector of counters per process: each process increments its own entry before local events, sends its vector clock with messages, and on receive updates its vector by taking the element-wise max with the received vector and then increments its own entry. This lets processes determine causal order since a vector clock v dominates w if every component of v is ≥ w and at least one is greater, meaning v happened after w; if neither dominates, the events are concurrent. Causal violations are detected by checking if a received message’s vector clock depends on events the receiver hasn't seen—specifically, a message can only be delivered safely if the message’s sender index counter is exactly one more than the receiver’s and all other counters are less than or equal; otherwise, delivering would break causality.
A vector clock associates each event in a distributed system with an (n)–tuple of integers, one counter per process. The standard maintenance rules are:
-
Each process (P_i) keeps its own vector (V) of length (n). Initially all entries are zero.
-
Just before (P_i) timestamps a local event, it increments its own component: (V[i] := V[i]+1).
-
When (P_i) sends a message, it piggy‑backs a copy of its current vector on the message.
-
When (P_j) receives a message carrying vector (M), it first updates its local vector to the element‑wise maximum of the two, i.e. for all (k), (V[k] := \max(V[k], M[k])), and then applies the “local event” rule to reflect the receive event by incrementing (V[j]).
These rules ensure that the “happens‑before” relation is reflected in the vectors: if event (a) causally precedes event (b) ((a\to b)), then (VC(a)[k] \leq VC(b)[k]) for all (k) and at least one component is strictly less. You can use this to reason about ordering:
-
On receipt of a message, you can check its attached clock against your own. If the message’s clock has, for some component, a value greater than what you have seen so far, that indicates the message depends on an event you haven’t observed yet. Protocols such as causal multicast buffer such messages until the condition “for all (k\neq i), (M[k] \leq V[k]) and (M[i] = V[i]+1)” holds; otherwise immediate delivery would violate causal order.
-
Given two arbitrary events with vectors (x) and (y), you compare them component‑wise. If (x) “dominates” (y) (i.e. (x[k]\ge y[k]) for all (k) and (x\neq y)), then (x) happened after (y) in the causal order. If neither vector dominates the other — there are components where (x) is larger and components where (y) is larger — then neither event is causally before the other, and they are concurrent.