100 likes | 114 Views
The Transaction. Durable starting state. Durable, consistent, ending state. Collection of resource actions. Successful completion. Abort. Rollback. Withdraw $100 Read current balance new balance = current - 100 Write new balance Dispense cash. Transfer $100
E N D
The Transaction Durable starting state Durable, consistent, ending state Collection of resource actions Successful completion Abort Rollback
Withdraw $100 Read current balance new balance = current - 100 Write new balance Dispense cash Transfer $100 Read savings (sub 100) Read checking (add 100) Write savings Write checking Transaction Examples
Transaction architecture Transaction manager Join Application logic Prepare, commit, abort Resource managers
Transaction manager Phase 1 commit() Transaction manager Phase 2 prepare() yes_or_no Transaction manager abort() Commit or abort One or more “no’s” Rollback All “yes”
Withdraw $100 Read checking balance new balance = current - 100 Write new balance Dispense cash Transfer $100 Read savings (sub 100) Read checking (add 100) Write savings Write checking Transaction Interference time
Isolation of transactions (Serializability) Two concurrent transactions Transaction_1 Shared resources Give the same result as: Transaction_2 Transaction_1 Transaction_2 Or: Transaction_2 Transaction_1
Withdraw $100 Read checking balance new balance = current - 100 Write new balance Dispense cash Transfer $100 Read savings (sub 100) Read checking (add 100) Write savings Write checking Bad (Not Serializable) time
Withdraw $100 Read checking balance new balance = current - 100 Write new balance Dispense cash Transfer $100 Read savings (sub 100) Read checking (add 100)Write savings Write checking OK (Same as Withdraw first) time
Transaction 1: Lock A Lock B … Release all Transaction 2: Lock B Lock A … Release all Danger from Waiting: Deadlock
Summary Application server Resource manager Transaction manager request(tp_ID,….) join(tp_ID) Lock OK or Already_locked More requests…. Prepare (tp_ID) commit_or_abort(tp_ID) Commit or rollback Unlock