SlideShare a Scribd company logo
1 of 40
Download to read offline
2/1/2012 1
6. Two Phase Commit
CSEP 545 Transaction Processing
for E-Commerce
Philip A. Bernstein
Sameh Elnikety
Copyright ©2012 Philip A. Bernstein
2/1/2012 2
Distributed Systems
• Failures
– Links and nodes
– Models
• Algorithms
– Correctness
– Termination
A B
2/1/2012 3
Introduction
• Goal - ensure the atomicity of a transaction that
accesses multiple resource managers.
• (Recall, resource abstracts data, messages, and other
items that are shared by transactions.)
• Why is this hard?
– After a transaction commits at RMa,what if resource
manager RMb fails?
– When RMb recovers, what to do if other resource
managers are down?
– What if a transaction thinks a resource manager failed
and therefore aborted, when it actually is still running?
2/1/2012 4
Assumptions
• Each resource manager independently commits or
aborts a transaction atomically on its resources.
• Home(T) decides when to start committing T.
• Home(T) doesn’t start committing T until T
terminates at all nodes (possibly hard).
• Resource managers fail by stopping.
– No Byzantine failures, where a failed process exhibits
arbitrary behavior, such as sending the wrong message.
2/1/2012 5
Problem Statement
• Transaction T accessed data at resource managers
R1, … Rn.
• The goal is to either
– Commit T at all of R1, … Rn, or
– Abort T at all of R1, … Rn
– Even if resource managers, nodes and communications
links fail during the commit or abort activity.
• That is, never commit at Ri but abort at Rk.
2/1/2012 6
Outline
1. Introduction
2. The Two-Phase Commit (2PC) Protocol
3. 2PC Failure Handling
4. 2PC Optimizations
5. Process Structuring
6. Three Phase Commit
2/1/2012 7
2. Two-Phase Commit
• Two phase commit (2PC) is the standard protocol
for making commit and abort atomic.
• Coordinator - the component that coordinates
commitment at home(T).
• Participant - a resource manager accessed by T.
• A participant P is ready to commit T if all of T’s
after-images at P are in stable storage.
• The coordinator must not commit T until all
participants are ready.
– If P isn’t ready, T commits, and P fails, then P can’t
commit when it recovers.
2/1/2012 8
The Protocol
1 (Begin Phase 1) The coordinator sends a
Request-to-Prepare message to each participant.
2 The coordinator waits for all participants to vote.
3 Each participant
 Votes Prepared if it’s ready to commit
 May vote No for any reason
 May delay voting indefinitely.
