Lecture 13: Distributed TransactionsHypothetical Web Service TransactionTransactions (ACID)PowerPoint PresentationSlide 5Object informs participantSuppose all goes well (1)Suppose all goes well (2)This time no cars available (1)This time no cars available (2)This time no cars available (3)Slide 12Slide 13Slide 14Two-Phase Commit ProtocolTwo-Phase Commit Protocol (Gray2PC Finite State Machine from Tanenbaum2PC Blocks in three placesSlide 19Slide 20Slide 21Slide 22Slide 23Slide 24OCT Distributed Transaction 1Lecture 13: Distributed TransactionsNotes adapted from Tanenbaum’s “Distributed Systems Principles and Paradigms”OCT Distributed Transaction 2Hypothetical Web Service TransactionBegin transaction BookTrip book plane book hotel book rental carEnd transaction BookTripOCT Distributed Transaction 3Transactions (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 then 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 4Client talks to coordinatorBookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientopenTransUnique Transaction IDTIDRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.TID = openTransaction() Recoverable objects neededto rent a car.Any serverOCT Distributed Transaction 5Client calls methods BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.Call + TIDplane.bookFlight(111,”Seat32A”,TID)Any serverRecoverable objects neededto rent a car.OCT Distributed Transaction 6BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.Object informs participant The participant knows where the coordinator is because that information can be included inthe TID (eg. an IP address.)The coordinator now has a pointer to the participant.The participant onlycalls join if it has notalready done so.join(TID,ref to participant)OCT Distributed Transaction 7BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.Suppose all goes well (1) OK returnedOK returnedOK returnedRecoverable objects neededto rent a car.OCT Distributed Transaction 8BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.Suppose all goes well (2) OK returnedOK returnedOK returnedCloseTransaction(TID) Called Coordinator begins2PC and this results ina GLOBAL COMMITsent to each participant.Recoverable objects neededto rent a car.OCT Distributed Transaction 9BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.This time no cars available (1)OK returnedOK returnedNO CARS AVAILabortTransaction(TID) calledRecoverable objects neededto rent a car.OCT Distributed Transaction 10BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.This time no cars available (2)OK returnedOK returnedNO CARS AVAILabortTransaction(TID) calledCoordinator sends a GLOBAL_ABORT to allparticpantsRecoverable objects neededto rent a car.OCT Distributed Transaction 11BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientROLLBACK CHANGESROLLBACK CHANGESThis time no cars available (3)OK returnedOK returnedNO CARS AVAIL abortTransaction(TID)abortTransaction Each participantGets a GLOBAL_ABORTROLLBACK CHANGESOCT Distributed Transaction 12BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.BookPlane Server Crashes after returning ‘OK’ (1)OK returnedOK returnedOK returnedRecoverable objects neededto rent a car.OCT Distributed Transaction 13BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane Recoverable objects neededto book a hotel.BookPlane Server Crashes after returning ‘OK’ (2)OK returnedOK returnedOK returnedCloseTransaction(TID) Called Coordinator excutes 2PC:Ask everyone to vote.No news from the BookPlaneParticipant so multicast a GLOBAL ABORTRecoverable objects neededto rent a car.OCT Distributed Transaction 14BookTrip CoordinatorBookPlane ParticipantBookHotel ParticipantBookRentalCar ParticipantDifferent serversBookTrip ClientRecoverable objects neededto book a plane ROLLBACKBookPlane Server Crashes after returning ‘OK’ (3)OK returnedOK returnedOK returnedCloseTransaction(TID) Called ROLLBACKGLOBAl ABORTROLLBACKOCT Distributed Transaction 15Two-Phase Commit ProtocolBookTripCoordinator BookPlaneBookHotelBookRentalCarPhase 1 BookTrip coordinator sends a Vote_Request to each process. Each process returns a Vote_Commit or Vote_Abort.Vote_RequestVote RequestVote RequestVote_CommitVote CommitVote CommitOCT Distributed Transaction 16Two-Phase Commit Protocol (Gray BookTripCoordinator BookPlaneBookHotelBookRentalCarPhase 2 BookTrip coordinator 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 thetransaction.Global CommitACKGlobal CommitACKGlobal CommitACKOCT Distributed Transaction 172PC Finite State Machine from Tanenbaum
View Full Document