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
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.