UNIT 7 - Atomic Transactions
UNIT 7 - Atomic Transactions
Distributed Systems
CS-4513
D-Term 2007
(Slides include materials from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne,
Modern Operating Systems, 2nd ed., by Tanenbaum, and Distributed Systems: Principles & Paradigms, 2nd
ed. By Tanenbaum and Van Steen)
CS-4513, D-Term
2007
Atomic Transac
tions
Definition Transaction
A sequence of operations that perform a
single logical function
Examples
Atomic Transac
tions
Example:
Cash machine hands you cash and deducts amount
from your account
Airline confirms your reservation and
Reduces number of free seats
Charges your credit card
(Sometimes) increases number of meals loaded on flight
CS-4513, D-Term
2007
Atomic Transac
tions
CS-4513, D-Term
2007
Atomic Transac
tions
Atomic Transac
tions
End_transaction
Mark the end of a transaction and try to commit
Abort_transaction
Terminate the transaction and restore old values
Read
Read data from a file, table, etc., on behalf of the transaction
Write
Write data to file, table, etc., on behalf of the transaction
CS-4513, D-Term
2007
Atomic Transac
tions
CS-4513, D-Term
2007
Atomic Transac
tions
Nested Transactions
One or more transactions inside another transaction
May individually commit, but may need to be
undone
Example
Planning a trip involving three flights
Reservation for each flight commits individually
Must be undone if entire trip cannot commit
CS-4513, D-Term
2007
Atomic Transac
tions
Stable storage
i.e., write to disk atomically (ppt, html)
Log file
i.e., record actions in a log before committing
them (ppt, html)
Log in stable storage
Locking protocols
Serialize Read and Write operations of same data by
separate transactions
CS-4513, D-Term
2007
Atomic Transac
tions
Begin_transaction
Place a begin entry in log
Write
Write updated data to log
Abort_transaction
Place abort entry in log
Atomic Transac
tions
10
CS-4513, D-Term
2007
Atomic Transac
tions
11
Failure modes
Crash or other failure of one site or system
Network failure or partition
Byzantine failures
CS-4513, D-Term
2007
Atomic Transac
tions
12
Seminal reference
Jim Gray, Notes on Database Operating
Systems, in Operating Systems: an Advanced
Course, vol 60 of Lecture Notes in Comp. Sci.,
Springer-Verlag, 1978, pp. 393-481
CS-4513, D-Term
2007
Atomic Transac
tions
13
Two-Phase Commit
One site is elected coordinator of the
transaction T
See Election algorithms (ppt, html)
Atomic Transac
tions
14
Atomic Transac
tions
15
Atomic Transac
tions
16
coordinator
CS-4513, D-Term
2007
participant
Atomic Transac
tions
17
Atomic Transac
tions
18
Atomic Transac
tions
19
Coordinator Crash
Inspect Log
If Abort or Commit state
Resend corresponding message
Take corresponding local action
Atomic Transac
tions
20
No Response to Participants
Ready_to_commit(T) message
Re-contact coordinator, ask what to do
If unable to contact coordinator, contact other
participants, ask if they know
If any other participant is in Abort or Commit state
Take equivalent action
CS-4513, D-Term
2007
Atomic Transac
tions
21
Participant Crash
Inspect local log
Commit state:
Redo/replay the transaction
Abort state:
Undo/abort the transaction
No records about T:
Same as local_abort(T)
Ready State:
Same as no response to Ready_to_commit(T) message
CS-4513, D-Term
2007
Atomic Transac
tions
22
Atomic Transac
tions
23
Three-Phase Commit
Minor variation
Widely quoted in literature
Rarely implemented
Because indefinite blocking due to coordinator
failures doesnt happen very often in real life!
CS-4513, D-Term
2007
Atomic Transac
tions
24
Atomic Transac
tions
25
CS-4513, D-Term
2007
Atomic Transac
tions
26
CS-4513, D-Term
2007
Atomic Transac
tions
27
Contact others
If any in Abort, then abort transaction
If any in Precommit, the move to Precommit state
CS-4513, D-Term
2007
Atomic Transac
tions
28
CS-4513, D-Term
2007
Atomic Transac
tions
29
Questions?
CS-4513, D-Term
2007
Atomic Transac
tions
30