4 (Begin Phase 2) If coordinator receives Prepared
from all participants, it decides to commit.
(The transaction is now committed.)
Otherwise, it decides to abort.
2/1/2012 9
The Protocol (cont’d)
5 The coordinator sends its decision to all
participants (i.e., Commit or Abort).
6 Participants acknowledge receipt of Commit or
Abort by replying Done.
2/1/2012 10
Case 1: Commit
Coordinator Participant
Request-to-Prepare
Prepared
Commit
Done
2/1/2012 11
Case 2: Abort
Coordinator
Request-to-Prepare
No
Abort
Done
Participant
2/1/2012 12
Performance
• In the absence of failures, 2PC requires 3
rounds of messages before the decision is made
known to RM’s.
– Request-to-prepare
– Votes (Prepared, No)
– Decision (Commit, Abort).
• Done messages are just for bookkeeping .
– They don’t affect response time.
– They can be batched.
2/1/2012 13
Uncertainty
• Before it votes, a participant can abort unilaterally.
• After a participant votes Prepared and before it receives the
coordinator’s decision, it is uncertain. It can’t unilaterally
commit or abort during its uncertainty period.
Coordinator Participant
Request-to-Prepare
Prepared
Commit
Done
Uncertainty
Period
2/1/2012 14
Uncertainty (cont’d)
• The coordinator is never uncertain.
• If a participant fails or is disconnected from
the coordinator while it’s uncertain,
at recovery it must find out the decision.
2/1/2012 15
The Bad News Theorems
• Uncertainty periods are unavoidable.
• Blocking - a participant must await a repair before
continuing. Blocking is bad.
• Theorem 1 - For every possible commit protocol
(not just 2PC), a communications failure can cause
a participant to become blocked.
• Independent recovery - a recovered participant can
decide to commit or abort without communicating
with other nodes.
• Theorem 2 - No commit protocol can guarantee
independent recovery of failed participants.
2/1/2012 16
3. 2PC Failure Handling
• Failure handling - what to do if the coordinator or
a participant times out waiting for a message.
– Remember, all failures are detected by timeout.
• A participant times out waiting for coordinator’s
Request-to-prepare.
– It decides to abort.
• The coordinator times out waiting for a
participant’s vote.
– It decides to abort.
2/1/2012 17
2PC Failure Handling (cont’d)
• A participant that voted Prepared times out waiting
for the coordinator’s decision
– It’s blocked.
– Use a termination protocol to decide what to do.
– Naïve termination protocol - wait till the coordinator
recovers.
• The coordinator times out waiting for Done.
– It must resolicit them, so it can forget the decision.
2/1/2012 18
Forgetting Transactions
• After a participant receives the decision, it may
forget the transaction.
• After the coordinator receives Done from all
participants, it may forget the transaction.
• A participant must not reply Done until its commit
or abort log record is stable.
– Else, if it fails, then recovers, then asks the coordinator
for a decision, the coordinator may not know.
2/1/2012 19
Logging 2PC State Changes
• Logging may be eager.
– It’s flushed to disk before the next Send Message.
• Or it may be lazy = not eager
Coordinator
Participant
Request-to-Prepare
Prepared
Commit
Done
Log commit
(eager)
Log commit (eager)
Log commit (lazy)
Log prepared (eager)
Log Start2PC
(eager)
2/1/2012 20
Coordinator Recovery
• If the coordinator fails and later recovers, it must know the
decision. It must therefore log:
– The fact that it began T’s 2PC protocol, including the list
of participants, and
– Commit or Abort, before sending Commit or Abort to any
participant (so it knows whether to commit or abort after
it recovers).
• If the coordinator fails and recovers, it resends the decision
to participants from which it doesn’t remember getting Done
– If the participant forgot the transaction, it replies Done
– The coordinator should therefore log Done after it has
received them all.
2/1/2012 21
Participant Recovery
• If a participant P fails and later recovers, it first performs
centralized recovery (Restart).
• For each distributed transaction T that was active at the
time of failure:
– If P is not uncertain about T, then it unilaterally aborts T
– If P is uncertain, it runs the termination protocol
(which may leave P blocked).
• To ensure it can tell whether it’s uncertain, P must log its
vote before sending it to the coordinator.
• To avoid becoming totally blocked due to one blocked
transaction, P should reacquire T’s locks during Restart
and allow Restart to finish before T is resolved.
2/1/2012 22
Heuristic Commit
• Suppose a participant recovers, but the termination
protocol leaves T blocked.
• Operator can guess whether to commit or abort
– Must detect wrong guesses when coordinator recovers.
– Must run compensations for wrong guesses.
• Heuristic commit
– If T is blocked, the local resource manager (actually,
transaction manager) guesses.
– At coordinator recovery, the transaction managers jointly
detect wrong guesses.
2/1/2012 23
4. 2PC Optimizations and Variations
• Optimizations
– Read-only transaction
– Presumed Abort
– Transfer of coordination
– Cooperative termination protocol
• Variations
– Re-infection
– Phase Zero
2/1/2012 24
Read-only Transaction
• A read-only participant need only respond to phase
one. It doesn’t care what the decision is.
• It responds Prepared-Read-Only to
Request-to-Prepare, to tell the coordinator not to
send the decision.
• Limitation - All other participants must be fully
terminated, since the read-only participant will
release locks after voting.
– No more testing of SQL integrity constraints.
– No more evaluation of SQL triggers.
2/1/2012 25
Presumed Abort
• After a coordinator decides Abort and sends Abort to
participants, it forgets about T immediately.
• Participants don’t acknowledge Abort (with Done).
Coordinator
Participant
Request-to-Prepare
Prepared
Abort
Log abort
(forget T)
Log abort (forget T)
Log prepared
Log Start2PC
• If a participant times out waiting for the decision, it asks the
coordinator to retry.
– If the coordinator has no info for T, it replies Abort.
2/1/2012 26
Transfer of Coordination
If there is one participant, you can save a round of messages
1. Coordinator asks participant to prepare and become the
coordinator.
2. The participant (now coordinator) prepares, commits, and
tells the former coordinator to commit.
3. The coordinator commits and replies Done.
Coordinator
Participant
Request-to-Prepare-and
-transfer-coordination
CommitLog commit
Log committed
Log prepared
Done
• Supported by some app servers, but not in any standards.
2/1/2012 27
Cooperative Termination Protocol (CTP)
• Assume coordinator includes a list of participants in
Request-to-Prepare.
• If a participant times-out waiting for the decision,
it runs the following protocol.
1. Participant P sends Decision-Req to other participants.
2. If participant Q voted No or hasn’t voted or received Abort
from the coordinator, it responds Abort.
3. If participant Q received Commit from the coordinator,
it responds Commit.
4. If participant Q is uncertain, it responds Uncertain
(or doesn’t respond at all).
• If all participants are uncertain, then P remains blocked.
2/1/2012 28
Cooperative Termination Issues
• Participants don’t know when to forget T,
since other participants may require CTP
– Solution 1 - After receiving Done from all participants,
coordinator sends End to all participants.
– Solution 2 - After receiving a decision, a participant may
forget T any time.
• To ensure it can run CTP, a participant should
include the list of participants in the vote log record.
2/1/2012 29
Reinfection
• Suppose A is coordinator and B and C are participants
– A asks B and C to prepare.
– B votes prepared.
– C calls B to do some work. (B is reinfected.)
– B does the work and tells C it has prepared,
but now it expects C to be its coordinator.
– When A asks C to prepare, C propagates the request to B
and votes prepared only if both B and C are prepared.
(See Tree of Processes discussion later.)
• Can be used to implement integrity constraint checking,
triggers, and other commit-time processing, without
requiring an extra phase (between phases 1 and 2 of 2PC).
2/1/2012 30
Phase Zero
• Suppose a participant P is caching transaction T’s
updates that P needs to send to an RM (another
participant) before T commits.
– P must send the updates after T invokes Commit, to ensure P
has all of T’s updates
– P must send the updates before the RM prepares, to ensure the
updates are made stable during phase one.
– Thus, we need an extra phase, before phase 1.
• A participant explicitly enlists for phase zero.
– It doesn’t ack phase zero until it finishes flushing its cached
updates to other participants.
• Supported in Microsoft DTC.
2/1/2012 31
5. Process Structuring
• To support multiple RMs on multiple nodes, and minimize
communication, use one transaction manager (TM) per node
• TM may be in the OS (VAX/VMS, Win), the app server
(IBM CICS), DBMS, or a separate product (early Tandem).
• TM performs coordinator and participant roles for all
transactions at its node.
• TM communicates with local RMs and remote TMs.
Transaction Manager
Resource ManagerResource ManagerResource Manager
Application
Enlist and 2PC ops
RM ops
StartTransaction,
Commit, RollbackTX
XA
2PC ops Other
TMs
2/1/2012 32
Enlisting in a Transaction
• When an Application in a transaction T first calls an RM,
the RM must tell the TM it is part of T.
• Called enlisting or joining the transaction
Transaction Manager
Resource Manager
Application
3. Enlist(T)
2. Write(X, T)
1. StartTransaction
(returns Tranction ID)
2/1/2012 33
Enlisting in a Transaction (cont’d)
• When an application A in a transaction T first calls an
application B at another node, B must tell its local TM that
the transaction has arrived.
Transaction
Manager
Communications
Manager
Application A
2. AddBranch(N, T)
1. Call(AP-B, T)
Transaction
Manager
Communications
Manager
Application B
4. StartBranch(N, T)
5. Call(AP-B, T)
3. Send Call(AP-B, T)
Node M Node N
2/1/2012 34
Tree of Processes
• Application calls to RMs and other applications induces a
tree of processes.
• Each internal node is the coordinator for its descendants,
and a participant to its parents.
• This adds delay to two-phase commit.
• Optimization: flatten the tree, e.g. during phase 1
TM1
TM2
TM3
TM4
RM1
RM2 RM3
RM4
RM5
Different
Nodes
2/1/2012 35
Handling Multiple Protocols
• Communication managers solve the problem of handling
multiple 2PC protocols by providing:
– A model for communication between address spaces.
– A wire protocol for two-phase commit.
• But, expect restrictions on multi-protocol interoperation.
• The RM only talks to the TM-RM interface. The multi-
protocol problem is solved by the TM vendor.
Transaction Manager
Resource ManagerResource ManagerResource Manager
Application
Enlist and 2PC ops
RM ops
TX
XA
2PC ops
other
TMs
Communication
Manager
Send/receive msg
XA+
2/1/2012 36
Complete Walkthrough
Application:
Start-trans
Call DBMS
Call remote app
Commit
Application
Comm Mgr
Database
System
Txn Manager
Transaction
Manager
Comm
Manager
8. Req-prepare
9. Prepared
10. Commit
11. Done
1. Start Tran
4. Add-branch
7. Commit
2. Call DBMS
5. Call
6. Start-branch
3. Enlist
DBMS
2/1/2012 37
Customer Checklist
• Does your DBMS support 2PC?
• Does your execution environment support it? If so,
– With what DBMSs?
– Using what protocol(s)?
– Do these protocols meet your interoperation needs?
• Is the TM-DBMS interface open (for home-grown
DBMSs)?
• Can an operator commit/abort a blocked txn?
– If so, is there automated support for reconciling
mistakes?
– Is there automated heuristic commit?
2/1/2012 38
6. Three Phase Commit- The Idea
• 3PC prevents blocking in the absence of communications
failures (unrealistic, but …). It can be made resilient to
communications failures, but then it may block
• 3PC is much more complex than 2PC, but only marginally
improves reliability — prevents some blocking situations.
• 3PC therefore is not used much in practice.
• Main idea: becoming certain and deciding to commit are
separate steps.
• 3PC ensures that if any operational process is uncertain,
then no (failed or operational) process has committed.
• So, in the termination protocol, if the operational processes
are all uncertain, they can decide to abort (avoids blocking).
2/1/2012 39
Three Phase Commit- The Protocol
1. (Begin phase 1) Coordinator C sends Request-to-prepare
to all participants.
2. Participants vote Prepared or No, just like 2PC.
3. If C receives Prepared from all participants, then (begin
phase 2) it sends Pre-Commit to all participants.
4. Participants wait for Abort or Pre-Commit.
Participant acknowledges Pre-commit.
5. After C receives acks from all participants, or times out
on some of them, it (begin third phase) sends Commit to
all participants (that are up).
2/1/2012 40
3PC Failure Handling
• If coordinator times out before receiving Prepared
from all participants, it decides to abort.
• Coordinator ignores participants that don’t ack its
Pre-Commit.
• Participants that voted Prepared and timed out
waiting for Pre-Commit or Commit use the termination
protocol.
• The termination protocol is where the complexity
lies. (E.g. see [Bernstein, Hadzilacos, Goodman 87],
Section 7.4).

