• Aucun résultat trouvé

On-the-Fly Determination of a Global State Property

To illustrate the use of vector clocks, this section presents an algorithm that deter-mines the first global state of a distributed computation that satisfies a conjunction of stable local predicates.

Conjunction of Stable Local Predicates A predicate is local to a processpi if it is only on local variables ofpi. Let LPi be a predicate local to processpi. The fact that the local stateσi ofpi satisfies the predicate LPi is denotedσi|=LPi.

Let{LPi}1in be a set of nlocal predicates, one per process. (If there is no local predicate for a processpx, we can consider a fictitious local predicate LPx= true satisfied by all local states ofpx.) The predicate

iLPi is a global predicate, called conjunction of local predicates. LetΣ= [σ1, . . . , σn]be a consistent global state. We say thatΣ satisfies the global predicate

iLPi, if

ii|=LPi). This is denotedΣ|=

iLPi.

A predicate is stable if, once true, it remains true forever. Hence, if a local state σisatisfies a local stable predicate LPi, all the local states that followσiinpi’s local history satisfy LPi. Let us observe that, if each local predicate LPi is stable, so is the global predicate

iLPi.

This section presents a distributed algorithm that computes, on the fly and with-out using additional control messages, the first consistent global state that satisfies a conjunction of stable local predicates. The algorithm, which only adds control data to application messages, assumes that the application sends “enough” messages (the meaning of “enough” will appear clearly in the description of the algorithm).

On the Notion of a “First” Global State The consistent global stateΣ defined by a processpi from the vector date firsti[1..n] is the first global state satisfying

iLPi, in the following sense: There is no global stateΣ such that=Σ )|=

iLPi)−→Σ Σ ).

7.2 Vector Time 167

Fig. 7.14 First global state satisfying a global predicate (1)

Where Is the Difficulty Let us consider the execution described in Fig.7.14. The predicates LP1, LP2 and LP3 are satisfied from the local states σ1x, σ2b, andσ3c, respectively. (The fact that they are stable is indicated by a bold line on the corre-sponding process axis.) Not all local states are represented; the important point is thatσ2yis the state ofp2after it has sent the messagem8top1, andσ3zis the state of p3after it has sent the messagem5top2. The first consistent global state satisfying LP1LP2LP3isΣ= [σ1x, σ2y, σ3z].

Using causality created by message exchanges and appropriate information pig-gybacked by messages, the processes can “learn” information related to the predi-cate detection. More explicitly, we have the following when looking at the figure.

• Whenp1receivesm1, it learns nothing about the predicate detection (and simi-larly forp3when it receivesm2).

• When p1 receives m4 (sent by p2), it can learn that (a) the global state [σ10, σ2b, σ30] is consistent and (b) it “partially” satisfies the global predicate, namely,σ2b|=LP2.

• Whenp2 receives the messagem3 (fromp1), it can learn that the global state [σ1a, σ2b, σ30]is consistent and suchσ2a|=LP2. When it later receives the message m5(fromp3), it can learn that the global state[σ1a, σ2b, σ3c]is consistent and such 2b|=LP2)3c|=LP3). Processp3can learn the same when it receives the messagem7(sent byp2).

• Whenp1receives the messagem8 (sent byp2), it can learn that, while LP1is not yet locally satisfied, the global state[σ1a, σ2b, σ3c]is the first consistent global state that satisfies LP2and LP3.

• Finally, whenp1produces the internal event giving rise toσ1x, it can learn that the first consistent global state satisfying the three local predicates is[σ1x, σ2y, σ3z].

The corresponding consistent cut is indicated by a dotted line on the figure.

Let us recall that the vector date of the local stateσ2y is the date of the preceding event, which is the sending ofm8, and this date is piggybacked bym5. Similarly, the date ofσ3zis the date of the sending ofm5.

Another example is given in Fig.7.15. In this case, due to the flow of control created by the exchange of messages, it is only whenp3receivesm3that it can learn

Fig. 7.15 First global state satisfying a global predicate (2)

that[σ1x, σ2y, σ3z]is the first consistent global state satisfying

iLPi. As previously, the corresponding consistent cut is indicated by a dotted line on the figure.

As no control messages are allowed, it is easy to see that, in some scenarios, enough application messages have to be sent after

iLPi is satisfied, in order to compute the vector date of the first consistent global state satisfying the global pred-icate

iLPi.

Local Control Variables In order to implement the determination of the first global state satisfying a conjunction of stable local predicates, each processpi man-ages the following local variables:

vci[1..n]is the local vector clock.

