Distributed Transactions Chapter – 13.1-13.4 Vidya Satyanarayanan.

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
L-16 Transactions 1. Important Lessons – Fault Tolerance Terminology & Background  Failure models Byzantine Fault Tolerance  Protocol design  with.
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.
Consistency in distributed systems Distributed systems Lecture # 10 Distributed systems Lecture # 10.
OCT Distributed Transaction1 Lecture 13: Distributed Transactions Notes adapted from Tanenbaum’s “Distributed Systems Principles and Paradigms”
CSS434 Distributed Transactions and Replication
Distributed Systems Fall 2010 Transactions and concurrency control.
Persistent State Service 1 Distributed Object Transactions  Transaction principles  Concurrency control  The two-phase commit protocol  Services for.
©Silberschatz, Korth and Sudarshan19.1Database System Concepts Distributed Transactions Transaction may access data at several sites. Each site has a local.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 11: Transactions Dr. Michael R. Lyu Computer Science & Engineering.
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?
Exercises for Chapter 16: Transactions and Concurrency Control
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.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
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,
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.
University of Tampere, CS Department Distributed Commit.
 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.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 17: Distributed.
 2002 M. T. Harandi and J. Hou (modified: I. Gupta) Distributed Transactions.
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.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Transactions on Replicated Data Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Transactions What is a transaction? (A sequence of server operations that must be carried out atomically ) ACID properties - what are these.
10-Jun-16COMP28112 Lecture 131 Distributed Transactions.
Topics in Distributed Databases Database System Implementation CSE 507 Some slides adapted from Navathe et. Al and Silberchatz et. Al.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Distributed Systems Topic 7: Transactions and Distributed Transactions
Replication and Recovery in Distributed Systems
CSE 486/586 Distributed Systems Concurrency Control --- 3
Slides for Chapter 14: Distributed transactions
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
CIS 720 Concurrency Control.
CSE 486/586 Distributed Systems Concurrency Control --- 3
Presentation transcript:

Distributed Transactions Chapter – Vidya Satyanarayanan

Introduction a distributed transaction refers to a flat or nested transaction that accesses objects managed by multiple servers When a distributed transaction comes to an end – either all of the servers commit the transaction –or all of them abort the transaction. one of the servers is coordinator, it must ensure the same outcome at all of the servers. the ‘two-phase commit protocol’ is the most commonly used protocol for achieving this

Distributed Transaction

Nested Banking Transaction a.withdraw(10) c. deposit(10) b.withdraw(20) d.deposit(20) Client A B C T 1 T 2 T 3 T 4 T D X Y Z T =openTransaction openSubTransaction a.withdraw(10); closeTransaction openSubTransaction b.withdraw(20); openSubTransaction c.deposit(10); openSubTransaction d.deposit(20); client transfers $10 from A to C and then transfers $20 from B to D

The coordinator of a flat distributed transaction Since many servers execute requests in a distributed transaction –when it commits they must communicate with one another to coordinate their actions –a client starts a transaction by sending an openTransaction request to a coordinator in any server (next slide) it returns a TID unique in the distributed system(e.g. server ID + local transaction number) at the end, it will be responsible for committing or aborting it –each server managing an object accessed by the transaction is a participant - it joins the transaction (next slide) a participant keeps track of objects involved in the transaction at the end it cooperates with the coordinator in carrying out the commit protocol –note that a participant can call abortTransaction in coordinator

A flat 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

Atomic commit protocols The atomicity of a transaction requires that at the end, –either all of its operations are carried out or none of them. Two protocols - 1. one-phase atomic commit protocol –the coordinator tells the participants whether to commit or abort –what is the problem with that? –this does not allow one of the servers to decide to abort – it may have discovered a deadlock or it may have crashed and been restarted. 2PC –voting phase: coordinator asks all participants if they can commit if yes, participant records updates in permanent storage and then votes –completion phase: coordinator tells all participants to commit or abort

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. participant interface - canCommit?, doCommit, doAbort coordinator interface - haveCommitted, getDecision

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): 1.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. 2.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.

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 1.Uncertain participant (step 2) has voted yes. it can’t decide on its own  it uses getDecision method to ask coordinator about outcome 2.participant has carried out client requests, but has not had a canCommit?from the coordinator. It can abort unilaterally 3.coordinator delayed in waiting for votes (step 1). It can abort and send doAbort to participants. Time-out actions in the 2PC to avoid blocking forever when a process crashes or a message is lost

