Formal Approaches to Distributed Systems Design
3.4 Logical Clocks
3.4.1 Scalar logical clock In this model each process P
i owns a logical clock LC
i (it may be implemented by a counter with no actual timing mechanism). LC
i is initialized to init (≥ 0) and it is a nondecreasing sequence of integers.
Every message m issued by P
i is stamped with the current value of LC
i and with the process label i, producing the triplet (m, LC
i, i).
The updates on LC
i are based on the following two rules:
• Rule
1. Before producing an event (an external send or internal event), we update LC:
(d can have a different value at each application of Rule
1)
Table 3.1Events in Example 3.2 with their logical times.
Events a
2. When it receives the timestamped message (m, LC
j, j), P
i executes the update
We assume that each LC
i is initialized to init (≥ 0) which can have a different value for different processes.
The timestamping method can also be implemented in such a way that logical clocks change only when an external event occurs. This can be done by deleting the internal event condition in the above
algorithm.
With the timestamping method we can determine the logical time for each event in Figure 3.7, see Table 3.1, assuming that d = 1 and init = 0.
It is easy to prove that the timestamping method satisfies the following condition: For any events a, b, if a → b then LC(a) < LC(b) where LC(a) is the logical time associated with the event a. However,
normally the converse condition does not hold, i.e., it is not necessary that a → b when LC(a) < LC(b).
For example, LC(c
0) < LC(a
2) for events c
0 and a
2 in Figure 3.6. However c
0 a
2.
We can also define the following total ordering ⇒, one of many possible orders, on the event set while still satisfying the above condition:
iff
where < is an arbitrary total ordering of the process set, e.g., < can be defined as P
i < P
j iff i < j. With this definition the events in Figure 3.2 can be ordered as:
under the assumption that P
a < P
b < P
c.
The total ordering also provides an interleaving view of a distributed system. Although some system information is lost in such a view compared with the time-space view, the interleaving view can be very useful in implementing several types of distributed algorithms [18]; for example, the distributed mutual exclusion algorithm discussed in a later section.
Previous Table of Contents Next
Copyright © CRC Press LLC
Previous Table of Contents Next
3.4.2 Extensions
The timestamping mechanism discussed uses linear time, i.e., time is represented by an ordinary real number. However, a linear time clock system cannot distinguish between the advancements of clocks due to local events from those due to the exchange of message between processes. Extensions to the timestamping approach include vector time and matrix time. The vector time approach [14] uses n-dimensional vectors of integers to represent time while the matrix time approach [28] uses n × n matrices. The objective of using the vector and matrix is the following:
Based on Rule
2 (in the previous section) each receiving process receives a message together with the logical global time as perceived by the sender at sending time. This allows the receiver to update its view of the global time. Naturally, when information is included in time the receiver has a better and more accurate view of the global time.
In the vector time approach each P
i is associated with a vector LC
i[1..n], where
• LC
i[i] describes the progress of P
i, i.e., its own process.
i’s local view of the logical global time.
Rule1 and Rule
2 are modified as follows for each P
i:
• Rule
1. Before producing an event (an external send or internal event), we update LC
i[i]:
• Rule
2. Each message piggybacks the vector clock of the sender at sending time. When receiving a message (m, LC
j, j), P
i executes the update.
Figure 3.13 An example of vector clocks.
Figure 3.13 shows the progress of vector clocks of Example 3.1 with the increment value d = 1 and initialization value init= 0.
When d = 1 and init = 0, LC
i[i] counts the number of internal events and LC
i[j] corresponds to the number of events produced by P
j that causally precede the line; LC
i is read at P
i. LC
i(j) - 1 counts the total number of events, including internal ones, that causally precede the receive event.
Let two events a and b be time stamped respectively by LC
i and LC
j. The timestamp associated with an event is the one that is right after this event but before the next event. We have:
and
where
In the matrix time approach each P
i is associated with a matrix LC
i[1..n, 1..n] where
• LC
i[i, i] is the local logical clock.
• LC
i[k, l] represents the view (or knowledge) P
i has about P
k’s knowledge about the local logical clock of P
l. In fact, row LC
i[i,*] is a vector clock, and hence, this row inherits the properties of the vector clock system. In addition, fact. If
then P
i knows that every other process knows its progress until its local time t.
The update of matrix time can be done similarly using Rule
1 and Rule
2. See [21] and [28] for a detailed treatment of this topic. An application of logical time in systems where processes are dynamically generated or deleted can be found in [8]. Basically the dynamic approach considers both process creation and process termination. A computation consists of one or more possibly nested process instances.
• Process creation. If event a and process instance Q occur in process instance P, event b occurs in Q, and Q begins after a, then a → b.
• Process termination. If event a and process instance Q occur in process instance P, event b occurs in Q and a occurs after Q terminates, then b → a.