10-Jun-16COMP28112 Lecture 131 Distributed Transactions.

Slides:



Advertisements
Similar presentations
University of Tampere, CS Department Distributed Transaction Management Jyrki Nummenmaa
Advertisements

1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
CS542: Topics in Distributed Systems Distributed Transactions and Two Phase Commit Protocol.
Slides for Chapter 13: Distributed transactions
Exercises for Chapter 17: Distributed Transactions
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.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Systems of Distributed Systems Module 2 -Distributed algorithms Teaching unit 3 – Advanced algorithms Ernesto Damiani University of Bozen Lesson 6 – Two.
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)
1 More on Distributed Coordination. 2 Who’s in charge? Let’s have an Election. Many algorithms require a coordinator. What happens when the coordinator.
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?
CS162 Section Lecture 10 Slides based from Lecture and
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.
Distributed Transactions Chapter 13
Lecture 12: Distributed transactions Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Distributed Transactions
CS551 - Lecture 18 1 CS551 Object Oriented Middleware (VII) Advanced Topics (Chap of EDO) Yugi Lee STB #555 (816)
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.
Transactions and Concurrency Control Distribuerade Informationssystem, 1DT060, HT 2013 Adapted from, Copyright, Frederik Hermans.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
XA Transactions.
Distributed Transactions Chapter – Vidya Satyanarayanan.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Two-Phase Commit Brad Karp UCL Computer Science CS GZ03 / M th October, 2008.
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.
Revisiting failure detectors Some of you asked questions about implementing consensus using S - how does it differ from reaching consensus using P. Here.
Introduction to Distributed Databases Yiwei Wu. Introduction A distributed database is a database in which portions of the database are stored on multiple.
A client transaction becomes distributed if it invokes operations in several different Servers There are two different ways that distributed transactions.
TRANSACTION & CONCURRENCY CONTROL 1. CONTENT 2  Transactions & Nested transactions  Methods for concurrency control  Locks  Optimistic concurrency.
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.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Recovery in Distributed Systems:
Two phase commit.
Fault Tolerance - Transactions
Fault Tolerance - Transactions
Fault Tolerance - Transactions
CSE 486/586 Distributed Systems Concurrency Control --- 3
Slides for Chapter 14: Distributed transactions
Distributed Transactions
Distributed Transactions
Fault Tolerance - Transactions
Exercises for Chapter 14: Distributed Transactions
Distributed Transactions
UNIVERSITAS GUNADARMA
Distributed Transactions
Distributed Systems Course Distributed transactions
Distributed Transactions
TRANSACTION & CONCURRENCY CONTROL
CSE 486/586 Distributed Systems Concurrency Control --- 3
Fault Tolerance - Transactions
Presentation transcript:

10-Jun-16COMP28112 Lecture 131 Distributed Transactions

10-Jun-16COMP28112 Lecture 132 Transactions (recap from last time) A set of operations that is either fully committed or aborted as a whole (i.e., the set is treated as an atomic operation); if aborted, no operation in the set is executed: –This guarantees that data will not be left in a corrupted state as a result of (unforeseen) server crashes or other concurrent transactions (cf. client-server example with bank transfer from last lecture). Need to provide: –Concurrency control –Recovery mechanisms

10-Jun-16COMP28112 Lecture 133 Concurrency Control Two-phase locking – “ Acquire locks ” phase Get a read lock before reading Get a write lock before writing Read locks conflict with write locks Write locks conflict with read and write locks – “ Release locks ” phase when the transaction terminates (commit or abort) What does all this remind you of? ( recall COMP25111, thread synchronization: there are some key problems in core Computer Science!) Hmm, if only I was able to lock available hotel and band slots in lab exercise 2… it would make my life easier!

10-Jun-16COMP28112 Lecture 134 Using locks… …concurrent transactions are serialised. Now, think about part 3 of lab exercise 2. Assume that the server allowed you to submit (locked) transactions: Begin transaction get hotel_free_slots; get band_free_slots; slot=find_earliest_common_slot; book_hotel(slot); book_band(slot); End transaction What would the problem be?

10-Jun-16COMP28112 Lecture 135 Disadvantages of locks Reduce significantly the potential for concurrency even though they are really needed in extreme cases. May result in a deadlock! Improvements: –Optimistic concurrency control: transactions are allowed to proceed as normal and everything is checked at the ‘commit transaction’ phase. If there is a problem, transactions are then aborted. –Timestamp ordering: each operation in a transaction is validated when it is carried out. If it cannot be validated, the transaction is aborted immediately.

10-Jun-16COMP28112 Lecture 136 Recovery When a transaction needs to be aborted: Backward recovery: bring the system from its present (erroneous) state into a previously correct state. To do so, the system’s state from time to time is recorded; each time this happens, a checkpoint is said to be made. Forward recovery: try to bring the system to a correct new state from which it can continue to execute. It must know in advance which errors may occur (so that it is possible to correct them!)

