Vector clocks and distributed snapshots

vector clock

A vector clock is a vector composed of the logical clocks of all nodes. For a by NNA distributed system composed of N nodes, the vector clock of each node is a NNN -dimensional vector, expressed as[ C 0 , C 1 , . . . , C n − 1 ] [C_0,C_1,...,C_{n-1}][C0,C1,...,Cn1]

Idea: Let each process know the logical clocks of all other processes in the system, so that the total order relationship can be achieved without additionally specifying the priority of the process.

Calculation method:
for process iii coming,T i [ i ] T_i[i]Ti[ i ] means processiii local logical time.
1. When the processiii When a new event occurs,T i [ i ] = T i [ i ] + 1 T_i[i] = T_i[i] +1Ti[i]=Ti[i]+1 .
2. When the processiiWhen i sends a message, its vector clockT i T_iTiattached to the message.
3. When the process jjAfter receiving the message, j will update the local vector time:T j [ k ] = max ( T j [ k ] , T [ k ] ) T_j[k] = max(T_j[k], T[k])Tj[k]=max(Tj[k],T[k]) ,其中 k ∈ [ 1 , N ] k \in [1,N ] k[1,N ] (T is the vector time attached to the message).

T i < T j     ⇔     ∀ x : T i [ x ] ⩽ T j [ x ]    a n d    ∃ y : T i [ y ] < T j [ y ] T_i < T_j ~~~\Leftrightarrow~~~ \forall x:T_i[x] \leqslant T_j[x] ~~and~~\exists y:T_i[y] < T_j[y] Ti<Tj      x:Ti[x]Tj[x]  and  yTi[y]<Tj[y]

For any two events aaa andbbb a → b    ⇔    T i < T j a\rightarrow b ~~\Leftrightarrow~~ T_i<T_j ab    Ti<Tj

distributed snapshot

How to "take a snapshot" of the system to obtain the global state of the system, which is used to restore the system to a normal state in the past when a failure occurs.

Master Lamport gave an example: a sky full of migratory birds, the scene is too big to be captured in one photo, how to take multiple photos and put them together to form a complete panorama?

Chandy-Lamport Algorithm
1. Initialization: Process P i P_iPiRecord your own status and broadcast marker markermark er to other processes and start recording incoming edge messages .

2. Spread the snapshot: process P j P_jPjReceived marker marker for the first timeAfter the marker message, it will record its own status and start recording other incoming edge messages . ProcessP j P_jPjwill pipe C ij C_{ij}CijThe state of the node is recorded as empty, and the snapshot is broadcast to other processes.

3. Terminate the snapshot: when all incoming edges have received marker markersWhen the mark er message is sent , the snapshot is recorded.

(Once a process receives the marker markerma r k er , then receivemarker markerThe channel of mark er is set to empty, and the process no longer records the messages of this channel )

Guess you like

Origin blog.csdn.net/weixin_46878177/article/details/127648169