COMP9315 21T1 ♢ Transaction Processing ♢ [0/12]
A transaction (tx) is ...
- a single application-level operation
- performed by a sequence of database operations
A transaction effects a state change on the DB
COMP9315 21T1 ♢ Transaction Processing ♢ [1/12]
❖ Transaction Processing (cont) | |
Transaction states:
COMMIT
⇒ all changes preserved,
ABORT
⇒ database unchanged
COMP9315 21T1 ♢ Transaction Processing ♢ [2/12]
❖ Transaction Processing (cont) | |
Concurrent transactions are
- desirable, for improved performance (throughput)
- problematic, because of potential unwanted interactions
To ensure problem-free concurrent transactions:
- Atomic ... whole effect of tx, or nothing
- Consistent ... individual tx's are "correct" (wrt application)
- Isolated ... each tx behaves as if no concurrency
- Durable ... effects of committed tx's persist
COMP9315 21T1 ♢ Transaction Processing ♢ [3/12]
❖ Transaction Processing (cont) | |
Transaction processing:
- the study of techniques for realising ACID properties
Consistency is the property:
- a tx is correct with respect to its own specification
- a tx performs a mapping that maintains all DB constraints
Ensuring this must be left to application programmers.
Our discussion focusses on:
Atomicity, Durability, Isolation
COMP9315 21T1 ♢ Transaction Processing ♢ [4/12]
❖ Transaction Processing (cont) | |
Atomicity is handled by the commit and abort mechanisms
- commit ends tx and ensures all changes are saved
- abort ends tx and undoes changes "already made"
Durability is handled by implementing stable storage, via
- redundancy, to deal with hardware failures
- logging/checkpoint mechanisms, to recover state
Isolation is handled by
concurrency control mechanisms
- possibilities: lock-based, timestamp-based, check-based
- various levels of isolation are possible (e.g. serializable)
COMP9315 21T1 ♢ Transaction Processing ♢ [5/12]
❖ Transaction Processing (cont) | |
Where transaction processing fits in the DBMS:
COMP9315 21T1 ♢ Transaction Processing ♢ [6/12]
❖ Transaction Terminology | |
To describe transaction effects, we consider:
-
READ
- transfer data from "disk" to memory
-
WRITE
- transfer data from memory to "disk"
-
ABORT
- terminate transaction, unsuccessfully
-
COMMIT
- terminate transaction, successfully
Relationship between the above operations and SQL:
-
SELECT
produces READ
operations on the database
-
UPDATE
and DELETE
produce READ
then WRITE
operations
-
INSERT
produces WRITE
operations
COMP9315 21T1 ♢ Transaction Processing ♢ [7/12]
❖ Transaction Terminology (cont) | |
More on transactions and SQL
-
BEGIN
starts a transaction
- the
begin
keyword in PLpgSQL is not the same thing
-
COMMIT
commits and ends the current transaction
- some DBMSs e.g. PostgreSQL also provide
END
as a synonym
- the
end
keyword in PLpgSQL is not the same thing
-
ROLLBACK
aborts the current transaction, undoing any changes
- some DBMSs e.g. PostgreSQL also provide
ABORT
as a synonym
In PostgreSQL, tx's cannot be defined inside functions (e.g. PLpgSQL)
COMP9315 21T1 ♢ Transaction Processing ♢ [8/12]
❖ Transaction Terminology (cont) | |
The READ
, WRITE
, ABORT
, COMMIT
operations:
- occur in the context of some transaction T
- involve manipulation of data items X, Y, ...
(READ and WRITE)
The operations are typically denoted as:
RT(X) |
| read item X in transaction T |
WT(X) |
| write item X in transaction T |
AT |
| abort transaction T |
CT |
| commit transaction T |
COMP9315 21T1 ♢ Transaction Processing ♢ [9/12]
A schedule gives the sequence of operations from ≥ 1 tx
Serial schedule for a set of tx's T1 .. Tn
- all operations of Ti complete before Ti+1 begins
E.g.
RT1(A)
WT1(A)
RT2(B)
RT2(A)
WT3(C)
WT3(B)
Concurrent schedule for a set of tx's T1 .. Tn
- operations from individual Ti's are interleaved
E.g.
RT1(A)
RT2(B)
WT1(A)
WT3(C)
WT3(B)
RT2(A)
COMP9315 21T1 ♢ Transaction Processing ♢ [10/12]
Serial schedules guarantee database consistency
- each Ti commits before Ti+1 starts
- prior to Ti database is consistent
- after Ti database is consistent (assuming Ti is correct)
- before Ti+1 database is consistent ...
Concurrent schedules interleave tx operations arbitrarily
- and may produce a database that is not consistent
- after all of the transactions have committed successfully
COMP9315 21T1 ♢ Transaction Processing ♢ [11/12]
What problems can occur with (uncontrolled) concurrent tx's?
The set of phenomena can be characterised broadly under:
- dirty read:
reading data item written by a concurrent uncommitted tx
- nonrepeateable read:
re-reading data item, since changed by another concurrent tx
- phantom read:
re-scanning result set, finding it changed by another tx
COMP9315 21T1 ♢ Transaction Processing ♢ [12/12]
Produced: 11 Apr 2021