Module_6�Transaction, Management and Concurrency
Ms. Khushbu Tikhe
Assistant Professor
Shree L. R. Tiwari College of Engineering
Transaction
Example
Open_Account(A)
Old_Balance = A.balance
New_Balance = Old_Balance - 500
A.balance = New_Balance
Close_Account(A)
Open_Account(B)
Old_Balance = B.balance
New_Balance = Old_Balance + 500
B.balance = New_Balance
Close_Account(B)
Types of Operation in Transaction
Transaction Structure and Boundaries
ACID Properties in DBMS
Atomicity�
—Abort: If a transaction aborts, changes made to database are not visible.
—Commit: If a transaction commits, changes made are visible.
Consistency
Isolation
Suppose T has been executed till Read (Y) and then T’’ starts. As a result , interleaving of operations takes place due to which T’’ reads correct value of X but incorrect value of Y and sum computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
This results in database inconsistency, due to a loss of 50 units. Hence, transactions must take place in isolation and changes should be visible only after they have been made to the main memory.
Durability:
States of Transactions
State Transition Diagram for a Database Transaction
Let's study a state transition diagram that highlights how a transaction moves between these various states.
Transition State
Serial Execution/Transition/Schedules
Serial Execution/Transition/Schedules
Concurrent Execution/Transition/Schedules
However, there are some good reasons for allowing concurrency:
Serializable Execution/Transition/schedule
1. Conflict Serializability
2. View Serializability
1. Conflict Serializability
Note : read(Q), and read(Q) do not conflict
Conflict Serializability ..........(Cont.)
Conflict Serializability ..........(Cont.)
S1: R1(A), W1(A), R2(A), W2(A), R1(B), W1(B), R2(B), W2(B)
T1: R1(A), W1(A), R1(B), W1(B)
T2: R2(A), W2(A), R2(B), W2(B)
Conflict Serializability ..........(Cont.)
-> Swapping non-conflicting operations R2(A) and R1(B) in S1, the schedule becomes,
S11: R1(A), W1(A), R1(B), W2(A), R2(A), W1(B), R2(B), W2(B)
-> Similarly, swapping non-conflicting operations W2(A) and W1(B) in S11, the schedule becomes,
S12: R1(A), W1(A), R1(B), W1(B), R2(A), W2(A), R2(B), W2(B)
2. View Serializability
View Serializability..........(Cont.)
T1 T2
----- ------
R(X)
W(X)
R(Y)
W(Y)
R(X)
W(X)
R(Y)
W(Y)
Why we need View Serializability?
View Equivalent
1. Initial Read: Initial read of each data item in transactions must match in both schedules. For example, if transaction T1 reads a data item X before transaction T2 in schedule S1 then in schedule S2, T1 should read X before T2.
2. Final Write: Final write operations on each data item must match in both the schedules. For example, a data item X is last written by Transaction T1 in schedule S1 then in S2, the last write operation on X should be performed by the transaction T1.
3. Update Read: If in schedule S1, the transaction T1 is reading a data item updated by T2 then in schedule S2, T1 should read the value after the write operation of T2 on same data item. For example, In schedule S1, T1 performs a read operation on X after the write operation on X by T2 then in S2, T1 should read the X after T2 performs write on X.
Precedence Graph For Testing Conflict Serializability
Example:
Explanation:
Concurrency Control
Potential problems of Concurrency
1. Lost Updates Problems
Here
2. Uncommitted dependency issues
In this example,
T2 reads the dirty value of A written by the uncommitted transaction T1.
T1 fails in later stages and roll backs.
Thus, the value that T2 read now stands to be incorrect.
Therefore, database becomes inconsistent.
3. Inconsistent analysis Problem
Here
4. Dirty read
Here
5. Non-Repeatable Read
6. Incorrect Summary issue
7. Phantom Read Problem:
Concurrency Control Protocol
1. Lock based protocol
Example:
1. Shared Lock (S):
2. Exclusive Lock (X):
Lock Compatibility Matrix
Looking Level
Working of Locking Protocol
Example:
2. Timestamp-based Protocols
Timestamp Ordering Protocol
Thomas' Write Rule
Recovery System
Failure Classification
1. Transaction failure
Failure Classification
2. System Crash/ Hardware Failure:
3. Software Failure
4. Media Failure
5. Network Failure
6. Application Software Error
7. Physical Disasters
Log based Recovery in DBMS
Types of Log Record
Types of Log Record
Types of Log Record
Types of Log Record
Deferred Modification Technique(No-undo/Redo Algorithm)
Cont....
<T0 start>
<T0, A, 950> <TO, A, 1000, 950>
<T0, B, 2050> <TO, B, 2000, 2050>
<T0 commit>
<T1 start>
<T1, C, 600>
<T1 commit>
cont........
Case1:
Case2:
<T0 start>
<T0, A, 950>
<T0, B, 2050>
<T0 commit>
<T1 start>
<T1, C, 600>
Case3:
<T0 start>
<T0, A, 950>
<T0, B, 2050>
<T0 commit>
<T1 start>
<T1, C, 600>
<T1 commit>
Deferred Modification Technique(No-undo/Redo Algorithm)
Immediate Database Update (Undo algorithm)
Cont...
<T0 start>
<T0, A, 1000, 950>
<T0, B, 2000, 2050>
<T0 commit>
<T1 start>
<T1, C, 700, 600>
<T1 commit>
Cont..
Cont....
Case1
<T0 start>
<T0, A, 1000, 950>
<T0, B, 2000, 2050>
Case2
Case3:
Cont.....
Deadlock in DBMS
Deadlock Prevention
Approach_3: Preventation and Transacition rollback
Deadlock Detection
Recovery from Deadlock
Cont...
Ref for protocol