You are on page 1of 14

Transactions

Transaction -Definition

One or more operations, single real-


world transition
Example

– Suppose a bank employee transfers Rs 500 from A's account to B's account.

– This very simple and small transaction involves several low-level tasks.
eXAMPLE

– A’s Account – B’s Account


– Open A’s Account – Open B’s Account
– Balance1 = A.balance; – Balance1 = B.balance;
– NewBanace=Balance1-500; – NewBanace=Balance1+500;
– A.Balance=NewBalance; – A.Balance=NewBalance;
– Close A’s Account – Close B’s Account
ACID
ACID Properties

– A transaction is a small unit of program.


– Contains several low level tasks.
– A transactions in DB must maintain ACID properties.
– Atomicity, Consistency, Isolation, and Durability
Atomicity,
Consistency,
Isolation, Durability

ACID
Atomicity

– In a transaction connecting two or more separate pieces of data, either all the
pieces are committed, or none are.

– Two possible outcomes for a transaction


– It commits: all the changes are made
– It aborts: no changes are made
Consistency

– The database must remain in a consistent state after any transaction.


– The state of the database is restricted by integrity constraints
– Constraints may be explicit or implicit
Isolation

– A transaction executes concurrently with other transaction

– Its effect must be as if each transaction executes in isolation of the others


Durability

– The effect of a transaction must continue to exists after the transaction, or the
whole program has terminated

What it means for us: write data to disk


Example of transaction

– Transfer $50 from account A to Atomicity - shouldn’t take money


account B from A without giving it to B
Read(A) Consistency - money isn’t lost or
A = A - 50 gained

Write(A) Isolation - other queries shouldn’t see


A or B change until completion
Read(B)
Durability - the money does not go
B = B+50
back to A
Write(B)
The Transaction Manager

– The transaction manager enforces the ACID properties


– It schedules the operations of transactions
– COMMIT and ROLLBACK are used to ensure atomicity
COMMIT and ROLLBACK

– COMMIT signals the successful end of a transaction


– Any changes made by the transaction should be saved
– These changes are now visible to other transactions
– ROLLBACK signals the unsuccessful end of a transaction
– Any changes made by the transaction should be undone
– It is now as if the transaction never existed

You might also like