Distributed System (4)

Event Ordering

Three types of events:

  • Local computation
  • Sending a message
  • Receiving a message

Happened-Before Relationship

  • e \rightarrow e’ means e happened before e’.
  • e ie\rightarrow_i e' means e happened before ee' , as observed by PiP_{i}

HB rules:

  • If Pi,eie\exists P_{i}, e \rightarrow_{i} e' then eee \rightarrow e' .
  • For any message mm , send (m)(m) \rightarrow receive (m)(m)
  • If eee \rightarrow e' and eee' \rightarrow e'' then eee \rightarrow e''

This is also called “causal” or “potentially causal” ordering.
{: .prompt-info }

if aea \nrightarrow e and eae \nrightarrow a then aea \| e , i.e. a and e are concurrent.

Lamport’s Logical Clock

Algorithm: for each process PiP_i :

  1. init local lock Li=0L_i = 0
  2. Li+=1L_i += 1 before timestamping each event
  3. for each message mm to send, send (m,Li)(m,L_i)
  4. upon receiving (m,t)(m,t)
    • Li=max(t,Li)L_i = \max(t, L_i)
    • Do step (2)

if events eee \to e' , then L(e)<L(e)L(e) < L(e’)

Vector Clocks

Vi[j]V_i[j] is the clock for process PjP_j as maintained by PiP_i

Algorithm: for each process PiP_i :

  1. initializes local clock Vi[]=0V_i[\cdot] = 0
  2. Vi[i]+=1V_i[i] += 1 before timestamping each event.
  3. for each message mm to send, send (m,Vi)(m, V_i)
  4. upon receiving (m,v)(m, v)
    • j:Vi[j]=max(Vi[j],v[j])\forall j : V_i[j] = \max(V_i[j], v[j])
    • Do step (2)

Comparing Vector Timestamps

  • Let V(e)=VV(e)=V and V(e)=VV\left(e'\right)=V'
  • V=VV=V' , iff V[i]=V[i]V[i]=V'[i] , for all i=1,,ni=1, \ldots, n
  • VVV \leq V ', iff V[i]V[i]V[i] \leq V'[i] , for all i=1,,ni=1, \ldots, n
  • V<VV<V' , iff VVV \leq V' and VVV \neq V'
  • e e\rightarrow e' iff V<VV<V'
  • e e\| e' iff (VV\left(V \nless V'\right. and VV)\left.V' \nless V\right)

Global State (or Global Snapshot)

State of each process (and each channel) in the system at a
given instant of time.

definitions

For a process PiP_{i} ,
where events ei0,ei1,\mathbf{e}_i^0, \mathbf{e}_i^1, \ldots occur:

  • history (Pi)=hi=<ei0,ei1,>(P_i) = h_i = <e_i^0, e_i^1, \ldots>
  • prefix history (Pik)=hik=<ei0,ei1,,eik>(P_i^k) = h_i^k = <e_i^0, e_i^1, \ldots, e_i^k>
  • siks_i^k : PiP_i 's state immediately after k-th event.

For a set of process <P1,P2,,Pn><P_1, P_2, \ldots, P_n> ,

  • global history: H=i(hi)H=\cup_i\left(h_i\right)
  • global state: S=i(si)S=\cup_i\left(s_i\right)
  • a cut CH=h1c1h2c2hncnC \subseteq H=h_1^{c_1} \cup h_2^{c_2} \cup \ldots \cup h_n^{c_n}
  • the frontier of C={eici,i=1,2,n}C=\{e_i^{c_i}, i=1,2, \ldots n\}

Consistent cut

A cut C is consistent iff

$ eC,if fe then fC\forall e \in C, \text{if } f\to e \text{ then } f \in C $


Distributed System (4)
https://yzzzf.xyz/2024/02/21/distributed-system-4/
Author
Zifan Ying
Posted on
February 20, 2024
Licensed under