sati is a set, initially empty, of process identities. It has the following meaning:

(jsati)⇔(pi knows thatpjhas entered a local state satisfying LPj).

donei is Boolean, initialized to false, and then set to the value true bypi when LPi becomes satisfied for the first time. As LPi is a stable predicate, donei then keeps that value forever.

firsti is the vector date of the first consistent global state, known by pi, for which all the processes in sati satisfy their local predicate. Initially, firsti = [0, . . . ,0]. Hence,[σ1first[1], . . . , σnfirst[n]]is this global state, and we have∀ jsati: σjfirst[j]|=LPj.

As an example, considering Fig.7.14, afterp1has received the messagem4, we have sat1= {2}and first1= [0, b,0]. After it has received the messagem8, we have sat1= {2,3}and first1= [0, b, c].

The Algorithm The algorithm is described in Fig.7.16. It ensures that if consis-tent global states satisfy

LPi, at least one process will compute the vector date of the first of them. As already indicated, this is under the assumption that the processes send enough application messages.

Before producing a new event,pi always increases its local clock vci[i](lines7, 10, and13). If the eventeis an internal event, and LPi has not yet been satisfied (i.e., doneiis false),pi invokes the operationcheck_lp()(line9). If its current local stateσsatisfies LPi (line1),pi adds its identity to satiand, as it is the first time that

7.2 Vector Time 169 internal operationcheck_lp(σ )is

(1) if|=LPi)then

(2) satisati∪ {i}; firsti[1..n] ←vci[1..n]; doneitrue;

(3) if(sati= {1, . . . , n})then

(4) firsti[1..n]is the vector date of the first global state satisfying

jLPj (5) end if

(6) end if.

when producing an internal eventedo (7) vci[i] ←vci[i] +1;

(8) Produce eventeand move to the next stateσ;

(9) if(¬donei)thencheck_lp(σ )end if.

when sendingMSG(m)topjdo

(10) vci[i] ←vci[i] +1; move to the next local stateσ; (11) if(¬donei)thencheck_lp(σ )end if;

(12) sendMSG(m,vci,sati,firsti)topj. whenMSG(m,vc,sat,first)is received frompjdo

(13) vci[i] ←vci[i] +1; vcimax(vci[1..n],vc[1..n]);

(14) move to the next local stateσ;

(15) if(¬donei)thencheck_lp(σ )end if;

(16) if(satsati)then

(17) satisatisat; firstimax(firsti[1..n],first[1..n]);

(18) if(sati= {1, . . . , n})then

(19) firsti[1..n]is the vector date of the first global state satisfying

jLPj (20) end if

(21) end if.

Fig. 7.16 Detection the first global state satisfying

iLPi(code for processpi)

LPi is satisfied, it defines accordingly firsti as being vci (which is the vector date of the global state associated with the causal past of the eventecurrently produced bypi, line2). Processpi then checks if the consistent global state defined by the vector date firsti(=vci)satisfies the whole global predicate

jLPj (lines3–4). If it is the case,pihas determined the first global state satisfying the global predicate.

If the eventeis the sending of a message bypitopj, before sending the message, processpifirst moves to its next local stateσ(line10), and does the same as ifewas an internal event. The important point is that, in addition to the application message, pi sends topj (line 12) its full current state (from the global state determination point of view), which consists of vci (current vector time at pi), sati (processes whose local predicates are satisfied), and firsti (date of the consistent global state satisfying the local predicates of the processes in sati).

If the eventeis the reception bypi of a message sent bypj,pi updates first its vector clock (line13), and moves to its next local state (line14). As in the previous cases, if LPi has not yet been satisfied,pithen invokescheck_lp()(line15). Finally, ifpi learns something new with respect to local predicates (test of line16), it “adds”

what it knew before (sati and firsti[1..n]) with what it learns (sat and first[1..n]).

The new value of firsti[1..n] is the vector date of the first consistent global state

in which all the local states of the processes in satisat satisfy their local predi-cates. Finally,pi checks if the global state defined by firsti[1..n]satisfies all local predicates (lines18–20).

When looking at the executions described in Figs.7.14and7.15, we have the following. In Fig.7.14, p1 ends the detection at line4 after it has produced the event that gave rise toσ1x. In Fig.7.15,p3ends the detection at line19after it has received the protocol messageMSG(m3,[−,,−],{1,2},[x, y,0]). Just before it receives this message we have sat3= {2,3}and first3= [0, y, z].

7.2.6 Vector Clocks in Action:

Outline

Documents relatifs