Two-Phase Commit Brad Karp UCL Computer Science CS GZ03 / M030 20 th October, 2008.

Slides:



Advertisements
Similar presentations
Two phase commit. Failures in a distributed system Consistency requires agreement among multiple servers –Is transaction X committed? –Have all servers.
Advertisements

6.852: Distributed Algorithms Spring, 2008 Class 7.
CS542: Topics in Distributed Systems Distributed Transactions and Two Phase Commit Protocol.
(c) Oded Shmueli Distributed Recovery, Lecture 7 (BHG, Chap.7)
CS 603 Handling Failure in Commit February 20, 2002.
Nummenmaa & Thanish: Practical Distributed Commit in Modern Environments PDCS’01 PRACTICAL DISTRIBUTED COMMIT IN MODERN ENVIRONMENTS by Jyrki Nummenmaa.
COS 461 Fall 1997 Transaction Processing u normal systems lose their state when they crash u many applications need better behavior u today’s topic: how.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 12: Three-Phase Commits (3PC) Professor Chen Li.
Consensus Algorithms Willem Visser RW334. Why do we need consensus? Distributed Databases – Need to know others committed/aborted a transaction to avoid.
CIS 720 Concurrency Control. Timestamp-based concurrency control Assign a timestamp ts(T) to each transaction T. Each data item x has two timestamps:
Computer Science Lecture 18, page 1 CS677: Distributed OS Last Class: Fault Tolerance Basic concepts and failure models Failure masking using redundancy.
E-Transactions: End-to-End Reliability for Three-Tier Architectures Svend Frølund and Rachid Guerraoui.
ICS 421 Spring 2010 Distributed Transactions Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/16/20101Lipyeow.
Distributed Transaction Processing Some of the slides have been borrowed from courses taught at Stanford, Berkeley, Washington, and earlier version of.
© City University London, Dept. of Computing Distributed Systems / Distributed Systems Session 9: Transactions Christos Kloukinas Dept. of Computing.
Transaction Processing Lecture ACID 2 phase commit.
Two phase commit. What we’ve learnt so far Sequential consistency –All nodes agree on a total order of ops on a single object Crash recovery –An operation.
Systems of Distributed Systems Module 2 -Distributed algorithms Teaching unit 3 – Advanced algorithms Ernesto Damiani University of Bozen Lesson 6 – Two.
CS 603 Distributed Transactions February 18, 2002.
Computer Science Lecture 17, page 1 CS677: Distributed OS Last Class: Fault Tolerance Basic concepts and failure models Failure masking using redundancy.
Non-blocking Atomic Commitment Aaron Kaminsky Presenting Chapter 6 of Distributed Systems, 2nd edition, 1993, ed. Mullender.
1 Distributed Databases CS347 Lecture 16 June 6, 2001.
CS 603 Three-Phase Commit February 22, Centralized vs. Decentralized Protocols What if we don’t want a coordinator? Decentralized: –Each site broadcasts.
©Silberschatz, Korth and Sudarshan19.1Database System Concepts Distributed Transactions Transaction may access data at several sites. Each site has a local.
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.
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.
Distributed Commit. Example Consider a chain of stores and suppose a manager – wants to query all the stores, – find the inventory of toothbrushes at.
CMPT 401 Summer 2007 Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
Paxos Made Simple Jinghe Zhang. Introduction Lock is the easiest way to manage concurrency Mutex and semaphore. Read and write locks. In distributed system:
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
Distributed Transactions March 15, Transactions What is a Distributed Transaction?  A transaction that involves more than one server  Network.
Distributed Txn Management, 2003Lecture 3 / Distributed Transaction Management – 2003 Jyrki Nummenmaa
Distributed Algorithms – 2g1513 Lecture 9 – by Ali Ghodsi Fault-Tolerance in Distributed Systems.
Chapter 19 Recovery and Fault Tolerance Copyright © 2008.
Distributed Transactions Chapter 13
Consensus and Its Impossibility in Asynchronous Systems.
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.
Chapter 15 Recovery. Topics in this Chapter Transactions Transaction Recovery System Recovery Media Recovery Two-Phase Commit SQL Facilities.
Distributed Transaction Management, Fall 2002Lecture Distributed Commit Protocols Jyrki Nummenmaa
University of Tampere, CS Department Distributed Commit.
Paxos: Agreement for Replicated State Machines Brad Karp UCL Computer Science CS GZ03 / M st, 23 rd October, 2008.
XA Transactions.
Commit Algorithms Hamid Al-Hamadi CS 5204 November 17, 2009.
Distributed Transactions Chapter – Vidya Satyanarayanan.
Committed:Effects are installed to the database. Aborted:Does not execute to completion and any partial effects on database are erased. Consistent state:
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Replication Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Paxos Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
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.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Paxos Steve Ko Computer Sciences and Engineering University at Buffalo.
Two phase commit.
COS 418: Distributed Systems Lecture 6 Daniel Suo
IS 651: Distributed Systems Consensus
Commit Protocols CS60002: Distributed Systems
Outline Announcements Fault Tolerance.
Fault-tolerance techniques RSM, Paxos
CSE 486/586 Distributed Systems Concurrency Control --- 3
Assignment 5 - Solution Problem 1
Distributed Transactions
Lecture 21: Replication Control
Causal Consistency and Two-Phase Commit
Distributed Databases Recovery
Lecture 21: Replication Control
CSE 486/586 Distributed Systems Concurrency Control --- 3
Presentation transcript:

