pptx

advertisement
MUTUAL EXCLUSION AND
QUORUMS
CS 271
1
Distributed Mutual Exclusion
• Given a set of processes and a single resource,
develop a protocol to ensure exclusive access
to the resource by a single process at a time.
• This is a fundamental operation in operating
systems, and is generalized to locking in
databases.
CS 271
2
Centralized Solution
• Choose a special coordinator site, coord.
• Coord maintains a queue of pending requests.
• Protocol:
– Process send request to coord.
– If no other request, coord sends back reply.
• Otherwise, put request in queue
– On receipt of reply, process accesses resource.
– Once done, process sends release to coord.
– On receipt of release, coord checks queue for any
pending requests.
CS 271
3
Centralized Solution
Queue
P1
P2
request(R)
request(R)
P2
C
reply(R)
P0
request(R)
reply(R)
P1
release(R)
thanks paul krzyzanowski rutgers
CS 271
4
Distributed Solution
• Instead of a central coordinator, all processes
collectively
• Use similar approach:
– Process sends request to all processes and puts request
in local queue.
– On receipt of request, process sends back reply.
– Process accesses resource
• On receipt of all replies
• Own request at head of queue
– Once done, process sends release to all processes.
– On receipt of release, process removes request
CS 271
5
Distributed Solution
• Does this work (Lamport original solution)?
• Need to order queues so they are identical:
– Use logical Lamport time + proc id to break ties.
– FIFO channels
• Requests are executed in causal order.
• Ricart and Agrawala’s optmization:
– If a process also wants resource, it replies only if
request has lower timestamp (higher priority).
– No need for FIFO
CS 271
6
Quorums
• What if there are failures?
• Do we need to communicate with ALL processes?
• Any two requests should have a common process
to act as an arbitrator.
• Let process pi (pj)request permission from Vi (Vj), then
–Vi ⋂ Vj ≠ ϕ.
• Vi is called a quorum.
• Basic protocol still works (basically think locking),
but: Deadlock
CS 271
7
Quorums
• Given n processes: 2|Vi| >n, ie,
• In general, majority, ie ⌈(n/2)⌉. [Gifford 79]
CS 271
8
Studying the Sizes of Quorums
• Can we have quorums of sizes LESS than
majority?
• Yes, but we need to set up some basic ground
rules.
CS 271
9
Maekawa’s Mutual Exclusion
• Assume process pi gets permission from
quorum Qi and there are N processes.
1. Qi contains pi.
2. Equal Effort: |Q1|=|Q2|=…….|Qn|= K
3. Equal Responsibility: Every process is
included in M quorums only.
CS 271
10
Minimality Result
•
•
•
•
•
•
•
•
Each member of Qi is in M-1 other quorums.
Max number of quorums: K(M-1) +1
Since # of quorums = # of processes
N = K(M-1) +1 …………………..(1)
N= (# of elements)/(# duplicates of elements)
N= K*N/M  K=M ………… (2)
From (1) and (2): N= K(K-1) + 1
Hence K= O(√(N))
CS 271
11
Quorum Sizes
• Finite Projective Plane Theory for N points
ensure quorums of size √(n).
• Easier, grid structure and any row and column.
CS 271
12
Quorum Sizes
CS 271
13
Tree Structure
1
2
4
3
5
6
CS 271
7
14
Tree Quorum Algorithm
• A path is a sequence of nodes such that each
node is the parent of the next one in sequence.
1. Select a path from root to leaf.
2. If successful this is the quorum.
3. O.W.  for each inaccessible node, pick two
paths from 2 children to leaves.
4. Repeat recursively for all inaccessible nodes.
Correctness Proof: By Induction.
CS 271
15
Tree Quorum Sizes
• Best case: log(n).
• Worst case: n/2
CS 271
16
General Quorums
• In a database context, we have read and write
operations. Hence, read quorums, Qr, and
write quorums, Qw.
• Simple generalization:
– Qr⋂ Qw ≠ϕ, Qw ⋂ Qw ≠ϕ
– Qr + Qw> n and 2 Qw > n
CS 271
17
Basic Concepts up to now
•
•
•
•
•
Happens before and causality
Logical (Lamport) Clocks
Vector Clocks
Mutual Exclusion
Quorums
CS 271
18
Download