290 likes | 383 Views
Global State (1). A consistent cut An inconsistent cut. Election Algorithms. The idea behind these algorithm is to have the ability to elect a unique coordinator process from the currently running processes. Some assumptions: Every process has a unique priority number.
E N D
Global State (1) • A consistent cut • An inconsistent cut
Election Algorithms • The idea behind these algorithm is to have the ability to elect a unique coordinator process from the currently running processes. • Some assumptions: • Every process has a unique priority number. • It can be a concatenated with the IP address and the process' priority number. • However, this may not be desirable especially if the process' IP address is a high number
Election Algorithms • Some more assumptions: • Whenever an election is held, the process with the highest priority number will be elected. • When the failed leader recovers, it can take appropriate action to rejoin the set of active processes. When it returns and if it has the highest priority, it will be the new leader.
Bully Algorithm • Devised by Garcia-Molina, 1982 • Assume every process knows the priority number of every other process in the system. • It is broadcasted so that everyone knows it • Suppose P sends REQUEST to coordinator. • P waits a while so that REQUEST times out (the coordinator times out) • P assumes the coordinator has failed • P then initiates an election
Bully Algorithm • To initiate an election: • P sends an ELECTION message to every process with a higher process ID. • If no one responds, P wins the election and becomes the coordinator • If one of the higher-up processes answers, it takes over. P waits for the final response from the new coordinator
Bully Algorithm • If P receives and ELECTION message • This means that some other process below me is holding an election • P sends a response to the sending process • P holds an election (as above) if it is not already holding one • The election process gradually move to the process with the highest priority number
Bully Algorithm • How a recovered process rejoins the system: • If a failed process recovers then it initiates an election. • Even if it's the bottom process, it still initiates an election so that it can identify who the coordinator is.
The Bully Algorithm Example • The bully election algorithm • Process 4 holds an election • Process 5 and 6 respond, telling 4 to stop • Now 5 and 6 each hold an election
Bully Algorithm Example • Process 6 tells 5 to stop • Process 6 wins and tells everyone
A Ring Algorithm • Election algorithm using a ring.
Mutual Exclusion • The idea of mutual exclusion in distributed systems is to guarantee • that either ab or ba, that is, that a and b are not concurrent • Examples of applications that require this • file sharing in NFS • implementation of distributed shared memory, • The approach can either be centralized or distributed. • A centralized approach requires a central coordinator • it is not fault tolerant since there is a single point of failure, and it can be a performance bottleneck.
Mutual Exclusion: A Centralized Algorithm • Process 1 asks the coordinator for permission to enter a critical region. Permission is granted • Process 2 then asks permission to enter the same critical region. The coordinator does not reply. • When process 1 exits the critical region, it tells the coordinator, when then replies to 2
Ricart and Agrawala Distributed Algorithm • Two processes want to enter the same critical region at the same moment. • Process 0 has the lowest timestamp, so it wins. • When process 0 is done, it sends an OK also, so 2 can now enter the critical region.
Distributed Mutual Exclusion • Next paper: Mamoru Maekawa, "A SQRT(N) Algorithm for mutual exclusion in decentralized systems," ACM Transactions on Computer Systems, Vol. 3, No. 2, May 1985, p. 145-159,
A Token Ring Algorithm • An unordered group of processes on a network. • A logical ring constructed in software.
Comparison • A comparison of three mutual exclusion algorithms.
The Transaction Model (1) • Updating a master tape is fault tolerant.
The Transaction Model (2) • Examples of primitives for transactions.
The Transaction Model (3) • Transaction to reserve three flights commits • Transaction aborts when third flight is unavailable
Transaction are: • Atomic: To the outside world the transaction happens indivisibly • Consistent: The transaction does not violate system invariants • Isolated: Concurrent transactions do not interfere with each other • Durable: Once a transaction commits, the changes are permanent • These properties are the ACID properties of transactions. • Flat transactions are the simplest type of transaction – but are limited because they do not allow partial results to be committed or aborted.
Distributed Transactions • A nested transaction • A distributed transaction
Private Workspace • The file index and disk blocks for a three-block file • The situation after a transaction has modified block 0 and appended block 3 • After committing
Writeahead Log • a) A transaction • b) – d) The log before each statement is executed
Concurrency Control (1) • General organization of managers for handling transactions.
Concurrency Control (2) • General organization of managers for handling distributed transactions.
Serializability (d) • a) – c) Three transactions T1, T2, and T3 • d) Possible schedules
Two-Phase Locking (1) • Two-phase locking.
Two-Phase Locking (2) • Strict two-phase locking.
Pessimistic Timestamp Ordering • Concurrency control using timestamps.