• Aucun résultat trouvé

Vector time

Dans le document This page intentionally left blank (Page 75-79)

3 Logical time

3.4 Vector time

3.4.1 definition

The system of vector clocks was developed independently by Fidge [4], Mattern [12], and Schmuck [23]. In the system of vector clocks, the time domain is represented by a set ofn-dimensional non-negative integer vectors.

Each processpi maintains a vectorvti1n, wherevtii is the local logical clock ofpi and describes the logical time progress at processpi.vtij rep-resents processpi’s latest knowledge of process pj local time. If vtij=x, then processpiknows that local time at processpj has progressed tillx. The entire vectorvti constitutespi’s view of the global logical time and is used to timestamp events.

Processpiuses the following two rulesR1andR2to update its clock:

R1 Before executing an event, processpi updates its local logical time as follows:

vtii =vtii+d d >0

R2 Each messagemis piggybacked with the vector clockvtof the sender process at sending time. On the receipt of such a message(m,vt), process pi executes the following sequence of actions:

1. update its global logical time as follows:

1≤k≤n vtik =maxvtik vtk 2. executeR1;

3. deliver the messagem.

The timestamp associated with an event is the value of the vector clock of its process when the event is executed. Figure3.2shows an example of vector clocks progress with the increment value d=1. Initially, a vector clock is 000 0.

Figure 3.2 Evolution of vector

The following relations are defined to compare two vector timestamps,vh andvk:

Recall that relation “→” induces a partial order on the set of events that are produced by a distributed execution. If events in a distributed system are timestamped using a system of vector clocks, we have the following property.

If two eventsxandyhave timestampsvhandvk, respectively, then x→y ⇔vh < vk

xy ⇔vhvk

Thus, there is an isomorphism between the set of partially ordered events produced by a distributed computation and their vector timestamps. This is a very powerful, useful, and interesting property of vector clocks.

If the process at which an event occurred is known, the test to compare two timestamps can be simplified as follows: if eventsxandyrespectively occurred at processes pi and pj and are assigned timestamps vh and vk, respectively, then

x→y ⇔ vhi≤vki

xy ⇔ vhi > vki∧vhj < vkj

57 3.4 Vector time

Strong consistency

The system of vector clocks is strongly consistent; thus, by examining the vector timestamp of two events, we can determine if the events are causally related. However, Charron–Bost showed that the dimension of vector clocks cannot be less thann, the total number of processes in the distributed com-putation, for this property to hold [2].

Event counting

Ifdis always 1 in ruleR1, then theithcomponent of vector clock at process pi, vtii, denotes the number of events that have occurred at pi until that instant. So, if an event e has timestamp vh, vhj denotes the number of events executed by process pj that causally precedee. Clearly, vhj−1 represents the total number of events that causally precedeein the distributed computation.

Applications

Since vector time tracks causal dependencies exactly, it finds a wide variety of applications. For example, they are used in distributed debugging, imple-mentations of causal ordering communication and causal distributed shared memory, establishment of global breakpoints, and in determining the consis-tency of checkpoints in optimistic recovery.

A brief historical perspective of vector clocks

Although the theory associated with vector clocks was first developed in 1988 independently by Fidge and Mattern, vector clocks were informally introduced and used by several researchers before this. Parkeret al.[17] used a rudimentary vector clocks system to detect inconsistencies of replicated files due to network partitioning. Liskov and Ladin [11] proposed a vector clock system to define highly available distributed services. Similar system of clocks was used by Strom and Yemini [26] to keep track of the causal dependencies between events in their optimistic recovery algorithm and by Raynal to prevent drift between logical clocks [18]. Singhal [24] used vector clocks coupled with a boolean vector to determine the currency of a critical section execution request by detecting the cusality relation between a critical section request and its execution.

3.4.3 On the size of vector clocks

An important question to ask is whether vector clocks of sizenare necessary in a computation consisting ofn processes. To answer this, we examine the usage of vector clocks.

• A vector clock provides the latest known local time at each other process.

If this information in the clock is to be used to explicitly track the progress at every other process, then a vector clock of sizenis necessary.

• A popular use of vector clocks is to determine the causality between a pair of events. Given any eventseandf, the test fore≺f if and only if Te < Tf, which requires a comparison of the vector clocks ofeandf. Although it appears that the clock of sizenis necessary, that is not quite accurate. It can be shown that a size equal to the dimension of the partial orderE≺is necessary, where the upper bound on this dimension isn.

This is explained below.

To understand this result on the size of clocks for determining causal-ity between a pair of events, we first introduce some definitions. A linear extensionof a partial orderE≺is a linear ordering ofEthat is consistent with the partial order, i.e., if two events are ordered in the partial order, they are also ordered in the linear order. A linear extension can be viewed as projecting all the events from the different processes on a single time axis.

However, the linear order will necessarily introduce ordering between each pair of events, and some of these orderings are not in the partial order. Also observe that different linear extensions are possible in general. Let denote the set of tuples in the partial order defined by the causality relation; so there is a tuplee fin for each pair of eventseandf such thate≺f. Let1, 2 denote the sets of tuples in different linear extensions of this partial order. The set is contained in the set obtained by taking the intersection of any such collection of linear extensions 1,2 . This is because each i must contain all the tuples, i.e., causality dependencies, that are in . Thedimensionof a partial order is the minimum number of linear extensions whose intersection gives exactly the partial order.

Consider a client–server interaction between a pair of processes. Queries to the server and responses to the client occur in strict alternating sequences.

Althoughn=2, all the events are strictly ordered, and there is only one linear order of all the events that is consistent with the “partial” order. Hence the dimension of this “partial order” is 1. A scalar clock such as one implemented by Lamport’s scalar clock rules is adequate to determinee≺f for any events eandf in this execution.

Now consider an execution on processesP1 andP2 such that each sends a message to the other before receiving the other’s message. The two send events are concurrent, as are the two receive events. To determine the causality between the send events or between the receive events, it is not sufficient to use a single integer; a vector clock of size n=2 is necessary. This execution exhibits the graphical property called a crown, wherein there are some messagesm0 mn−1such thatSendmi≺Receivemi+1mod n−1for allifrom 0 ton−1. A crown ofnmessages has dimensionn. We introduced the notion of crown and studied its properties in Chapter6.

For a complex execution, it is not straightforward to determine the dimension of the partial order. Figure3.3shows an execution involving four processes. However, the dimension of this partial order is two. To see this

59 3.5 Efficient implementations of vector clocks

informally, consider the longest chain a b d g h i j. There are events outside this chain that can yield multiple linear extensions. Hence, the dimen-sion is more than 1. The right side of Figure3.3shows the earliest possible and the latest possible occurrences of the events not in this chain, with respect to the events in this chain. Let1bec e f a b d g h i j, which contains the following tuples that are not in:

c a c b c d c g c h c i c j extensions are enough to generate.

Unfortunately, it is not computationally easy to determine the dimension of a partial order. To exacerbate the problem, the above form of analysis has to be completed a posteriori (i.e., off-line), once the entire partial order has been determined after the completion of the execution.

Dans le document This page intentionally left blank (Page 75-79)