SlideShare a Scribd company logo
1 of 15
Two Phase Commit
WHY WE ARE GOING FOR
THIS??
A transaction which executes at multiple
sites must either be committed at all
the sites, or aborted at all the sites.
Not acceptable to have a transaction
committed at one site and aborted at
the other.
DEFINITION
The protocol results in either all nodes
committing the transaction or
aborting, even in the case of site
failures.
TERMS USED
One node is designated the coordinator
(or) Transaction Manager, which is the
master site, and the rest of the nodes in
the network are called cohorts.
TRANSACTION MANAGER
1) Transaction Manager responsible for
Maintaining a log for recovery
purposes.
2) Starting the execution of transactions
that originate at the site.
3) Coordinating the termination of each
transaction at the site.
TERMS USED
Log -> It is a file listing changes to the
database, stored in a stable storage
format.
Undo -> It allows us move to the last
action we have performed.
Redo -> Reverse action of Undo
EXAMPLE
Bank A Bank B
Transfer $1000
From A:$3000
To B:$2000
client
Transaction
coordinator
TRANSACTION CHART
client
transaction
coordinator
bank A bank B
start
result
prepare
prepare
rB
rA
outcome
outcome
If rA==yes && rB==yes
outcome = “commit”
else
outcome = “abort”
B commits upon
receiving “commit”
TYPES OF PHASES
1) COMMIT REQUEST PHASE
2) COMMIT PHASE
BASIC ALGORITHM
During phase 1, initially the coordinator
sends a query to commit message to all
cohorts. Then it waits for all cohorts to
report back with the agreement
message. The cohorts, if the
transaction was successful, write an
entry to the log.
BASIC ALGORITHM
During phase 2, if the coordinator
receives an agree message from all
cohorts, then it writes a commit record
into its log and sends a commit
message to all the cohorts. If all
agreement messages do not come
back the coordinator sends an abort
message.
BASIC ALGORITHM
Next the coordinator waits for the
acknowledgement from the cohorts.
When acks are received from all
cohorts the coordinator writes a
complete record to its log.
BASIC ALGORITHM
If the cohort receives a commit
message, it releases all the locks and
resources held during the transaction
and sends an acknowledgement to the
coordinator.
BASIC ALGORITHM
If the message is abort, then the cohort
undoes the transaction with the undo
log and releases the resources and
locks held during the transaction. Then
it sends an acknowledgement.
CONS OF 2 PHASE COMMIT
Other processes competing for resource
locks held by the blocked processes
will have to wait for the locks to be
released.
If the coordinator fails permanently it will
go back to Rollback state.

More Related Content

What's hot

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency controlBinte fatima
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Meghaj Mallick
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactionsNilu Desai
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesMeghaj Mallick
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management SystemJanki Shah
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionSHIKHA GAUTAM
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systemssumitjain2013
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed SystemsArsnet
 
Practical Byzantine Fault Tolernace
Practical Byzantine Fault TolernacePractical Byzantine Fault Tolernace
Practical Byzantine Fault TolernaceYongraeJo
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed SystemsPritom Saha Akash
 
Congetion Control.pptx
Congetion Control.pptxCongetion Control.pptx
Congetion Control.pptxNaveen Dubey
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemDHIVYADEVAKI
 
Deadlock detection
Deadlock detectionDeadlock detection
Deadlock detectionNadia Nahar
 
deadlock handling
deadlock handlingdeadlock handling
deadlock handlingSuraj Kumar
 

What's hot (20)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed Systems
 
Practical Byzantine Fault Tolernace
Practical Byzantine Fault TolernacePractical Byzantine Fault Tolernace
Practical Byzantine Fault Tolernace
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Congetion Control.pptx
Congetion Control.pptxCongetion Control.pptx
Congetion Control.pptx
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed System
 
Deadlock detection
Deadlock detectionDeadlock detection
Deadlock detection
 
deadlock handling
deadlock handlingdeadlock handling
deadlock handling
 

Similar to 2 PHASE COMMIT PROTOCOL

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
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-queryM Rezaur Rahman
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)Sri Prasanna
 
Management of Distributed Transactions
Management of Distributed TransactionsManagement of Distributed Transactions
Management of Distributed TransactionsAnkita Dubey
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OSC.U
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database SystemsMoutasm Tamimi
 