Two-phase commit protocol for nested transactions Recall the Fig, top-level transaction T and subtransactions T 1, T 2, T 11, T 12, T 21, T 22 A subtransaction starts after its parent and finishes before it. When a subtransaction completes, it makes an independent decision either to commit provisionally or to abort. –A provisional commit is not the same as being prepared: it is a local decision and is not backed up on permanent storage. –If the server crashes subsequently, its replacement will not be able to carry out a provisional commit. A two-phase commit protocol is needed for nested transactions –it allows servers of provisionally committed transactions that have crashed to abort them when they recover.

Operations in coordinator for nested transactions openSubTransaction(trans) -> subTrans Opens a new subtransaction whose parent is trans and returns a unique subtransaction identifier. getStatus(trans)-> committed, aborted, provisional Asks the coordinator to report on the status of the transaction trans. Returns values representing one of the following: committed, aborted, provisional.  This is the interface of the coordinator of a subtransaction. –It allows it to open further subtransactions –It allows its subtransactions to enquire about its status  Client starts by using OpenTransaction to open a top-level transaction. –This returns a TID for the top-level transaction –The TID can be used to open a subtransaction  The subtransaction automatically joins the parent and a TID is returned.

Transaction T decides whether to commit 1.T 12 has provisionally committed and T 11 has aborted, but the fate of T 12 depends on its parent T 1 and eventually on the top-level transaction, T. 2.Although T 21 and T 22 have both provisionally committed, T 2 has aborted and this means that T 21 and T 22 must also abort. 3.Suppose that T decides to commit although T 2 has aborted, also that T 1 decides to commit although T11 has aborted. 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

canCommit? for hierarchic two-phase commit protocol canCommit?(trans, subTrans) -> Yes / No A call from coordinator to ask the 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 Top-level transaction is coordinator of 2PC (here T). participant list: –the coordinators of all the subtransactions that have provisionally committed –but do not have an aborted ancestor –E.g. T, T1 and T12 in Figure –if they vote yes, they prepare to commit by saving state in permanent store The state is marked as belonging to the top-level transaction Hierarchic 2PC - T asks canCommit? to T 1 and T 1 asks canCommit? to T 12.

canCommit? for flat two-phase commit protocol canCommit?(trans, abortList) -> Yes / No Call from coordinator to participants asking whether it can commit a transaction. Participant replies with its vote Yes / No. Flat 2PC –the coordinator of the top-level transaction sends canCommit? messages to the coordinators of all of the subtransactions in the provisional commit list. –in our example, T sends to the coordinators of T 1 and T 12. –the trans argument is the TID of the top-level transaction –the abortList argument gives all aborted subtransactions e.g. server N has T 12 prov committed and T 21 aborted.

Concurrency control in distributed transactions Each server manages a set of objects and is responsible for ensuring that they remain consistent when accessed by concurrent transactions –therefore, each server is responsible for applying concurrency control to its own objects. –the members of a collection of servers of distributed transactions are jointly responsible for ensuring that they are performed in a serially equivalent manner –therefore if transaction T is before transaction U in their conflicting access to objects at one of the servers then they must be in that order at all of the servers whose objects are accessed in a conflicting manner by both T and U

Locking In a distributed transaction, the locks on an object are held by the server that manages it. –The local lock manager decides whether to grant a lock or make the requesting transaction wait. –it cannot release any locks until it knows that the transaction has been committed or aborted at all the servers involved in the transaction. –the objects remain locked and are unavailable for other transactions during the atomic commit protocol an aborted transaction releases its locks after phase 1 of the protocol.

Interleaving of transactions T and U at servers X and Y in this example, we have –T before U at server X and U before T at server Y different orderings lead to cyclic dependencies and distributed deadlock TU Write(A)at Xlocks A Write(B)at Ylocks B Read(B)at Ywaits for U Read(A)at Xwaits for T

Timestamp ordering concurrency control Single server transactions –coordinator issues a unique timestamp to each transaction before it starts –serial equivalence ensured by committing objects in order of timestamps Distributed transactions –the first coordinator accessed by a transaction issues a globally unique timestamp –as before the timestamp is passed with each object access –the servers are jointly responsible for ensuring serial equivalence that is if T access an object before U, then T is before U at all objects –coordinators agree on timestamp ordering a timestamp consists of a pair.

Timestamp ordering concurrency control (continued) The same ordering can be achieved at all servers even if their clocks are not synchronized –for efficiency it is better if local clocks are roughly synchronized –then the ordering of transactions corresponds roughly to the real time order in which they were started Optimistic concurrency control Recall, each transaction is validated before it is allowed to commit –transaction numbers assigned at start of validation –transactions are serialized according to transaction numbers –validation takes place in phase 1 of 2PC protocol