A logical unit of work consisting of one or more statements. The effects of the transaction only becomes permanent when the transaction is completed successfully.
An application program may contain several transactions.
The basic data operations are read and write. A read operation will:
- Find the address of the disk block that contains the item
- Copy that block into a buffer in main memory
- Copy the item from the buffer to a program variable
A write operation will:
- Find the address of the disk block that contains the item
- Copy the block into a buffer in main memory
- Copy the item from the program variable into the correct location in the buffer
- Copy the updated buffer back to disk, either immediately or at some later point in time
A transaction can be in the following states:
- Active: running read/write operations
- Partially committed: all writes to memory finished; DBMS performs housekeeping (logs changes etc.)
- Committed: all changes copied from memory to disk
The transaction can be aborted when in the active or partially committed states.
Concurrent Execution of Transactions
Multi-user systems:
- Single-user system: at most one user can use the system at a time
- Multi-user system: many users can access the system concurrently
Concurrency:
- Interleaved processing: transactions run interleaved in a single CPU
- Parallel processing: transactions concurrently executed in multiple CPUs
Lost Update Problem
When two transactions that update the same database items have their operations interleaved in a way that makes the value of some database item incorrect.
Example:
Transaction 1 | Transaction 2
|
read_item(X) |
X := X - N |
| read_item(X)
| X := X + M
|
write_item(X) <-- This is lost!
| write_item(X)
Temporary Update Problem
One transaction updates a database item but the transaction fails. Another transaction accesses the updated item before it is reverted to its original value.
Reading the uncommitted value is called a dirty read.
Example:
Transaction 1 | Transaction 2
read_item(X) |
X := X - N |
write_item(X) |
| read_item(X) <- Dirty Read
| X := X + M
| write_item(X)
throw_error() |
undo_change() |
Incorrect Summary Problem
While one transaction is running an aggregate function while other transactions update some of the records, causing the aggregate function to read values both before and after they are updated.
ACID Properties
Atomic: a transaction is either performed entirely or not at all.
Consistent: the transaction will move the database from one consistent state to another.
Isolated: the transaction’s changes should not be visible to other transactions until it is committed - this can solve the temporary update problem.
Durable: once a transaction is committed, system failures will not cause the changes to be lost.
The concurrency system is the primary means by which the isolation property is preserved, and supports the atomicity and consistency properties.
The recovery system is the primary means by which the atomicity and durability properties are preserved, and supports the consistency and isolation properties.
Concurrency Control and Recovery
Not covered due to time limitations.