Two-Phase Commit Brad Karp UCL Computer Science CS GZ03 / M th October, 2008

2 Context: Sharing and Failures Thus far: –NFS: share one filesystem among many clients, with explicit communication, caching, and (weak) consistency –Ivy: share memory among many CPUs, with implicit communication, read-only sharing, and stronger consistency What happens when components in distributed system fail?

3 Challenge: Agreement in Presence of Failures Two servers must each take an action in distributed system Can we ensure they agree to do so? Example: transfer money from bank A to bank B –Debit A, credit B, tell client “OK” Want both to do it or neither to do it Never want only one side to act –Better if nothing happens! Goal: Atomic Commit Protocol

4 Transaction Processing Context: Two Kinds of Atomicity Serializability: –Series of operations requested by users –Outside observer sees them each complete atomically in some complete order –Requires support for locking Recoverability: –Each operation executes completely or not at all; “all-or-nothing semantics” –No partial results Today’s topic: recoverability Assume for now some external entity serializes: Lock server may force transactions to execute one at a time Or maybe only one source of transactions

5 Atomic Commit Is Hard! A -> B: “I’ll commit if you commit” A hears no reply from B Now what? Neither party can make final decision!

6 Straw Man Atomic Commit Protocol Create Transaction Coordinator (TC), single authoritative entity Four entities: client, TC, Bank A, Bank B Client sends “start” to TC TC sends “debit” to A TC sends “credit” to B TC reports “OK” to client client TC BA “start” “credit” “debit” “OK”

7 Failure Scenarios Not enough money in A’s bank account –A doesn’t commit, B does B’s bank account no longer exists –A commits, B doesn’t Network link to B broken –A commits, B doesn’t One of A or B has crashed –Other of A or B commits, A or B doesn’t TC crashes between sending to A and B –A commits, B doesn’t

8 Atomic Commit: Defining Desirable Properties TC, A, and B have separate notions of committing Safety –(Really, “correct execution”) –If one commits, no one aborts –If one aborts, no one commits Liveness: –(In a sense, “performance”) –If no failures, and A and B can commit, then commit –If failures, come to some conclusion ASAP

9 Correct Atomic Commit Protocol TC sends “prepare” messages to A and B A and B respond, saying whether they’re willing to commit If both say “yes,” TC sends “commit” messages If either says “no,” TC sends “abort” messages A and B “decide to commit” if they receive a commit message. –In example, “commit” means “change bank account” client TC BA “start” “prepare” “OK” “yes” “commit”

10 Protocol’s Safety, Liveness? Why is previous protocol correct (i.e., safe)? –Knowledge centralized at TC about willingness of A and B to commit –TC enforces both must agree for either to commit Does previous protocol always complete (i.e., does it exhibit liveness)? –No! What if nodes crash or messages lost?