[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
 
3 phases in transactions 3 units
3 phases in transactions 3 units3 phases in transactions 3 units
3 phases in transactions 3 unitsavniS
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationWayne Jones Jnr
 
UNIT IV DIS.pptx
UNIT IV DIS.pptxUNIT IV DIS.pptx
UNIT IV DIS.pptxSamPrem3
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed Coordinationsiva krishna
 

Similar to 2 PHASE COMMIT PROTOCOL (20)

dos.ppt.pptx
dos.ppt.pptxdos.ppt.pptx
dos.ppt.pptx
 
2 pc
2 pc2 pc
2 pc
 
Transaction management transparencies
Transaction management transparenciesTransaction management transparencies
Transaction management transparencies
 
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
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query
 
Transactions (Distributed computing)
Transactions (Distributed computing)Transactions (Distributed computing)
Transactions (Distributed computing)
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Managing transactions 11g release 1 (10.3
Managing transactions   11g release 1 (10.3Managing transactions   11g release 1 (10.3
Managing transactions 11g release 1 (10.3
 
Management of Distributed Transactions
Management of Distributed TransactionsManagement of Distributed Transactions
Management of Distributed Transactions
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OS
 
OSCh17
OSCh17OSCh17
OSCh17
 
OS_Ch17
OS_Ch17OS_Ch17
OS_Ch17
 
Recovery in Multi database Systems
Recovery in Multi database SystemsRecovery in Multi database Systems
Recovery in Multi database Systems
 
[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
 
3 phases in transactions 3 units
3 phases in transactions 3 units3 phases in transactions 3 units
3 phases in transactions 3 units
 
Chapter 18 - Distributed Coordination
Chapter 18 - Distributed CoordinationChapter 18 - Distributed Coordination
Chapter 18 - Distributed Coordination
 
UNIT IV DIS.pptx
UNIT IV DIS.pptxUNIT IV DIS.pptx
UNIT IV DIS.pptx
 
Dos.pptx
Dos.pptxDos.pptx
Dos.pptx
 
12EASApril-3412
12EASApril-341212EASApril-3412
12EASApril-3412
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed Coordination
 

More from KABILESH RAMAR

More from KABILESH RAMAR (20)

Online i os
Online i osOnline i os
Online i os
 
Linux and windows
Linux and windowsLinux and windows
Linux and windows
 
Android os versions and architecture
Android os versions and architectureAndroid os versions and architecture
Android os versions and architecture
 
Turtle Graphics in CG
Turtle Graphics in CGTurtle Graphics in CG
Turtle Graphics in CG
 
Ray Tracing in Computer Graphics
Ray Tracing in Computer GraphicsRay Tracing in Computer Graphics
Ray Tracing in Computer Graphics
 
Email security
Email securityEmail security
Email security
 
Visible surface detection methods
Visible surface detection methodsVisible surface detection methods
Visible surface detection methods
 
Raster scan and random scan
Raster scan and random scanRaster scan and random scan
Raster scan and random scan
 
Properties of light
Properties of lightProperties of light
Properties of light
 
Polygon mesh
Polygon meshPolygon mesh
Polygon mesh
 
Liquid crystal display
Liquid crystal displayLiquid crystal display
Liquid crystal display
 
Ink jet printer
Ink jet printerInk jet printer
Ink jet printer
 
Illumination models
Illumination modelsIllumination models
Illumination models
 
Dot matrix printers
Dot matrix printersDot matrix printers
Dot matrix printers
 
Cathode ray tubes
Cathode ray tubesCathode ray tubes
Cathode ray tubes
 
NEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATIONNEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATION
 
RFID
RFIDRFID
RFID
 
Digital libraries
Digital librariesDigital libraries
Digital libraries
 
Covert networks
Covert networksCovert networks
Covert networks
 
Ethernet
EthernetEthernet
Ethernet
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 

2 PHASE COMMIT PROTOCOL

  • 2. WHY WE ARE GOING FOR THIS?? A transaction which executes at multiple sites must either be committed at all the sites, or aborted at all the sites. Not acceptable to have a transaction committed at one site and aborted at the other.
  • 3. DEFINITION The protocol results in either all nodes committing the transaction or aborting, even in the case of site failures.
  • 4. TERMS USED One node is designated the coordinator (or) Transaction Manager, which is the master site, and the rest of the nodes in the network are called cohorts.
  • 5. TRANSACTION MANAGER 1) Transaction Manager responsible for Maintaining a log for recovery purposes. 2) Starting the execution of transactions that originate at the site. 3) Coordinating the termination of each transaction at the site.
  • 6. TERMS USED Log -> It is a file listing changes to the database, stored in a stable storage format. Undo -> It allows us move to the last action we have performed. Redo -> Reverse action of Undo
  • 7. EXAMPLE Bank A Bank B Transfer $1000 From A:$3000 To B:$2000 client Transaction coordinator
  • 8. TRANSACTION CHART client transaction coordinator bank A bank B start result prepare prepare rB rA outcome outcome If rA==yes && rB==yes outcome = “commit” else outcome = “abort” B commits upon receiving “commit”
  • 9. TYPES OF PHASES 1) COMMIT REQUEST PHASE 2) COMMIT PHASE
  • 10. BASIC ALGORITHM During phase 1, initially the coordinator sends a query to commit message to all cohorts. Then it waits for all cohorts to report back with the agreement message. The cohorts, if the transaction was successful, write an entry to the log.
  • 11. BASIC ALGORITHM During phase 2, if the coordinator receives an agree message from all cohorts, then it writes a commit record into its log and sends a commit message to all the cohorts. If all agreement messages do not come back the coordinator sends an abort message.
  • 12. BASIC ALGORITHM Next the coordinator waits for the acknowledgement from the cohorts. When acks are received from all cohorts the coordinator writes a complete record to its log.
  • 13. BASIC ALGORITHM If the cohort receives a commit message, it releases all the locks and resources held during the transaction and sends an acknowledgement to the coordinator.
  • 14. BASIC ALGORITHM If the message is abort, then the cohort undoes the transaction with the undo log and releases the resources and locks held during the transaction. Then it sends an acknowledgement.
  • 15. CONS OF 2 PHASE COMMIT Other processes competing for resource locks held by the blocked processes will have to wait for the locks to be released. If the coordinator fails permanently it will go back to Rollback state.