Outline • Theoretical Foundations - continued – Lab 1 • Lamport’s algorithm for distributed mutual exclusion – – – – Casual ordering of messages – continued Global state Cuts Termination detection 5/29/2016 COP5611 1 Regarding Lab 1 • For this project, you can work as a team with at most two members per team – Each team only needs to turn in one report – However, all the members are required to understand all the parts as you may be tested on the midterm or the final exam • Three processes – Bank Account Server – Bank Office Clients – Bank Office Mutual Exclusion Processes 5/29/2016 COP5611 2 Lamport’s Clock • Implementation rules – [IR1] Clock Ci is incremented between any two successive events in process Pi Ci := Ci + d ( d > 0) – [IR2] If event a is the sending of message m by process Pi, then message m is assigned a timestamp tm = Ci(a). On receiving the same message m by process Pj, Cj is set to Cj := max(Cj, tm + d) 5/29/2016 COP5611 3 Total Ordering Using Lamport’s Clocks • If a is any event at process Pi and b is any event at process Pj, then a => b if and only if either Ci (a) C j (b) or Ci (a) C j (b) and Pi Pj – Where is any arbitrary relation that totally orders the processes to break ties 5/29/2016 COP5611 4 Lamport’s Distributed Mutual Exclusion Algorithm • This algorithm is based on the total ordering using Lamport’s clocks – Each process keeps a Lamport’s logical clock • Each process is associated with a unique id that can be used to break the ties – In the algorithm, each process keeps a queue, request_queuei, which contains mutual exclusion requests ordered by their timestamp and associated id – Ri of each process consists of all the processes – The communication channel is assumed to be FIFO 5/29/2016 COP5611 5 Lamport’s Distributed Mutual Exclusion Algorithm – cont. 5/29/2016 COP5611 6 Lamport’s Distributed Mutual Exclusion Algorithm – cont. 5/29/2016 COP5611 7 Vector Clocks • Implementation rules – [IR1] Clock Ci is incremented between any two successive events in process Pi Ci[i] := Ci[i] + d ( d > 0) – [IR2] If event a is the sending of message m by process Pi, then message m is assigned a timestamp tm = Ci(a). On receiving the same message m by process Pj, Cj is set to Cj[k] := max(Cj[k], tm[k]) 5/29/2016 COP5611 8 Vector Clocks – cont. • In a system of vector clocks, a b iff t t a b where 5/29/2016 COP5611 9 Causal Ordering of Messages • The causal ordering of messages tries to maintain the same causal relationship that holds among “message send” events with the corresponding “message receive” events – In other words, if Send(M1) -> Send(M2), then Receive(M1) -> Receive(M2) – This is different from causal ordering of events 5/29/2016 COP5611 10 Birman-Schiper-Stephenson Protocol 5/29/2016 COP5611 11 Schiper-Eggli-Sando Protocol 5/29/2016 COP5611 12 Schiper-Eggli-Sando Protocol – cont. 5/29/2016 COP5611 13 Schiper-Eggli-Sando Protocol – cont. 5/29/2016 COP5611 14 Global State 5/29/2016 COP5611 15 Local State • Local state – For a site Si, its local state at a given time is defined by the local context of the distributed application, denoted by LSi. • More notations – mij denotes a message sent by Si to Sj – send(mij) and rec(mij) denote the corresponding sending and receiving event. 5/29/2016 COP5611 16 Definitions – cont. 5/29/2016 COP5611 17 Definitions – cont. 5/29/2016 COP5611 18 Global State – cont. 5/29/2016 COP5611 19 Definitions – cont. Strongly consistent global state: A global state is strongly consistent if it is consistent and transitless 5/29/2016 COP5611 20 Global State – cont. 5/29/2016 COP5611 21 Chandy-Lamport’s Global State Recording Algorithm 5/29/2016 COP5611 22 Cuts of a Distributed Computation • A cut is a graphical representation of a global state – A consistent cut is a graphical representation of a consistent global state • Definition – A cut of a distributed computation is a set C={c1, c2, ...., cn}, where ci is a cut event at site Si in the history of the distributed computation 5/29/2016 COP5611 23 Cuts of a Distributed Computation – cont. 5/29/2016 COP5611 24 Cuts of a Distributed Computation – cont. 5/29/2016 COP5611 25 Cuts of a Distributed Computation – cont. 5/29/2016 COP5611 26 Cuts of a Distributed Computation – cont. 5/29/2016 COP5611 27 Cuts of a Distributed Computation – cont. 5/29/2016 COP5611 28 Termination Detection • Termination detection is to detect when a distributed algorithm is terminated, such as election, a deadlock detection, or token generating algorithm – A process can be active or idle – A computation is said to have terminated if and only if all the processes are idle and there are no messages in transit – Basic idea • We are not going to cover the algorithm in detail 5/29/2016 COP5611 29 Summary • The absence of global time and the absence of shared memory are two main characteristics of distributed systems – Two schemes, Lamport’s logical clocks and vector clocks are used to order events – Two algorithms for causal ordering of messages based on the vector clock-based ideas are discussed – Global states and cuts of a distributed system are also covered – These provide the theoretical foundations for other distributed algorithms 5/29/2016 COP5611 30