More Related Content

What's hot

management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactionsNilu Desai
 
ditributed databases
ditributed databasesditributed databases
ditributed databasesHira Awan
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithmBinal Parekh
 
Two phase commit protocol in dbms
Two phase commit protocol in dbmsTwo phase commit protocol in dbms
Two phase commit protocol in dbmsDilouar Hossain
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memoryJohn Scott Giini
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMSkoolkampus
 
FILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMSFILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMSAbhishek Dutta
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrollubna19
 
Ch02 early system memory management
Ch02 early system  memory managementCh02 early system  memory management
Ch02 early system memory managementJacob Cadeliña
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPTShushrutGupta
 
System programs in o.s. for bca and bscit students by hardik nathani
System programs in o.s. for bca and bscit students by hardik nathaniSystem programs in o.s. for bca and bscit students by hardik nathani
System programs in o.s. for bca and bscit students by hardik nathaniHardik Nathani
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Propertiesnomanbarki
 
Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011sumit_study
 
Transaction concurrency control
Transaction concurrency controlTransaction concurrency control
Transaction concurrency controlAnand Grewal
 

What's hot (20)

management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
Concurrency control
Concurrency control Concurrency control
Concurrency control
 
ditributed databases
ditributed databasesditributed databases
ditributed databases
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
Two phase commit protocol in dbms
Two phase commit protocol in dbmsTwo phase commit protocol in dbms
Two phase commit protocol in dbms
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
 
