0
0
DBMS Theoryknowledge~10 mins

Distributed transactions and 2PC in DBMS Theory - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Distributed transactions and 2PC
Client starts transaction
Coordinator sends PREPARE to all participants
Participants vote: YES or NO
Coordinator receives all YES
Coordinator sends COMMIT
Participants commit
Transaction ends
The coordinator asks all participants if they can commit. If all agree, it tells them to commit; if any say no, it tells them to abort.
Execution Sample
DBMS Theory
Coordinator: send PREPARE
Participants: vote YES or NO
Coordinator: if all YES send COMMIT else ABORT
Participants: commit or abort
This shows the basic message flow of the two-phase commit protocol in a distributed transaction.
Analysis Table
StepActionCoordinator StateParticipants StateMessage SentResult
1Client starts transactionWaitingIdleNoneTransaction begins
2Coordinator sends PREPAREWaiting for votesReady to votePREPAREParticipants prepare to vote
3Participants vote YESCollecting votesVote YESYESVote recorded
4Participants vote YESCollecting votesVote YESYESVote recorded
5Coordinator receives all YESAll votes YESWaiting for commit/abortNoneReady to commit
6Coordinator sends COMMITSent COMMITReceived COMMITCOMMITParticipants prepare to commit
7Participants commitWaiting for ackCommittedACKCommit done
8Coordinator receives ACKsTransaction completeIdleNoneTransaction ends
💡 All participants voted YES, so coordinator sent COMMIT and transaction completed successfully.
State Tracker
VariableStartAfter Step 2After Step 5After Step 7Final
Coordinator StateWaitingWaiting for votesAll votes YESSent COMMITTransaction complete
Participants StateIdleReady to voteVote YESCommittedIdle
Messages SentNonePREPAREYES votesCOMMITACK
Key Insights - 3 Insights
Why does the coordinator wait for all participants to vote before deciding?
Because the coordinator must ensure all participants agree to commit; if any say NO, the transaction must abort. This is shown in execution_table rows 3-5.
What happens if any participant votes NO?
The coordinator sends ABORT to all participants to cancel the transaction. This is not shown in the current table but would happen instead of sending COMMIT at step 6.
Why do participants send ACK after committing?
To inform the coordinator that they have completed the commit, so the coordinator knows the transaction is fully done. See execution_table rows 7-8.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the coordinator's state?
AAll votes YES
BWaiting for votes
CSent COMMIT
DTransaction complete
💡 Hint
Check the 'Coordinator State' column at step 5 in the execution_table.
At which step do participants commit the transaction?
AStep 4
BStep 6
CStep 7
DStep 8
💡 Hint
Look for 'Participants commit' in the 'Action' column of the execution_table.
If one participant votes NO at step 3, what message will the coordinator send next?
APREPARE
BABORT
CCOMMIT
DACK
💡 Hint
Recall the coordinator sends ABORT if any participant votes NO, as explained in key_moments.
Concept Snapshot
Distributed transactions involve multiple databases working together.
Two-Phase Commit (2PC) ensures all agree to commit or abort.
Phase 1: Coordinator asks participants to prepare and vote.
Phase 2: Coordinator sends COMMIT if all YES, else ABORT.
Participants commit or abort accordingly.
This prevents partial updates and keeps data consistent.
Full Transcript
Distributed transactions involve multiple databases or systems working together to complete a single transaction. The Two-Phase Commit protocol (2PC) is a method to ensure all parts agree to either commit or abort the transaction, keeping data consistent. First, the coordinator sends a PREPARE message to all participants asking if they can commit. Each participant votes YES or NO. If all vote YES, the coordinator sends a COMMIT message, and participants commit the transaction. If any vote NO, the coordinator sends ABORT, and participants cancel the transaction. Participants send acknowledgments after committing or aborting. This process prevents partial updates and ensures all systems stay in sync.