11 Liveness Problems Timeout –Host is up, but doesn’t receive message it expects –Maybe other host crashed, maybe network dropped message, maybe network down –Usually can’t distinguish these cases, so solution must be correct in all! Reboot –Host crashes, reboots, and must “clean up” –i.e., want to wind up in correct state despite reboot

12 Fixing Timeouts (1) Where in protocol do hosts wait for messages? –TC waits for “yes”/”no” from A and B –A and B wait for “commit”/”abort” from TC Making progress when TC waits for “yes”/”no” –TC not yet sent any “commit” messages –TC can safely abort, send “abort” messages –Preserved safety, sacrificed liveness (how?) –Perhaps both A, B prepared to commit, but a “yes” message was lost –Could have committed, but TC unaware! –Thus, TC is conservative

13 Timeouts (2): Progress when A or B Times Out Awaiting “commit”/”abort” wlog, consider B (A case symmetric) If B voted “no”, can unilaterally abort; TC will never send “commit” in this case What if B voted “yes”? Can B unilaterally abort? –No! e.g., TC might have received “yes” from both, sent “commit” to A, then crashed before sending “commit” to B –Result: A would commit, B would abort; incorrect (unsafe)! Can B unilaterally commit? –No! A might have voted “no”

14 Timeouts (3): Progress when A or B Times Out Awaiting “commit”/”abort” Blocking “solution”: B waits forever for commit/abort from TC Better plan: termination protocol for B if voted “yes”

15 Timeouts (4): Termination Protocol When B Voted “yes” B sends “status” request message to A, asking if A knows whether transaction should commit If no reply from A, no decision; wait for TC If A received “commit” or “abort” from TC, B decides same way; can’t disagree with TC If A hasn’t voted “yes”/”no” yet, B and A both abort –TC can’t have decided “commit”; will eventually hear from A or B If A voted “no”, B and A both abort –TC can’t have decided “commit” If A voted “yes”, no decision possible! –TC might have decided “commit” and replied to client –TC might have timed out and aborted –A and B must wait for TC

16 Timeout Termination Protocol Behavior Some timeouts can be resolved with guaranteed correctness (safety) Sometimes, though, A and B must block –When TC fails, or TC’s network connection fails –Remember: TC is entity with centralized knowledge of A’s and B’s state

17 Problem: Crash-and-Reboot Cannot back out of commit once decided Suppose TC crashes just after deciding and sending “commit” –What if “commit” message to A or B lost? Suppose A and/or B crash just after sending “yes” –What if “yes” message to TC lost? If A or B reboots, doesn’t remember saying “yes”, big trouble! –Might change mind after reboot –Even after everyone reboots, may not be able to decide!

18 Crash-and-Reboot Solution: Persistent State If all nodes know their pre-crash state, can use previously described termination protocol A and B can also ask TC, which may know it committed Preserving state across crashes: –Need non-volatile memory, e.g., a disk –What order: write disk, then send “yes” message if A/B, or “commit” if TC? or vice-versa?

19 Persistent State across Reboots (2) Cannot send message before writing disk –Might then reboot between sending and writing, and change mind after reboot –e.g,. B might send “yes”, then reboot, then decide “no” Can we write disk before sending message? –For TC, write “commit” to disk before sending –For A/B, write “yes” to disk before sending

20 Revised Recovery Protocol using Non-Volatile State TC: after reboot, if no “commit” on disk, abort –No “commit” on disk means you didn’t send any “commit” messages; safe A/B: after reboot, if no “yes” on disk, abort –No “yes” on disk means you didn’t send any “yes” messages, so no one could have committed; safe A/B: after reboot, if “yes” on disk, use ordinary termination protocol –Might block! If everyone rebooted and reachable, can still decide! –Just look at whether TC has “commit” on disk

21 Two-Phase Commit Protocol: Summary of Properties “Prepare” and “commit” phases: Two- Phase Commit (2PC) Properties: –Safety: all hosts that decide reach same decision –Safety: no commit unless everyone says “yes” –Liveness: if no failures and all say “yes,” then commit –Liveness: if failures, then repair, wait long enough, eventually some decision Theorem [Fischer, Lynch, Paterson, 1985]: no distributed asynchronous protocol can correctly agree (provide both safety and liveness) in presence of crash-failures (i.e., if failures not repaired)