Two Phase Commit
Two Phase Commit
Department of
ARTIFICIAL INTELLIGENCE & DATA SCIENCE
M.Tech. 3rd Semester
ADBMS
Faculty: Dr. Savita Patil
1. Transaction Initiation:
1
1. Transaction Initiation:
In the first phase of the two-phase commit protocol, the coordinator sends a "prepare
to commit" message to all participating nodes.
2
3. Phase 2: Commit or Abort Phase:
Based on the responses received during the prepare phase, the coordinator
makes a decision to either commit or abort the transaction.
If any participant responded with a refusal (NO), indicating that they
cannot proceed with the transaction, the coordinator sends an "abort"
message to all participants.
3
CASE 1: COMMIT
Coordinator Participants
Request-to-Prepare
Prepared
Commit
Done
4
Case 2: Abort
Coordinator Participants
Request-to-Prepare
No
Abort
Done
5
WHAT IS DEADLOCK
A deadlock is a situation in a computer system where two or more processes
are unable to proceed because each is waiting for the other to release a
resource, such as a lock or a piece of memory, before it can continue.
6
DEADLOCK RECOVERY THROUGH 2 PHASE COMMIT
Detect Deadlock: First, the system needs to detect the presence of a deadlock. This
can be done through various deadlock detection algorithms that monitor resource
allocation and process states to identify circular wait conditions. (ex: Banker’s
Algorithm)
Initiate 2PC: The system then initiates the Two-Phase Commit protocol to
coordinate the aborting of transactions involved in the deadlock. This involves the
following steps:
7
Phase 2 - Commit or Abort: If all transactions agree to abort
(i.e., they respond affirmatively during the prepare phase), the
coordinator sends a commit message instructing all involved
transactions to abort. Otherwise, if any transaction refuses to
abort, the coordinator aborts the entire operation and may resort
to other recovery mechanisms.
Release Resources: With the aborted transactions releasing their held resources,
other transactions waiting for these resources can proceed, breaking the deadlock
cycle.
8
10