Transaction Management: 15-17.1 José Alferes - Adaptado de Database System Concepts - 5 Edition
Transaction Management: 15-17.1 José Alferes - Adaptado de Database System Concepts - 5 Edition
Transaction Operations
The low level operations performed in a transaction are −
begin_transaction − A marker that specifies start of
transaction execution.
read_item or write_item − Database operations that may
be interleaved with main memory operations as a part of
transaction.
end_transaction − A marker that specifies end of
transaction.
commit − A signal to specify that the transaction has been
successfully completed in its entirety and will not be
undone.
rollback − A signal to specify that the transaction has been
unsuccessful and so all temporary changes in the database
are
José Alferes - Adaptado de undone.
Database A committed
System Concepts
th
- 5 Edition transaction
15-17.4 cannot be rolled back.
Transaction ACID properties
E.g. transaction to transfer €50 from account A to account B:
1. read_from_acoount(A) (Suppose A=100,B=200 A+B=300)
2. A := A – 50 (A=50)
3. write_to_account(A) <---(Power Failure)
4. read_from_accont(B)
Mismatch i.e.
5. B := B + 50 data
6. write_to_account(B) (A+B=50+200=250) inconsistent
Atomicity requirement
if the transaction fails after step 3 and before step 6, money will be “lost”
leading to an inconsistent database state
Failure could be due to software or hardware
the system should ensure that updates of a partially executed transaction
are not reflected in the database
All or nothing, regarding the execution of the transaction
Durability requirement — once the user has been notified of transaction has
completion, the updates must persist in the database even if there are software
or hardware failures.
A=100
A=50
B=200
B=250
SUM=300
A= 50
temp=50*.10=5
A=45
B=250
B=250+5=255
A+B=300
José Alferes - Adaptado de Database System Concepts - 5th Edition 15-17.13
Equivalent Schedule
temp=50*0.1=5
A=50-5=45
B=200
B=200+50=250
B=250
B=250+5=255
A+B=45+255=300
A=90
B=200
B=200+50
B=250
B=250+10=260
T1 T2
R(A)
W(A)
R(A)
W(A)
T1
T2 Precedence Graph
R(A)
W(A)
T1
T2
R(A)
W(A)
W(A)
T1--->T2
OR
T1 T2--->T1
T2
R(A)
W(A)
W(A)
R(A)
W(A)
W(A)
T1--->T2--->T3
T1---->T3---->T2 Factorial of no. of Conflict
T2---->T1----->T3 tractions View
T2----->T3---->T1 3!=6
T3----->T1----->T2
T3----->T2------>T1
José Alferes - Adaptado de Database System Concepts - 5
th
Edition 15-17.21
T1 T2 T3
R(X)
R(Y)
R(X)
R(Y)
R(Z)
W(Y)
W(Z)
R(Z)
W(X)
W(Z)
T3
Consistent
Yes No
View Blind Write
CS Yes No
Check Not View Serializability
Dependency
graph
Final
Write
1-2-3
T1 1-3-2
T2 2-1-3
2-3-1
3-1-2
T3 3-2-1
Schedule 3 Schedule 6
José Alferes - Adaptado de Database System Concepts - 5th Edition 15-17.31
Conflict Serializability (Cont.)
T1 T2 T3 T4 T5
read(X)
read(Y)
read(Z)
read(V)
read(W) T1 T2
read(W)
read(Y)
write(Y)
write(Z)
read(U)
read(Y)
T3 T4
write(Y)
read(Z)
write(Z)
read(U)
write(U) T5
Example 1:
S1: R1(x), W1(x), R2(x), R1(y), R2(y), W2(x), W1(y), C1, C2;
B=20(Suppose)
R(B)
*
Fail At this
point,Transaction
failed due to any
reason
A=10 again
T1 T2
R(A)
A=A-5
W(A)
Commit
R(A)
A=A+2
W(A)
Commit
transaction transaction
with smaller with larger
timestamp timestamp