Lamport-Chandy Algorithm
Motivation
提出一個演算法,可以對distributed system的state做snapshot
,並可以解決兩個問題:
- Stable Property Detection
- Checkpoint
而 Lamport-Chandy algorithm
只要對每個node的state
做snapshot,就可以合成一個 global state
。
Stable Property Detection
如果某個property
的值變成true
,在它的值就一直會保持在true
,不會再改變了,例如系統是否deadlock
,某個計算是否完成等。
藉由此演算法,我們可以藉由對系統做snapshot,來做stable property detection
。
Prerequisite
- channels have
infinite
buffer - Delay 時間隨然隨意,但是不是
infinite
- channel裡的mesaage
order
是順序的 - channel 是有directed
- channel 整個graph是 strongly conntected
Global State of a distributed system
Define event ,其中:
- : process p in global state
- : is a channel, 如果 是 的 input channel,則 從 中消除,如果 是 的output channel,則把放到channel尾端
- : 的當下state
- : 的下一個state
next function
我們定義一個 function使得:
- =
- =
- 把 從 channel移除,如果 是 input channel
- 把 加到channel尾部,如果 是 output channel
而global state = 。
Lamport-Chandy Algorithm
Marker
每次要snapshot
(record global state
),會由發起者process 發送一個marker
,這是一個特別的message,當其他 process 收到marker
message,也會record state。
Marker-Sending Rule
在發送之前 marker
之前會record自身的state,而且在record state前,不會再發送其他message
。
Marker-Receiving Rule
如果 收到marker
的process 還沒有record state,則:
q records its state;
q records channel c state as the empty sequence
如果已經 record state,則:
q records channel c state 在做p作完record之後,收到 marker之前的狀態
proof
接著要證明,藉由上面的marker
作法,我們可以得到系統的 global state
。這邊定義兩種event:prerecording event
和postrecording event
。
- : 如果 在 event 來了之後才record state,稱為
prerecording event
- : 反之,如果 在 event 來之前record state,則 為
postrecording event
。
要證明即使這些events 的順序兌換(event之間無相關性),也不影響最終的結果。
假設 是一個發生在 process 的 postrecording event
,而 是一個發生在 process 的 prerecording event
。
與 必定無相關性,因為:
- 因為 是
postrecording event
,所以marker
早已送出去 - 發生的時候, 還能從 channel c收到message,那代表早收到
marker
,record過state了,那就是postrecording event
而不是prerecording event
,跟假設矛盾,所以 與 無相關性。
因此我們可以重排這些events的順序也不影響最後得到的global state 的結果,故得證。