Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.

Similar presentations


Presentation on theme: "Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of."— Presentation transcript:

1 Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of j

2 Updating Vector Clock Upon creating a local event a at process j –vc.j.j should be increased by 1 –vc.j.k should be unchanged for all other values of k vc.j.j = vc.j.j + 1  k : k  j : vc.j.k = vc.j.k

3 Updating Vector Clock Upon sending message m at process j –vc.j.j should be increased by 1 –vc.j.k should be unchanged for all other values of k –Message should carry this timestamp vc.j.j = vc.j.j + 1  k : k  j : vc.j.k = vc.j.k vc.m = vc.j

4 Updating Vector Clock Upon receiving message m at process j  k :: vc.j.k = max(vc.j.k, vc.m.k) vc.j.j = vc.j.j + 1

5 Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion At any time, at most one process is accessing the resource –Liveness If a process requests for the resource, it can eventually access the resource

6 Solution to mutual exclusion How could we do this if all processes shared a common clock –Each process timestamps its request –The process with lowest timestamp is allowed to access critical section What are the properties of clocks that enable us to solve this problem? Is there another type of clock that could help is to solve this problem

7 Solution to mutual exclusion, based on logical clocks Messages are timestamped with logical clocks Each process maintains a queue of pending requests When process j wants to access the resource, it adds its timestamp to the queue, and sends a request message containing its timestamp to all other processes When process k receives a request message from j, it sends a reply message to j

8 Solution to mutual exclusion, based on logical clocks (continued) Process j accesses the resource (enters critical section) iff –it has received a reply from every other process –its queue does not contain a timestamp that is smaller than its own request After a process is done accessing its critical section, it sends a release message to all processes and removes its own request from the pending queue When a process k receives the release message from j,it removes the entry of j from its pending queue

9 Solution to mutual exclusion, based on logical clocks (continued) This is called Lamport’s mutual exclusion algorithm What is the number of messages sent for every access to critical section?

10 Optimizations Should a process wait for a reply message from every other process? Should a process send a reply message immediately? Answer these questions to obtain a protocol where only 2 (n-1) messages are used for each critical section

11 Classification of Mutual Exclusion Algorithms Quorum Based –Each node is associated with a quorum Q j –When j wants to enter critical section, it asks for permission from all nodes in this quorum –What property should be met by the quorums of different processes? Token Based –A token is circulated among nodes; the node that has the token can access critical section –We will look at these later

12 Which category would Lamport’s protocol fit in? What is the quorum of a process in this algorithm? What are the possibilities of different quorums

13 Taking Quorum Based Algorithms to Extreme Centralized mutual exclusion –A single process `coordinator' is responsible for ensuring –mutual exclusion. –Each process requests the coordinator whenever it wishes to access the resource. –The coordinator permits only one process to access the resource at a time. –After a process accesses the resource, it sends a reply to the coordinator. Quorum for all processes is {c} where c is the coordinator

14 Centralized mutual exclusion Problem : What if the coordinator fails? Solution : Elect a new one

15 Leader Election : Problem Statement Given is a set of n processes, 1.. n. Each process j has variables : –l.j : true iff j is a leader –up.j : true iff j has not failed This is called an auxiliary variable. Requirements –In any state, there is at most one non-failed leader always (up.j  up.k a  l.j  l.k  j = k) –eventually some process is elected a leader eventually (exists j :: up.j  l.j)

16 Bully Algorithm The goal is to choose the process with highest ID as the leader. When a process is repaired or it suspects that the current leader has failed, it starts `election' Election process : –[Step 1 :] Make sure that processes with higher ID have failed –[Step 2 :] If successful, inform all processes with lower ID that a new leader is elected

17 Bully Algorithm (continued) Step 1 –When process j enters the election mode, it sends an `election' message to j+1,.. n. –If process k receives the election message from j, it enters the election mode, sends an OK message to j, and sends election message to k+1, n. –If j receives an OK message, j has lost the election. –If j does not receive any OK message, j can proceed to step 2.

18 Bully Algorithm (continued) Step 2 : When process j enters the second step, it has checked that processes j+1.. n have failed. It needs to make sure that no process in 1..(j-1) is a leader. Process j forces processes (j-1).. 1 to accept j as the leader. Garcia-Molina suggests that this be done using RPC; contact (j-1), (j-2),..., 1.

19 Results So Far Lack of global clocks Logical clocks Vector Clocks Mutual Exclusion Quorum Based Token Based Leader election

20 Homework 1 You must solve this homework by yourself. No outside help from books, internet, other students is permitted. Your solution should be typed. Design a protocol that is an optimization for Lamport’s mutual exclusion. Your protocol should use 2(n-1) messages per access to critical section Consider a system where all communication is broadcast in nature. That is whenever a process sends a message, it sends it to ALL processes. Assume that the number of processes is n. Whenever a process receives a message, it should buffer it in such a way that –Given any two messages m 1 and m 2, if send(m 1 )  send(m 2 ) then m 1 should be delivered before m 2 –Design a protocol that assigns timestamps to messages in such a way as to enable the above delivery requirement. –Hint: Your solution will resemble the algorithm for vector clocks How can be above problem be solved if the communication is not broadcast in nature? Due date: January 24.


Download ppt "Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of."

Similar presentations


Ads by Google