10-Jun-16COMP28112 Lecture 137 Recall our Simple Application Example (a client communicating with a remote server) Transfer £100 from account 1 to account 2 x = read_balance(1); y = read_balance(2); write_balance(1, x - 100); write_balance(2, y + 100);

10-Jun-16COMP28112 Lecture 138 What if the accounts are held in two databases?

10-Jun-16COMP28112 Lecture 139 Transfer Funds Across Databases AcctBal 2400 AcctBal 1200 Transfer £100 from Acct 1 to Acct 2

10-Jun-16COMP28112 Lecture 1310 The Joys of Distributed Computing More problems to worry about: – One or both databases can fail at anytime or be slow to respond – Slow or faulty network – How does your distributed application handle these failures?

10-Jun-16COMP28112 Lecture 1311 Distributed transactions to the rescue (transactions where more than one server is involved) ?

10-Jun-16COMP28112 Lecture 1312 Distributed Transactions Transaction Monitor begin_transaction x = read_balance(1); y = read_balance(2); write_balance(1, x - 100); write_balance(2, y + 100); commit; CRASH

10-Jun-16COMP28112 Lecture 1313 All-or-Nothing ALWAYS either – ALL databases commit the transaction or – ALL databases abort the transaction Example of a consensus problem – Everyone MUST agree on a single outcome More generally: – The distributed commit problem: an operation is performed by each member of a process group or none at all.

What protocol do we need to support distributed transactions? (protocol = standard rules regarding the messages exchanged between the servers) Step 1: A coordinator is chosen (figure 14.3 in CDK).. 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

10-Jun-16COMP28112 Lecture 1315 One-phase atomic commit Client tells the coordinator to commit or abort a transaction The coordinator communicates the commit (or abort) to all participants. (obvious) problem: if one of the participants cannot actually perform the operation it cannot tell the coordinator.

10-Jun-16COMP28112 Lecture 1316 Two-Phase Commit ( see Fig in CDK and Fig.8.18 in TvS ) 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 coordinatorparticipant

10-Jun-16COMP28112 Lecture 1317 Drawbacks of Two-Phase-Commit What if the coordinator has failed? –Three-phase commit protocol –Multicast to all other participants Participants need to trust the coordinator Transactions should be short in duration Distributed deadlocks may occur!

10-Jun-16COMP28112 Lecture 1318 Conclusion A distributed transaction is a transaction whose activity involves several different servers. Nested transactions may be used for additional concurrency. Atomicity requires that all servers participating in a transaction either all commit it or all abort it. Reading: Coulouris4, Chapter 14; Coulouris5, Chapter 17; Tanenbaum, Sections (too detailed in parts and not transaction-focused)

10-Jun-16COMP28112 Lecture 1319 Some additional information on deadlocks

10-Jun-16COMP28112 Lecture 1320 Deadlocks If we use locking to implement concurrency control in transactions, we can get deadlocks (even within a single server) So we need to discuss: –Deadlock detection within a single system –Distributed deadlock

10-Jun-16COMP28112 Lecture 1321 Deadlock detection A deadlock occurs when there is a cycle in the wait-for graph of transactions for locks There may be more than one Resolve the deadlock by aborting one of the transactions …. E.g. the youngest, or the one involved in more than one cycle, or can even use “priority” ….

10-Jun-16COMP28112 Lecture 1322 CDK Figure A cycle in a wait-for graph B A Waits for Held by T U U T Waits for

10-Jun-16COMP28112 Lecture 1323 Distributed Deadlock Within a single server, allocating and releasing locks can be done so as to maintain a wait-for graph which can be periodically checked. With distributed transactions locks are held in different servers – and the loop in the entire wait-for graph will not be apparent to any one server

10-Jun-16COMP28112 Lecture 1324 Distributed deadlock (2) 1 solution is to have a coordinator to which each server forwards its wait-for graph But centralised coordination is not ideal in a distributed system Have problems of phantom deadlocks

25 CDK Figure Distributed deadlock D Waits for Waits for Held by Held by B Waits for Held by X Y Z Held by W U V A C W V U (a)(b)

10-Jun-16COMP28112 Lecture 1326 Phantom deadlocks Information gathered at central coordinator is likely to be out-of-date So a transaction may have released a lock (by aborting) but the global wait-for graph shows it as still holding it! Thus a deadlock might be detected which never existed!

10-Jun-16COMP28112 Lecture 1327 An Alternative: Edge Chasing An alternative to a centralised deadlock checker is “Edge Chasing” or “Path Pushing”. Send a message (probe) containing “T->U” to the server at which U is blocked This message gets forwarded (and added to) if the lock U is waiting for is held by V … If a transaction repeats in the message, the deadlock is detected … E.g, T -> U -> V -> W -> X -> T