Module 17: Transactions
Database System Concepts, 7th Ed.
©Silberschatz, Korth and Sudarshan�See www.db-book.com for conditions on re-use
©Silberschatz, Korth and Sudarshan
17.1
Database System Concepts - 7th Edition
Outline
©Silberschatz, Korth and Sudarshan
17.2
Database System Concepts - 7th Edition
Transaction Concept
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
©Silberschatz, Korth and Sudarshan
17.3
Database System Concepts - 7th Edition
Example of Fund Transfer
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
©Silberschatz, Korth and Sudarshan
17.4
Database System Concepts - 7th Edition
Example of Fund Transfer (Cont.)
©Silberschatz, Korth and Sudarshan
17.5
Database System Concepts - 7th Edition
Example of Fund Transfer (Cont.)
� T1 T2
1. read(A)
2. A := A – 50
3. write(A)� read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B
©Silberschatz, Korth and Sudarshan
17.6
Database System Concepts - 7th Edition
ACID Properties
A transaction is a unit of program execution that accesses and possibly updates various data items. To preserve the integrity of data the database system must ensure:
©Silberschatz, Korth and Sudarshan
17.7
Database System Concepts - 7th Edition
Transaction State
©Silberschatz, Korth and Sudarshan
17.8
Database System Concepts - 7th Edition
Transaction State (Cont.)
©Silberschatz, Korth and Sudarshan
17.9
Database System Concepts - 7th Edition
Concurrent Executions
©Silberschatz, Korth and Sudarshan
17.10
Database System Concepts - 7th Edition
Schedules
©Silberschatz, Korth and Sudarshan
17.11
Database System Concepts - 7th Edition
Schedule 1
©Silberschatz, Korth and Sudarshan
17.12
Database System Concepts - 7th Edition
Schedule 2
©Silberschatz, Korth and Sudarshan
17.13
Database System Concepts - 7th Edition
Schedule 3
©Silberschatz, Korth and Sudarshan
17.14
Database System Concepts - 7th Edition
Schedule 4
©Silberschatz, Korth and Sudarshan
17.15
Database System Concepts - 7th Edition
Serializability
1. Conflict serializability
2. View serializability
©Silberschatz, Korth and Sudarshan
17.16
Database System Concepts - 7th Edition
Conflicting Instructions
1. li = read(Q), lj = read(Q). li and lj don’t conflict.� 2. li = read(Q), lj = write(Q). They conflict.� 3. li = write(Q), lj = read(Q). They conflict� 4. li = write(Q), lj = write(Q). They conflict
©Silberschatz, Korth and Sudarshan
17.17
Database System Concepts - 7th Edition
Conflict Serializability
©Silberschatz, Korth and Sudarshan
17.18
Database System Concepts - 7th Edition
Conflict Serializability
Ex:
T1
T2
T3
R(X)
R(Y)
R(X)
R(Y)
R(Z)
W(Y)
W(Z)
R(X)
W(X)
W(Z)
T1
T2
T3
Precedence Graph
Conflict pairs
R-W
W-R
W-W
©Silberschatz, Korth and Sudarshan
17.19
Database System Concepts - 7th Edition
Conflict Serializability
Ex:
T1
T2
T3
R(X)
R(Y)
R(X)
R(Y)
R(Z)
W(Y)
W(Z)
R(X)
W(X)
W(Z)
T1
T2
T3
Precedence Graph
Conflict pairs
R-W
W-R
W-W
T2
T3
T1
©Silberschatz, Korth and Sudarshan
17.20
Database System Concepts - 7th Edition
View Serializability
1. If in schedule S, transaction Ti reads the initial value of Q, then in
schedule S’ also transaction Ti must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was
produced by transaction Tj (if any), then in schedule S’ also
transaction Ti must read the value of Q that was produced by the
same write(Q) operation of transaction Tj .
3. The transaction (if any) that performs the final write(Q) operation in
schedule S must also perform the final write(Q) operation in schedule S’.
©Silberschatz, Korth and Sudarshan
17.21
Database System Concepts - 7th Edition
View Serializability (Cont.)
T27
Precedence Graph
T28
T29
©Silberschatz, Korth and Sudarshan
17.22
Database System Concepts - 7th Edition
Lock-Based Protocols
1. exclusive (X) mode. Data item can be both read as well as
written. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is
requested using lock-S instruction.
©Silberschatz, Korth and Sudarshan
17.23
Database System Concepts - 7th Edition
Lock-Based Protocols (Cont.)
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
©Silberschatz, Korth and Sudarshan
17.24
Database System Concepts - 7th Edition
Schedule With Lock Grants
©Silberschatz, Korth and Sudarshan
17.25
Database System Concepts - 7th Edition
Deadlock
�
©Silberschatz, Korth and Sudarshan
17.26
Database System Concepts - 7th Edition
Deadlock (Cont.)
©Silberschatz, Korth and Sudarshan
17.27
Database System Concepts - 7th Edition
The Two-Phase Locking Protocol
Time
Locks
©Silberschatz, Korth and Sudarshan
17.28
Database System Concepts - 7th Edition
The Two-Phase Locking Protocol (Cont.)
©Silberschatz, Korth and Sudarshan
17.29
Database System Concepts - 7th Edition
The Two-Phase Locking Protocol (Cont.)
©Silberschatz, Korth and Sudarshan
17.30
Database System Concepts - 7th Edition
Concurrency Control and Recovery
©Silberschatz, Korth and Sudarshan
17.31
Database System Concepts - 7th Edition
Undo and Redo Operations
©Silberschatz, Korth and Sudarshan
17.32
Database System Concepts - 7th Edition