 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Distributed Transactions.

Slides:



Advertisements
Similar presentations
Distributed Systems Course Distributed transactions
Advertisements

CS542: Topics in Distributed Systems Distributed Transactions and Two Phase Commit Protocol.
Slides for Chapter 13: Distributed transactions
Exercises for Chapter 17: Distributed Transactions
CIS 720 Concurrency Control. Timestamp-based concurrency control Assign a timestamp ts(T) to each transaction T. Each data item x has two timestamps:
1 TRANSACTION & CONCURRENCY CONTROL Huỳnh Văn Quốc Phương Thái Thị Thu Thủy
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
Slides for Chapter 10: Distributed transactions
ICS 421 Spring 2010 Distributed Transactions Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/16/20101Lipyeow.
© City University London, Dept. of Computing Distributed Systems / Distributed Systems Session 9: Transactions Christos Kloukinas Dept. of Computing.
CSS434 Distributed Transactions and Replication
Distributed Systems Fall 2010 Transactions and concurrency control.
Non-blocking Atomic Commitment Aaron Kaminsky Presenting Chapter 6 of Distributed Systems, 2nd edition, 1993, ed. Mullender.
Persistent State Service 1 Distributed Object Transactions  Transaction principles  Concurrency control  The two-phase commit protocol  Services for.
Chapter 18: Distributed Coordination (Chapter 18.1 – 18.5)
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 11: Transactions Dr. Michael R. Lyu Computer Science & Engineering.
CS 425 / ECE 428 Distributed Systems Fall 2014 Indranil Gupta (Indy) Lecture 18: Replication Control All slides © IG.
1 ICS 214B: Transaction Processing and Distributed Data Management Distributed Database Systems.
CMPT 401 Summer 2007 Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
Distributed Systems Fall 2009 Distributed transactions.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
Transactions and concurrency control
Distributed Deadlocks and Transaction Recovery.
Distributed Commit Dr. Yingwu Zhu. Failures in a distributed system Consistency requires agreement among multiple servers – Is transaction X committed?
Distributed Transactions March 15, Transactions What is a Distributed Transaction?  A transaction that involves more than one server  Network.
DISTRIBUTED SYSTEMS II AGREEMENT (2-3 PHASE COM.) Prof Philippas Tsigas Distributed Computing and Systems Research Group.
Distributed Transactions: Distributed deadlocks Recovery techniques.
Chapter 19 Recovery and Fault Tolerance Copyright © 2008.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
Distributed Systems CS 425 / CSE 424 / ECE 428 Transactions & Concurrency Control  2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi,
Distributed Transactions Chapter 13
Lecture 12: Distributed transactions Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Distributed Transactions
CSE 486/586 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Transactions CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Nikita Borisov - UIUC Material derived from slides by I. Gupta, M. Harandi,
PAVANI REDDY KATHURI TRANSACTION COMMUNICATION. OUTLINE 0 P ART I : I NTRODUCTION 0 P ART II : C URRENT R ESEARCH 0 P ART III : F UTURE P OTENTIAL 0 R.
Operating Systems Distributed Coordination. Topics –Event Ordering –Mutual Exclusion –Atomicity –Concurrency Control Topics –Event Ordering –Mutual Exclusion.
DISTRIBUTED SYSTEMS II FAULT-TOLERANT AGREEMENT II Prof Philippas Tsigas Distributed Computing and Systems Research Group.
 Distributed file systems having transaction facility need to support distributed transaction service.  A distributed transaction service is an extension.