Memory management
Memory managementMemory management
Memory management
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memory
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
FILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMSFILE STRUCTURE IN DBMS
FILE STRUCTURE IN DBMS
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrol
 
Directory structure
Directory structureDirectory structure
Directory structure
 
Ch02 early system memory management
Ch02 early system  memory managementCh02 early system  memory management
Ch02 early system memory management
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
 
System programs in o.s. for bca and bscit students by hardik nathani
System programs in o.s. for bca and bscit students by hardik nathaniSystem programs in o.s. for bca and bscit students by hardik nathani
System programs in o.s. for bca and bscit students by hardik nathani
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Properties
 
Database fragmentation
Database fragmentationDatabase fragmentation
Database fragmentation
 
Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011
 
Transaction concurrency control
Transaction concurrency controlTransaction concurrency control
Transaction concurrency control
 

Similar to 6 two phasecommit

enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...DHANUSHKUMARKS
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database SystemsMoutasm Tamimi
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlbalamurugan.k Kalibalamurugan
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-queryM Rezaur Rahman
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Peter R. Egli
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationWayne Jones Jnr
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OSC.U
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsSachin Chauhan
 
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture [WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture WSO2
 

Similar to 6 two phasecommit (20)

Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
 
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
enc=encoded=TlJst0_SHq0cPRhLS74QDXTP4FpU303sSqpyVVkfhckA93UCiZrRF0QVNAFGmuGu9...
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database Systems
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency control
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query
 
Bab8 transaction
Bab8 transactionBab8 transaction
Bab8 transaction
 
Lec13s transaction
Lec13s transactionLec13s transaction
Lec13s transaction
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed Coordination
 
Transaction management transparencies
Transaction management transparenciesTransaction management transparencies
Transaction management transparencies
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OS
 
OSCh17
OSCh17OSCh17
OSCh17
 
OS_Ch17
OS_Ch17OS_Ch17
OS_Ch17
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
 
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture [WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
[WSO2Con EU 2018] Managing Transactions in Your Microservices Architecture
 
dos.ppt.pptx
dos.ppt.pptxdos.ppt.pptx
dos.ppt.pptx
 
2 pc
2 pc2 pc
2 pc
 
9 queuing
9 queuing9 queuing
9 queuing
 
Process synchronization in operating system
Process synchronization in operating systemProcess synchronization in operating system
Process synchronization in operating system
 

More from ashish61_scs

More from ashish61_scs (20)

7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
Transactions
TransactionsTransactions
Transactions
 
22 levine
22 levine22 levine
22 levine
 
21 domino mohan-1
21 domino mohan-121 domino mohan-1
21 domino mohan-1
 
20 access paths
20 access paths20 access paths
20 access paths
 
19 structured files
19 structured files19 structured files
19 structured files
 
18 philbe replication stanford99
18 philbe replication stanford9918 philbe replication stanford99
18 philbe replication stanford99
 
17 wics99 harkey
17 wics99 harkey17 wics99 harkey
17 wics99 harkey
 
16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wics
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
14 turing wics
14 turing wics14 turing wics
14 turing wics
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 
13 tm adv
13 tm adv13 tm adv
13 tm adv
 
11 tm
11 tm11 tm
11 tm
 
10b rm
10b rm10b rm
10b rm
 
10a log
10a log10a log
10a log
 
09 workflow
09 workflow09 workflow
09 workflow
 
08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick
 
06 07 lock
06 07 lock06 07 lock
06 07 lock
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

6 two phasecommit

  • 1. 2/1/2012 1 6. Two Phase Commit CSEP 545 Transaction Processing for E-Commerce Philip A. Bernstein Sameh Elnikety Copyright ©2012 Philip A. Bernstein
  • 2. 2/1/2012 2 Distributed Systems • Failures – Links and nodes – Models • Algorithms – Correctness – Termination A B
  • 3. 2/1/2012 3 Introduction • Goal - ensure the atomicity of a transaction that accesses multiple resource managers. • (Recall, resource abstracts data, messages, and other items that are shared by transactions.) • Why is this hard? – After a transaction commits at RMa,what if resource manager RMb fails? – When RMb recovers, what to do if other resource managers are down? – What if a transaction thinks a resource manager failed and therefore aborted, when it actually is still running?
  • 4. 2/1/2012 4 Assumptions • Each resource manager independently commits or aborts a transaction atomically on its resources. • Home(T) decides when to start committing T. • Home(T) doesn’t start committing T until T terminates at all nodes (possibly hard). • Resource managers fail by stopping. – No Byzantine failures, where a failed process exhibits arbitrary behavior, such as sending the wrong message.
  • 5. 2/1/2012 5 Problem Statement • Transaction T accessed data at resource managers R1, … Rn. • The goal is to either – Commit T at all of R1, … Rn, or – Abort T at all of R1, … Rn – Even if resource managers, nodes and communications links fail during the commit or abort activity. • That is, never commit at Ri but abort at Rk.
  • 6. 2/1/2012 6 Outline 1. Introduction 2. The Two-Phase Commit (2PC) Protocol 3. 2PC Failure Handling 4. 2PC Optimizations 5. Process Structuring 6. Three Phase Commit
  • 7. 2/1/2012 7 2. Two-Phase Commit • Two phase commit (2PC) is the standard protocol for making commit and abort atomic. • Coordinator - the component that coordinates commitment at home(T). • Participant - a resource manager accessed by T. • A participant P is ready to commit T if all of T’s after-images at P are in stable storage. • The coordinator must not commit T until all participants are ready. – If P isn’t ready, T commits, and P fails, then P can’t commit when it recovers.
  • 8. 2/1/2012 8 The Protocol 1 (Begin Phase 1) The coordinator sends a Request-to-Prepare message to each participant. 2 The coordinator waits for all participants to vote. 3 Each participant  Votes Prepared if it’s ready to commit  May vote No for any reason  May delay voting indefinitely. 4 (Begin Phase 2) If coordinator receives Prepared from all participants, it decides to commit. (The transaction is now committed.) Otherwise, it decides to abort.
  • 9. 2/1/2012 9 The Protocol (cont’d) 5 The coordinator sends its decision to all participants (i.e., Commit or Abort). 6 Participants acknowledge receipt of Commit or Abort by replying Done.
  • 10. 2/1/2012 10 Case 1: Commit Coordinator Participant Request-to-Prepare Prepared Commit Done
  • 11. 2/1/2012 11 Case 2: Abort Coordinator Request-to-Prepare No Abort Done Participant
  • 12. 2/1/2012 12 Performance • In the absence of failures, 2PC requires 3 rounds of messages before the decision is made known to RM’s. – Request-to-prepare – Votes (Prepared, No) – Decision (Commit, Abort). • Done messages are just for bookkeeping . – They don’t affect response time. – They can be batched.
  • 13. 2/1/2012 13 Uncertainty • Before it votes, a participant can abort unilaterally. • After a participant votes Prepared and before it receives the coordinator’s decision, it is uncertain. It can’t unilaterally commit or abort during its uncertainty period. Coordinator Participant Request-to-Prepare Prepared Commit Done Uncertainty Period
  • 14. 2/1/2012 14 Uncertainty (cont’d) • The coordinator is never uncertain. • If a participant fails or is disconnected from the coordinator while it’s uncertain, at recovery it must find out the decision.
  • 15. 2/1/2012 15 The Bad News Theorems • Uncertainty periods are unavoidable. • Blocking - a participant must await a repair before continuing. Blocking is bad. • Theorem 1 - For every possible commit protocol (not just 2PC), a communications failure can cause a participant to become blocked. • Independent recovery - a recovered participant can decide to commit or abort without communicating with other nodes. • Theorem 2 - No commit protocol can guarantee independent recovery of failed participants.
  • 16. 2/1/2012 16 3. 2PC Failure Handling • Failure handling - what to do if the coordinator or a participant times out waiting for a message. – Remember, all failures are detected by timeout. • A participant times out waiting for coordinator’s Request-to-prepare. – It decides to abort. • The coordinator times out waiting for a participant’s vote. – It decides to abort.
  • 17. 2/1/2012 17 2PC Failure Handling (cont’d) • A participant that voted Prepared times out waiting for the coordinator’s decision – It’s blocked. – Use a termination protocol to decide what to do. – Naïve termination protocol - wait till the coordinator recovers. • The coordinator times out waiting for Done. – It must resolicit them, so it can forget the decision.
  • 18. 2/1/2012 18 Forgetting Transactions • After a participant receives the decision, it may forget the transaction. • After the coordinator receives Done from all participants, it may forget the transaction. • A participant must not reply Done until its commit or abort log record is stable. – Else, if it fails, then recovers, then asks the coordinator for a decision, the coordinator may not know.
  • 19. 2/1/2012 19 Logging 2PC State Changes • Logging may be eager. – It’s flushed to disk before the next Send Message. • Or it may be lazy = not eager Coordinator Participant Request-to-Prepare Prepared Commit Done Log commit (eager) Log commit (eager) Log commit (lazy) Log prepared (eager) Log Start2PC (eager)
  • 20. 2/1/2012 20 Coordinator Recovery • If the coordinator fails and later recovers, it must know the decision. It must therefore log: – The fact that it began T’s 2PC protocol, including the list of participants, and – Commit or Abort, before sending Commit or Abort to any participant (so it knows whether to commit or abort after it recovers). • If the coordinator fails and recovers, it resends the decision to participants from which it doesn’t remember getting Done – If the participant forgot the transaction, it replies Done – The coordinator should therefore log Done after it has received them all.
  • 21. 2/1/2012 21 Participant Recovery • If a participant P fails and later recovers, it first performs centralized recovery (Restart). • For each distributed transaction T that was active at the time of failure: – If P is not uncertain about T, then it unilaterally aborts T – If P is uncertain, it runs the termination protocol (which may leave P blocked). • To ensure it can tell whether it’s uncertain, P must log its vote before sending it to the coordinator. • To avoid becoming totally blocked due to one blocked transaction, P should reacquire T’s locks during Restart and allow Restart to finish before T is resolved.
  • 22. 2/1/2012 22 Heuristic Commit • Suppose a participant recovers, but the termination protocol leaves T blocked. • Operator can guess whether to commit or abort – Must detect wrong guesses when coordinator recovers. – Must run compensations for wrong guesses. • Heuristic commit – If T is blocked, the local resource manager (actually, transaction manager) guesses. – At coordinator recovery, the transaction managers jointly detect wrong guesses.
  • 23. 2/1/2012 23 4. 2PC Optimizations and Variations • Optimizations – Read-only transaction – Presumed Abort – Transfer of coordination – Cooperative termination protocol • Variations – Re-infection – Phase Zero
  • 24. 2/1/2012 24 Read-only Transaction • A read-only participant need only respond to phase one. It doesn’t care what the decision is. • It responds Prepared-Read-Only to Request-to-Prepare, to tell the coordinator not to send the decision. • Limitation - All other participants must be fully terminated, since the read-only participant will release locks after voting. – No more testing of SQL integrity constraints. – No more evaluation of SQL triggers.
  • 25. 2/1/2012 25 Presumed Abort • After a coordinator decides Abort and sends Abort to participants, it forgets about T immediately. • Participants don’t acknowledge Abort (with Done). Coordinator Participant Request-to-Prepare Prepared Abort Log abort (forget T) Log abort (forget T) Log prepared Log Start2PC • If a participant times out waiting for the decision, it asks the coordinator to retry. – If the coordinator has no info for T, it replies Abort.
  • 26. 2/1/2012 26 Transfer of Coordination If there is one participant, you can save a round of messages 1. Coordinator asks participant to prepare and become the coordinator. 2. The participant (now coordinator) prepares, commits, and tells the former coordinator to commit. 3. The coordinator commits and replies Done. Coordinator Participant Request-to-Prepare-and -transfer-coordination CommitLog commit Log committed Log prepared Done • Supported by some app servers, but not in any standards.
  • 27. 2/1/2012 27 Cooperative Termination Protocol (CTP) • Assume coordinator includes a list of participants in Request-to-Prepare. • If a participant times-out waiting for the decision, it runs the following protocol. 1. Participant P sends Decision-Req to other participants. 2. If participant Q voted No or hasn’t voted or received Abort from the coordinator, it responds Abort. 3. If participant Q received Commit from the coordinator, it responds Commit. 4. If participant Q is uncertain, it responds Uncertain (or doesn’t respond at all). • If all participants are uncertain, then P remains blocked.
  • 28. 2/1/2012 28 Cooperative Termination Issues • Participants don’t know when to forget T, since other participants may require CTP – Solution 1 - After receiving Done from all participants, coordinator sends End to all participants. – Solution 2 - After receiving a decision, a participant may forget T any time. • To ensure it can run CTP, a participant should include the list of participants in the vote log record.
  • 29. 2/1/2012 29 Reinfection • Suppose A is coordinator and B and C are participants – A asks B and C to prepare. – B votes prepared. – C calls B to do some work. (B is reinfected.) – B does the work and tells C it has prepared, but now it expects C to be its coordinator. – When A asks C to prepare, C propagates the request to B and votes prepared only if both B and C are prepared. (See Tree of Processes discussion later.) • Can be used to implement integrity constraint checking, triggers, and other commit-time processing, without requiring an extra phase (between phases 1 and 2 of 2PC).
  • 30. 2/1/2012 30 Phase Zero • Suppose a participant P is caching transaction T’s updates that P needs to send to an RM (another participant) before T commits. – P must send the updates after T invokes Commit, to ensure P has all of T’s updates – P must send the updates before the RM prepares, to ensure the updates are made stable during phase one. – Thus, we need an extra phase, before phase 1. • A participant explicitly enlists for phase zero. – It doesn’t ack phase zero until it finishes flushing its cached updates to other participants. • Supported in Microsoft DTC.
  • 31. 2/1/2012 31 5. Process Structuring • To support multiple RMs on multiple nodes, and minimize communication, use one transaction manager (TM) per node • TM may be in the OS (VAX/VMS, Win), the app server (IBM CICS), DBMS, or a separate product (early Tandem). • TM performs coordinator and participant roles for all transactions at its node. • TM communicates with local RMs and remote TMs. Transaction Manager Resource ManagerResource ManagerResource Manager Application Enlist and 2PC ops RM ops StartTransaction, Commit, RollbackTX XA 2PC ops Other TMs
  • 32. 2/1/2012 32 Enlisting in a Transaction • When an Application in a transaction T first calls an RM, the RM must tell the TM it is part of T. • Called enlisting or joining the transaction Transaction Manager Resource Manager Application 3. Enlist(T) 2. Write(X, T) 1. StartTransaction (returns Tranction ID)
  • 33. 2/1/2012 33 Enlisting in a Transaction (cont’d) • When an application A in a transaction T first calls an application B at another node, B must tell its local TM that the transaction has arrived. Transaction Manager Communications Manager Application A 2. AddBranch(N, T) 1. Call(AP-B, T) Transaction Manager Communications Manager Application B 4. StartBranch(N, T) 5. Call(AP-B, T) 3. Send Call(AP-B, T) Node M Node N
  • 34. 2/1/2012 34 Tree of Processes • Application calls to RMs and other applications induces a tree of processes. • Each internal node is the coordinator for its descendants, and a participant to its parents. • This adds delay to two-phase commit. • Optimization: flatten the tree, e.g. during phase 1 TM1 TM2 TM3 TM4 RM1 RM2 RM3 RM4 RM5 Different Nodes
  • 35. 2/1/2012 35 Handling Multiple Protocols • Communication managers solve the problem of handling multiple 2PC protocols by providing: – A model for communication between address spaces. – A wire protocol for two-phase commit. • But, expect restrictions on multi-protocol interoperation. • The RM only talks to the TM-RM interface. The multi- protocol problem is solved by the TM vendor. Transaction Manager Resource ManagerResource ManagerResource Manager Application Enlist and 2PC ops RM ops TX XA 2PC ops other TMs Communication Manager Send/receive msg XA+
  • 36. 2/1/2012 36 Complete Walkthrough Application: Start-trans Call DBMS Call remote app Commit Application Comm Mgr Database System Txn Manager Transaction Manager Comm Manager 8. Req-prepare 9. Prepared 10. Commit 11. Done 1. Start Tran 4. Add-branch 7. Commit 2. Call DBMS 5. Call 6. Start-branch 3. Enlist DBMS
  • 37. 2/1/2012 37 Customer Checklist • Does your DBMS support 2PC? • Does your execution environment support it? If so, – With what DBMSs? – Using what protocol(s)? – Do these protocols meet your interoperation needs? • Is the TM-DBMS interface open (for home-grown DBMSs)? • Can an operator commit/abort a blocked txn? – If so, is there automated support for reconciling mistakes? – Is there automated heuristic commit?
  • 38. 2/1/2012 38 6. Three Phase Commit- The Idea • 3PC prevents blocking in the absence of communications failures (unrealistic, but …). It can be made resilient to communications failures, but then it may block • 3PC is much more complex than 2PC, but only marginally improves reliability — prevents some blocking situations. • 3PC therefore is not used much in practice. • Main idea: becoming certain and deciding to commit are separate steps. • 3PC ensures that if any operational process is uncertain, then no (failed or operational) process has committed. • So, in the termination protocol, if the operational processes are all uncertain, they can decide to abort (avoids blocking).
  • 39. 2/1/2012 39 Three Phase Commit- The Protocol 1. (Begin phase 1) Coordinator C sends Request-to-prepare to all participants. 2. Participants vote Prepared or No, just like 2PC. 3. If C receives Prepared from all participants, then (begin phase 2) it sends Pre-Commit to all participants. 4. Participants wait for Abort or Pre-Commit. Participant acknowledges Pre-commit. 5. After C receives acks from all participants, or times out on some of them, it (begin third phase) sends Commit to all participants (that are up).
  • 40. 2/1/2012 40 3PC Failure Handling • If coordinator times out before receiving Prepared from all participants, it decides to abort. • Coordinator ignores participants that don’t ack its Pre-Commit. • Participants that voted Prepared and timed out waiting for Pre-Commit or Commit use the termination protocol. • The termination protocol is where the complexity lies. (E.g. see [Bernstein, Hadzilacos, Goodman 87], Section 7.4).