Vector Clocks

- by Donna Mitchell

Definition:

Vector Clocks are used in a distributed systems to determine whether pairs of events are causally related. Using Vector Clocks, timestamps are generated for each event in the system, and their causal relationship is determined by comparing those timestamps.

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’s logical time and the last known time of every other process.

Example:

Timestamp for P2:

( P1_Last_Known_Time, P2_Logical_Time, P3_Last_Known_Time)

Book Notation:

Ci refers to the entire timestamp
Ci[k] refers to the kth position in the Ci timestamp

How Vector Clock Timestamps Are Assigned

  1. Events: Every time an event is generated, a process increments its clock and assigns a timestamp to the event based on its knowledge of all the clocks in the system.
  2. Sending messages: When a message is sent the timestamp of the sending event is given to the message.
  3. Receiving messages: When a message is received, the process updates its knowledge of the system clock states by taking the maximum of each component of the message timestamp and its current knowledge of the system clock states. The receiving event gets this new timestamp.

Reading Vector Clock Timestamps

Causally OR Concurrent:

Events a and b are either causally related or they are concurrent.

Definition: "event a" causes "event b" if and only if ta < tb

where:
ta < tb If and only if they meet two conditions:
  1. they are not equal timestamps ( there exists i, ta[i] != tb[i]) and
  2. each ta[i] is less than or equal to tb[i] (for all i, ta[i] <= tb[i])

Examples:

Are the following Concurrent or Causally related?

          Column A             Column B
     1)   (0,1,0)     and      (1,0,0)

     2)   (2,3,1)     and      (0,0,2)

     3)   (2,4,1)     and      (0,0,1)

     4)   (2,4,1)     and      (3,4,1)

Vector Clock Algebra


Test Questions:

  1. What are the advantages of vector clocks over Lamports logical clocks?
  2. If two events are not causally related then they are concurrent. Explain why this is true.
  3. Are the following pairs of timestamps concurrent or causally related?
       (2,3,4) and (1,4,4)
       (1,2,1) and (0,1,1)
       (3,4,1) and (0,0,2)
       
  4. Can two timestamps be equal?
    If yes, give a system example.
    If no, give explanation.

References:

Strom,R.E., and S. Yemini. “Optimistic Recovery in Distributed Systems,” ACM Transactions on Computing Systems, vol.3, no. 3, 1985, pp. 204-226

Go Back to the Operating Systems page.

Written by Donna Mitchell
Converted to HTML by Will Schmidt
Last updated: 21 Feb 1995 / schmidt@cs.vt.edu