Transaction Management: Chapter 22.1, 22.2
Transaction Management: Chapter 22.1, 22.2
Basic Concepts
A transaction is any one execution of a user program in a DBMS A transaction is a series of reads and writes of database objects Additional operations:
Locking an object Si(O) by shared lock or Xi(O) by exclusive lock; Unlocking the object Ui(O); Commiti Aborti;
Transaction States
Active transaction Partially committed transaction Committed transaction Failed transaction Aborted transaction
Transaction Properties
Atomicity:
Remove the effect of incomplete transactions to the database Write-Ahead Log The effect of committed transactions is permanently recorded in the database
Durability:
Database Components
Hardware operation
Operations from different transactions on the same data item WR Conflict - reading uncommitted data (dirty read); RW Conflict - unrepeatable read; WW Conflict - overwriting uncommitted data (lost update):
8
Transaction Schedules
A schedule is a sequence of
operations from a set of concurrent transactions that preserves the order of the operations in each of the individual transactions. Must support Isolation property
Schedule Properties
Complete schedule Serial schedule operations from each transaction are executed consequently without interleaved operations from other transactions Nonserial schedule operations from a set of concurrent transactions are interleaved
10
Serializability
Only committed transactions A serializable schedule has the same effect to the database as any serial schedule. Example: Let A=500 and B= 400. Let transaction T1 decreases A by 100 and increase B by 100, and transaction T2 recalculates A=1.1*A and B=1.1*B.
11
One transaction writes a data item while another reads or writes the same data item:
Any write operation W(X) is preceded by R(X) in the same transaction New value of X depends on old value of X The rule is mandatory for all transactions in the schedule
13
Conflict Serializability
If two operations do not conflict they can be swapped If a schedule S can be transformed into schedule S by a series of swaps of nonconflicting operations, S and S are
conflict equivalent
T2
R(B)
W(A) W(B) R(B) W(B) Commit Commit
15
Precedence Graph
Allows to discover conflict serializability of schedule S Contains nodes for each transaction in S Contains an edge from Tl to Tk if Tl precedes Tk and one of the following conflicts occurs:
Tk reads the value of an object written by Tl; Tk writes an object after it has been read by Tl; Tk writes an object after it has been written by Tl.
16
Starting node of an edge (except the first one) is the ending node of the previous one The ending node of the last edge is the starting node of the first edge
Example 2
T1 enters marks for two students 53 and 60 who work as a team (by TA). T2 edits the same marks (by instructor).
T1
W(M53) W(M53) W(M60) W(M60) Commit Commit
18
T2
Example 3
T1 T2 R(X) W(Z) R(Z) T3 T4
W(X)
R(X)
R(Z) W(Z) W(X)
Commit
Commit Commit Commit
19
If an edge Ti Tj exists in the precedence graph for S, then in any conflict equivalent serial schedule S transaction Ti must precede Tj A schedule may have several conflict equivalent serial schedules.
20
A W(X) may not follow the R(X) in the same transaction The new value of X written by an operation W(X) may not depend on old value of X Blind write
21
Example 4
T1 W(X) W(X) T2 R(X) T3
W(X)
Commit Commit Commit
View Equivalence
Two schedules S1 and S2 over the same set of transactions are view equivalent if: If Ti reads the initial value of object A in S1, it must also read initial value of A in S2 If Ti reads a value of A written by Tj in S1, it must also read the value of A written by Tj in S2. For each data object A, the transaction that performs the final write on A in S1 must also perform the final write on A in S2.
23
View Serializability
A schedule is view serializable if it is view equivalent to some serial schedule. Every conflict serializable schedule is also view serializable. Any view serializable schedule, that is not conflict serializable, contains a blind write.
24
Recoverable Schedules
A recoverable schedule is one in which transactions commit only after all transactions whose changes they read commit. Avoid cascading rollback
25
A serializable schedule over a set S of transactions is a schedule with the same effect on a database as some complete serial schedule over the set of committed transactions in S.
26
Example 6
T1 R(X) R(X) W(X) T2
W(X)
Commit Commit
Example 7
T1 R(X) R(Y) W(X) R(X) W(X) R(Y) Commit Commit Commit T2 T3
28