- Asked 2/15
- 2074 Asoj · 2+6 marks
- Model question
Vector clock synchronization algorithm
Short answer
Clock synchronization is needed because clocks drift and events must be ordered consistently. A vector clock is a vector of N counters per process that captures causality exactly: increment own entry on local events, attach vector on send, take element-wise maxima on receive, then increment own entry. Events are concurrent if neither vector is smaller than the other.
Why is clock synchronization necessary? Explain the clock synchronization algorithm using vector clock along with an example. (Define vector clock.)
Why clock synchronization is necessary
Each machine has its own clock, and clocks drift (about 10⁻⁵ to 10⁻⁶ s/s). Without agreement, events recorded on different machines cannot be ordered correctly. Needed for: ordering of transactions and log entries, distributed mutual exclusion and deadlock detection, replica consistency, authentication tickets with expiry, and debugging. When real time is not important but order is, logical clocks such as vector clocks are used.
Vector clock
A vector clock is a logical clock where each of N processes keeps a vector VCi of N integers. VCi[i] counts local events of Pi, and VCi[j] is the number of events of Pj that Pi knows about. It captures causality exactly.
Algorithm
- Initially VCi[j] = 0 for all j.
- For each local event, Pi increments VCi[i] by 1.
- On sending a message, Pi increments VCi[i] and attaches a copy of VCi as timestamp t.
- On receiving a message with t, Pi sets VCi[j] = max(VCi[j], t[j]) for all j, then increments VCi[i].
Comparison: V(a) < V(b) if every V(a)[k] ≤ V(b)[k] and at least one is smaller. Then a → b. If neither vector is smaller, the events are concurrent.
Example with three processes
P1: a(1,0,0) b(2,0,0) e(3,3,0)
\ ^
P2: c(0,1,0) d(2,2,0)--g(2,3,0)-+
P3: f(0,0,1)
- a, b: events at P1 giving (1,0,0), (2,0,0); b sends m1 with (2,0,0).
- c: local event at P2, (0,1,0).
- d: P2 receives m1: max((0,1,0),(2,0,0)) = (2,1,0), then own entry +1 gives (2,2,0).
- g: P2 sends m2 with (2,3,0).
- e: P1 (at (2,0,0)) receives m2: max = (2,3,0), own entry +1 gives (3,3,0).
- f: local event at P3, (0,0,1).
Observations: b (2,0,0) < d (2,2,0), so b → d. c (0,1,0) and a (1,0,0) are incomparable, so concurrent. f (0,0,1) is concurrent with all P1 and P2 events shown.
Compared with Lamport clocks, vector clocks show both causality and concurrency, at the cost of vectors of size N in every message.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Physical clock synchronization algorithm · Distributed System, chapter 5
- Need of logical clock synchronization · Distributed System, chapter 5
- Clock synchronization need; Lamport · Distributed System, chapter 5
- Problems of Lamport's clock; vector clock · Distributed System, chapter 5 · asked 2×
- Lamport's logical clock algorithm · Distributed System, chapter 5 · asked 5×
- Cristian's algorithm · Distributed System, chapter 5 · asked 3×
- Clock synchronization in DFS · Big Data Technologies, chapter 1
- CST steel plate: stiffness, load vector, displacements · Computational Techniques in Civil Engineering, chapter 4
- Condition for constant direction of vector · Mathematics, chapter 5 · asked 6×
- Condition for constant magnitude of vector · Mathematics, chapter 5 · asked 5×