DISTRIBUTED SYSTEMS II AGREEMENT - COMMIT (2-3 PHASE COMMIT) Prof Philippas Tsigas Distributed Computing and Systems Research Group.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Transactions Chapter – Vidya Satyanarayanan.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
DEADLOCK DETECTION ALGORITHMS IN DISTRIBUTED SYSTEMS
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 17: Distributed.
IM NTU Distributed Information Systems 2004 Distributed Transactions -- 1 Distributed Transactions Yih-Kuen Tsay Dept. of Information Management National.
A client transaction becomes distributed if it invokes operations in several different Servers There are two different ways that distributed transactions.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
TRANSACTION & CONCURRENCY CONTROL 1. CONTENT 2  Transactions & Nested transactions  Methods for concurrency control  Locks  Optimistic concurrency.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
10-Jun-16COMP28112 Lecture 131 Distributed Transactions.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Recovery in Distributed Systems:
Distributed Systems Topic 7: Transactions and Distributed Transactions
CSE 486/586 Distributed Systems Concurrency Control --- 3
Slides for Chapter 14: Distributed transactions
Distributed Transactions
Exercises for Chapter 14: Distributed Transactions
Distributed Databases Recovery
Distributed Transactions
UNIVERSITAS GUNADARMA
Distributed Transactions
Distributed Systems Course Distributed transactions
Distributed Transactions
TRANSACTION & CONCURRENCY CONTROL
Lecture 21: Replication Control
CIS 720 Concurrency Control.
CSE 486/586 Distributed Systems Concurrency Control --- 3
Presentation transcript:

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Distributed Transactions

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Distributed Transactions  A transaction (flat or nested) that invokes operations in several servers. T A Y Z B C D T T1 T2 T11 T12 T21 T22 A B C D F H K Flat Distributed Transaction Nested Distributed Transaction X

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Coordination in Distributed Transactions Each server has a special participant process. Coordinator process resides in one of the servers, talks to trans. and participants. T A Y Z B C D X join Coordinator Participant T Coordinator Open Transacton TID Close Transaction Abort Transaction Participant A a.method (TID, ) 1 2 Join (TID, ref) 3 Coordinator & ParticipantsThe Coordination Process

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Distributed banking transaction.. BranchZ BranchX participant C D Client BranchY B A participant join T a.withdraw(4); c.deposit(4); b.withdraw(3); d.deposit(3); openTransaction b.withdraw(T, 3); closeTransaction T =openTransaction a.withdraw(4); c.deposit(4); b.withdraw(3); d.deposit(3); closeTransaction Note: the coordinator is in one of the servers, e.g. BranchX

 2002 M. T. Harandi and J. Hou (modified: I. Gupta)  Atomicity principle requires that either all the distributed operations of a transaction complete or all abort.  At some stage, client executes closeTransaction(). Now, atomicity requires that either all participants and the coordinator commit or all abort.  What problem statement is this? I. Atomic Commit Problem

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Atomic Commit Protocols  Consensus, but its impossible!  So, assure safety in the implementation.  In a one-phase commit protocol, the coordinator communicates commit or abort to all participants until all acknowledge.  When a client/coordinator requests a commit, it does not allow a server to make a unilateral decision to abort a transaction.  A server may have to abort the transaction, for example, in the case of deadlock.  In a two-phase protocol  First phase involves coordinator collecting commit or abort vote from each participant.  Coordinator decides and multicasts result (any participant can abort its part of the transaction)  On receiving second phase message, participant commits

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Operations for Two-Phase Commit Protocol canCommit?(trans)-> Yes / No Call from coordinator to participant to ask whether it can commit a transaction. Participant replies with its vote. doCommit(trans) Call from coordinator to participant to tell participant to commit its part of a transaction. doAbort(trans) Call from coordinator to participant to tell participant to abort its part of a transaction. haveCommitted(trans, participant) Call from participant to coordinator to confirm that it has committed the transaction. getDecision(trans) -> Yes / No Call from participant to coordinator to ask for the decision on a transaction after it has voted Yes but has still had no reply after some delay. Used to recover from server crash or delayed messages.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) The two-phase commit protocol Phase 1 (voting phase): 1. The coordinator sends a canCommit? request to each of the participants in the transaction. 2. When a participant receives a canCommit? request it replies with its vote (Yes or No) to the coordinator. Before voting Yes, it prepares to commit by saving objects in permanent storage. If the vote is No the participant aborts immediately. Phase 2 (completion according to outcome of vote): 3. The coordinator collects the votes (including its own). (a)If there are no failures and all the votes are Yes the coordinator decides to commit the transaction and sends a doCommit request to each of the participants. (b)Otherwise the coordinator decides to abort the transaction and sends doAbort requests to all participants that voted Yes. 4. Participants that voted Yes are waiting for a doCommit or doAbort request from the coordinator. When a participant receives one of these messages it acts accordingly and in the case of commit, makes a haveCommitted call as confirmation to the coordinator. Recall that server may crash

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Communication in Two-Phase Commit Protocol canCommit? Yes doCommit haveCommitted Coordinator 1 3 (waiting for votes) committed done prepared to commit step Participant 2 4 (uncertain) prepared to commit committed statusstepstatus  To deal with server crashes  Each server saves information relating to the two-phase commit protocol in permanent storage. The information can be retrieved by a new server after a server crash.  To deal with canCommit? loss  The participant may decide to abort unilaterally after a timeout.  To deal with Yes/No loss, the coordinator aborts the transaction after a timeout (pessimistic!). It must annouce doAbort to those who sent in their votes.  To deal with doCommit loss  The participant may wait for a timeout, send a getDecision request (retries until reply received).

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Two Phase Commit (2PC) Protocol Coordinator Participant Execute Precommit Uncertain Send request to each participant Wait for replies (time out possible) Commit Send COMMIT to each participant Abort Send ABORT to each participant Execute Precommit send YES to coordinator Wait for decision Abort Send NO to coordinator NO YES request not ready ready All YES Timeout or a NO Commit Make transaction visible Abort COMMIT decision CloseTrans() ABORT decision

 2002 M. T. Harandi and J. Hou (modified: I. Gupta)  Each server is responsible for applying concurrency control to its objects.  Servers are collectively responsible for serial equivalence of operations.  Locks are held locally, and cannot be released until all servers involved in a transaction have committed or aborted.  Locks are retained during 2PC protocol  Since lock managers work independently, deadlocks are very likely. II. Locks in Distributed Transactions

 2002 M. T. Harandi and J. Hou (modified: I. Gupta)  The wait-for graph in a distributed set of transactions is held partially by each server  To find cycles in a distributed wait-for graph, we can use a central coordinator:  Each server reports updates of its wait-for graph  The coordinator constructs a global graph and checks for cycles  Centralized deadlock detection suffers from usual comm. overhead + bottleneck problems.  In edge chasing, servers collectively make the global wait-for graph and detect deadlocks :  Servers forward “probe” messages to servers in the edges of wait-for graph, pushing the graph forward, until cycle is found. Distributed Deadlocks

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Probes Transmitted to Detect Deadlock V Held by W Waits for Held by Waits for Waits for Deadlock detected U C A B Initiation W  U  V  W W  U W  U  V Z Y X

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Edge Chasing Initiation: When a server S 1 notes that a transaction T starts waiting for another transaction U, where U is waiting to access an object at another server S 2, it initiates detection by sending to S 2. Detection: Servers receive probes and decide whether deadlock has occurred and whether to forward the probes. Resolution: When a cycle is detected, a transaction in the cycle is aborted to break the deadlock. Phantom deadlocks=false detection of deadlocks that don’t actually exist –Can happen if edge disappears after being chased but before deadlock is detected

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Transaction Priority In order to ensure that only one transaction in a cycle is aborted, transactions are given priorities in such a way that all transactions are totally ordered. When a deadlock cycle is found, the transaction with the lowest priority is aborted. Even if several different servers detect the same cycle, only one transaction aborts. Transaction priorities can be used to limit probe messages to be sent only to lower prio. trans. and initiating probes only when higher prio. trans. waits for a lower prio. trans. –Caveat: suppose edges were created in order 3->1, 1->2, 2->3. Deadlock never detected. –Fix: whenever an edge is created, tell everyone about this edge. Detection happens at the first instance the deadlock is created.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) III. 2PC in Nested Transactions  Each (sub)transaction has a coordinator openSubTransaction(trans-id)  subTrans-id getStatus(trans-id)  (committed / aborted / provisional)  Each sub-transaction starts after its parent and finishes before it.  When a sub-transaction finishes, it makes a decision to abort or provisionally commit. (Note that a provisional commit is not the same as being prepared – it is just a local decision and is not backed up on permanent storage.)  When the top-level transaction completes, it does a 2PC with its subs to decide to commit or abort.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Example 2PC in Nested Transactions T T1 T2 T11 T12 T21 T22 A B C D F H K T T1 T2 T11 T12 T21 T22 Nested Distributed Transaction No Abort Yes Provisional Yes Provisional Yes Provisional Yes Provisional No Abort Bottom up decision in 2PC

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) An Example of Nested Transaction 1 2 T 11 T 12 T 22 T 21 abort (at M) provisional commit (at N) provisional commit (at X) aborted (at Y) provisional commit (at N) provisional commit (at P) T T T

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Information Held by Coordinators of Nested Transactions Coordinator of transaction Child transactions ParticipantProvisional commit list Abort list T T 1, T 2 yes T 1, T 12 T 11, T 2 T 1 T 11, T 12 yes T 1, T 12 T 11 T 2 T 21, T 22 no (aborted) T 2 T 11 no (aborted) T 11 T 12, T 21 T 12 but not T 21 T, T 12 T 22 no (parent aborted) T 22 When each sub-transaction was created, it joined its parent transaction. The coordinator of each parent transaction has a list of its child sub-transactions. When a nested transaction provisionally commits, it reports its status and the status of its descendants to its parent. When a nested transaction aborts, it reports abort without giving any information about its descendants. The top-level transaction receives a list of all sub-transactions, together with their status.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Hierarchic Two-Phase Commit Protocol for Nested Transactions canCommit?(trans, subTrans) -> Yes / No Call a coordinator to ask coordinator of child subtransaction whether it can commit a subtransaction subTrans. The first argument trans is the transaction identifier of top-level transaction. Participant replies with its vote Yes / No.  The coordinator of the top-level transaction sends canCommit? to the coordinators of its immediate child sub- transactions. The latter, in turn, pass them onto the coordinators of their child sub-transactions.  Each participant collects the replies from its descendants before replying to its parent.  T sends canCommit? messages to T 1 (but not T 2 which has aborted); T 1 sends CanCommit? messages to T 12 (but not T 11 ).  If a coord. finds no subtrans. matching 2 nd param, then it must have crashed, so it replies NO  Wasteful if coords. shared among subtrans. May take long.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Flat Two-Phase Commit Protocol for Nested Transactions canCommit?(trans, abortList) -> Yes / No Call from coordinator to participant to ask whether it can commit a transaction. Participant replies with its vote Yes / No.  The coordinator of the top-level transaction sends canCommit? Messages to the coordinators of all sub-transactions in the provisional commit list (e.g., T 1 and T 12 ).  If the participant has any provisionally committed transactions that are descendants of the transaction with TID trans:  Check that they do not have any aborted ancestors in the abortList. Then prepare to commit.  Those with aborted ancestors are aborted.  Send a Yes vote to the coordinator.  If the participant does not have a provisionally committed descendent, it must have failed after it performed a provisional commit. Send a NO vote to the coordinator.

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) IV. Transaction Recovery  Recovery is concerned with:  Object (data) durability: saved permanently  Failure Atomicity: effects are atomic even when servers crash  Recovery Manager’s tasks  To save objects (data) on permanent storage for committed transactions.  To restore server’s objects after a crash  To maintain and reorganize a recovery file for an efficient recovery procedure  Garbage collection in recovery file

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) The Recovery File Object Entries Trans. Status Intention List Recovery File T1: PreparedT2: Prepared T1: committed ObjectRef ObjectRef ObjectRef ObjectRef ObjectRef name values name values name values name values name values … …… Transaction Entries

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Transaction T1 Transaction T2 balance = b.getBalance() b.setBalance = (balance*1.1) balance = b.getBalance() b.setBalance(balance*1.1) a.withdraw(balance* 0.1) c.withdraw(balance*0.1) Example: Recovery File a: b:c: 278 c: a: 242 b: A 100 B 200 C 300 A 80 B 220 T1: Preped P0 B 242 T1: Commit p3 C 278 T2: Preped p5 p0 p1 p2 p3p4 p5p6 p7 “Logging”=concatenation Write entries at prepared-to-commit and commit points Writes at commit point are forced

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Using the Recovery File after a Crash When a server recovers, it sets default initial values for objects and then hands over to recovery manager. Recovery manager should apply only those updates that are for committed transactions. Prepared-to-commit transactions are aborted. Recovery manager has two options: 1.Read the recovery file forward and update object values 2.Read the recovery file backwards and update object values Advantage: each object updated at most once Server may crash during recovery Recovery needs to be idempotent Needs save to volatile storage, difficult to achieve (but happens very rarely)

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) The Recovery File for 2PC Object Entries Trans. Status Intention List T1: PreparedT2: Prepared T1: committed ObjectRef ObjectRef ObjectRef ObjectRef ObjectRef name values name values name values name values name values … …… Transaction Entries Coordination Entries Coor’d: T1 Participants list. Status. Par’pant: T1 Coordinator. Status. Coor’d: T2 Participants list. Status. …

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Summary Distributed Transactions –More than one server process (each managing different set of objects) –One server process marked out as coordinator –Atomic Commit: 2PC –Deadlock detection: Edge chasing –2PC commit for nested trans. –Transaction Recovery: Recovery file

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Optional Slides

 2002 M. T. Harandi and J. Hou (modified: I. Gupta) A Different Kind of Edge Chasing T U Wait for Held by Wait for B V Held by Wait for A C X Y Z X: U  V Y: T  U Z: V  T LOCAL Wait-for GRAPHS T U Wait for Held by Wait for B V Held by Wait for A C X Y Z U  V X: U  V T  U  V Y: T  U  V Z: T  U  V  T deadlock detected