Lecture 13 Distributed Transactions Notes adapted from Tanenbaums
Lecture 13: Distributed Transactions Notes adapted from Tanenbaum’s “Distributed Systems Principles and Paradigms” OCT Distributed Transaction 1
Hypothetical Web Service Transaction Begin transaction Book. Trip book plane book hotel book rental car End transaction Book. Trip OCT Distributed Transaction 2
Transactions (ACID) • Atomic: All or nothing. No intermediate states are visible. • Consistent: system invariants preserved, e. g. , if there were n dollars in a bank before a transfer transaction there will be n dollars in the bank after the transfer. • Isolated: Two transactions do not interfere with each other. They appear as serial executions. • Durable: The commit causes a permanent change. OCT Distributed Transaction 3
Client talks to coordinator Different servers Any server Book. Plane Participant Book. Trip Coordinator Recoverable objects needed to book a plane Book. Hotel Participant open. Trans Unique Transaction ID TID Recoverable objects needed to book a hotel. Book. Rental. Car Participant Recoverable objects needed to rent a car. Book. Trip Client TID = open. Transaction() OCT Distributed Transaction 4
Client calls methods Different servers Any server Book. Plane Participant Book. Trip Coordinator Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Call + TID Book. Rental. Car Participant Recoverable objects needed to rent a car. Book. Trip Client plane. book. Flight(111, ”Seat 32 A”, TID) OCT Distributed Transaction 5
Object informs participant The participant only calls join if it has not Different servers already done so. Book. Plane Participant Book. Trip Coordinator Recoverable objects needed to book a plane join(TID, ref to participant) Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Rental. Car Participant Book. Trip Client The participant knows where the coordinator is because that information can be included in the TID (eg. an IP address. ) The coordinator now has a pointer to the OCT Distributed Transaction 6 participant.
Suppose all goes well (1) Different servers Book. Trip Coordinator Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Trip Client Book. Rental. Car Participant Recoverable objects needed to rent a car. OK returned OCT Distributed Transaction 7
Suppose all goes well (2) Different servers Book. Trip Coordinator begins 2 PC and this results in a GLOBAL COMMIT sent to each participant. Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Rental. Car Participant Book. Trip Client Recoverable objects needed to rent a car. OK returned Close. Transaction(TID) Called 8
This time no cars available (1) Different servers Book. Trip Coordinator Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Rental. Car Participant Book. Trip Client Recoverable objects needed to rent a car. OK returned NO CARS AVAIL abort. Transaction(TID) called 9
This time no cars available (2) Different servers Book. Trip Coordinator sends a GLOBAL_ABORT to all particpants Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Rental. Car Participant Book. Trip Client Recoverable objects needed to rent a car. OK returned NO CARS AVAIL abort. Transaction(TID) called 10
This time no cars available (3) Different servers Book. Trip Coordinator abort. Transaction Each participant Gets a GLOBAL_ABORT Book. Trip Client Book. Plane Participant ROLLBACK CHANGES Book. Hotel Participant ROLLBACK CHANGES Book. Rental. Car Participant ROLLBACK CHANGES OK returned NO CARS AVAIL abort. Transaction(TID) 11
Book. Plane Server Crashes after returning ‘OK’ (1) Different servers Book. Trip Coordinator Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Trip Client Book. Rental. Car Participant Recoverable objects needed to rent a car. OK returned OCT Distributed Transaction 12
Book. Plane Server Crashes after returning ‘OK’ (2) Different servers Book. Trip Coordinator excutes 2 PC: Ask everyone to vote. No news from the Book. Plane Participant so multicast a GLOBAL ABORT Book. Plane Participant Recoverable objects needed to book a plane Book. Hotel Participant Recoverable objects needed to book a hotel. Book. Rental. Car Participant Book. Trip Client Recoverable objects needed to rent a car. OK returned Close. Transaction(TID) Called 13
Book. Plane Server Crashes after returning ‘OK’ (3) Different servers Book. Plane Participant Book. Trip Coordinator Recoverable objects needed to book a plane GLOBAl ABORT Book. Hotel Participant ROLLBACK Book. Rental. Car Participant Book. Trip Client ROLLBACK OK returned ROLLBACK Close. Transaction(TID) Called 14
Two-Phase Commit Protocol Book. Plane Vote_Request Book. Trip Coordinator Vote_Commit Vote Request Vote Commit Vote Request Phase 1 Book. Trip coordinator sends a Vote_Request to each Vote Commit process. Each process returns a Vote_Commit or Vote_Abort. Book. Hotel Book. Rental. Car OCT Distributed Transaction 15
Two-Phase Commit Protocol (Gray Book. Plane Global Commit Book. Trip Coordinator ACK Book. Hotel Global Commit ACK Global Commit Book. Rental. Car Phase 2 Book. Trip coordinator ACK checks the votes. If every process votes to commit then so will the coordinator. In that case, it will send a Global_Commit to each process. If any process votes to abort the coordinator sends a GLOBAL_ABORT. Each process waits for a Global_Commit message before committing its part of 16 the transaction.
2 PC Finite State Machine from Tanenbaum Book. Trip Coordinator Init Commit -----Vote-request Participant State has already been saved to permanent storage. Init Vote-request ----------------Vote-commit Vote-abort Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 17
2 PC Blocks in three places If waiting too long for a Vote-Request send a Vote-Abort Init Vote-request --------Vote-commit Vote-request --------Vote-abort Commit -----Vote-request Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 18
2 PC Blocks in three places Init Vote-request If waiting too long --------After Vote-request Vote-commit Send a Global-Abort Vote-request Ready --------wait Vote-abort Vote-commit Vote-abort Global-commit -----------------------Global-abort Global-commit ACK Global-abort --------Commit Abort ACK Commit Abort Commit -----Vote-request OCT Distributed Transaction 19
2 PC Blocks in three places If waiting too long we can’t simply abort! We must wait until the coordinator recovers. We might also make queries on other participants. Init Commit -----Vote-request --------Vote-commit Vote-request --------Vote-abort Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 20
2 PC Blocks in three places If this process learns that another has committed then this process is free to commit. The coordinator must have sent out a Global-commit that did not get to this process. Init Commit -----Vote-request --------Vote-commit Vote-request --------Vote-abort Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 21
2 PC Blocks in three places If this process learns that another has aborted then it too is free to abort. Init Commit -----Vote-request --------Vote-commit Vote-request --------Vote-abort Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 22
2 PC Blocks in three places Init Commit -----Vote-request Vote-abort -------Global-abort Abort wait Suppose this process learns that another process is still in its init state. The coordinator must have crashed while multicasting the Vote-request. It’s safe for this process (and the queried process) to abort. Init Vote-request ----------------Vote-commit Vote-abort Ready Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 23
2 PC Blocks in three places Tricky case: If the queried processes are all still in their ready state what do we know? We have to block and wait until the Coordinator recovers. Init Commit -----Vote-request --------Vote-commit Vote-request --------Vote-abort Ready Vote-abort -------Global-abort Abort wait Vote-commit --------Global-commit Global-abort --------ACK Commit Abort OCT Distributed Transaction Global-commit ---------ACK Commit 24
- Slides: 24