1. Module IV – Concurrency Control & Recovery Management
DBMS (CSEN 3101) – BTech/CSE(AIML) – 3rd yr (5th Sem)
Prepared by Dr. Nilina Bera, CSE, HITK
2. A transaction is an atomic unit of execution, i.e., it is a sequence of
operations which either are performed in entirety or are not performed
at all.
Properties:
1. A Ti preserves the consistency of a database.
2. A Ti terminates in finite time.
What is termination? 🡪 Commit operation.
1. Ensures integrity, recovery & concurrency control.
2. Isolation
3. Serializability
A transaction Ti that does not modify any data object but just
performs read-operation is referred to as read-only transaction or
query. A Ti that modifies at least one ds is known as an update
transaction or an update or write-operation.
Transactions
3. A transaction Ti can be viewed as a partially ordered set (Si , <i )
where Si is the set of read and write actions of the transaction and
<i dictates the order in which these actions must be executed.
Ex:- For the purpose of concurrency control & serializability, a
transaction Ti can be considered as a sequence, {a1(d1), a2(d2),
a3(d3),…,an(dn)} of n steps, where, ai= action at step i, action like
read and write
di=data object acted upon at step i.
Summary of Transaction:
1) Group of actions (read and/or write) performed by an user
with a DBMS is referred to as a transaction (Ti).
2) Ti is an atomic unit of execution.
3) Begin Transaction to Commit transaction
4) Begin Transaction to Abort transaction
5) Begin Transaction can be X (System forces abort)
Transactions
7. Conflicts during transactions handling
Conflict occurs if two transactions T1 and T2 access the same shared
data object(s), ds at a particular time instant, Ti, and AT LEAST
ONE OF THEM IS A WRITE ACTION. There can be conflict if T1
wants to read ds and T2 wants to write (update/insert/delete) the same
ds at the same time instant.
RS (Read-set); WS (Write-set);
Transaction Conflict type
T1, T2 r-w, w-r, w-w
Action 🡪 RS(T1) ∩ WS(T2) ≠ ø (null)
WS (T1) ∩ RS(T2) ≠ ø (null)
WS (T1) ∩ WS (T2) ≠ ø (null)
8. Three transactions with their read-sets and write-sets :-
T1: RS(T1) = {d1, d3, d5}; WS(T1) = {d3, d6};
T2: RS(T2) = {d2, d4, d5}; WS(T2) = {d2, d4, d6};
T3: RS(T3) = {d1, d2, d4}; WS(T3) = {d2, d4};
T1 has w-w conflict with T2, WS(T1) ∩ WS(T2) = d6.
T2 has r-w, w-r and w-w conflicts with T3,
RS(T2) ∩ WS(T3) = {d2, d4}
WS(T2) ∩ RS(T3) = {d2, d4}
WS(T2) ∩ WS(T3) = {d2, d4}
T3 has no conflict with T1.
Conflicts during transactions handling
9. Serializability in a centralized database
A schedule (or a history or log) is a sequence of operations
performed by transactions (T1, T2,….,Tn). Let, S be a schedule;
comm. 🡪 commit Ti ; data-items🡪 {x, y, z}; r(x)🡪 read x; w(y)🡪
write y; .
T1 T2 T3
r(x), w(x), comm.
r(y), w(y), comm.
r(z), w(z), comm.
S =
Ex-1: S1=r(x)w(x)comm.r(y)w(y)comm.r(z)w(z)comm.
i.e., S1=r(x)w(x)r(y)w(y)r(z)w(z) ---------------------------(1)
Ex-2: S2=ri(x)rj(x)wi(y)rk(y)wj(x); T={Ti, Tj, Tk};
Data-items = {x, y} --------------------------------- (2)
10. Serializability of a set of transactions
■ Two transactions, Ti and Tj execute serially in a schedule S1
(equation-1), if the last operation of Ti precedes the first operation of
Tj in S1; otherwise, they execute concurrently.
S2 (equation-2) is NOT serial.
❑ A serial schedule, S2 = ri(x) wi(x) ri(y) rj(x) wj(y) rk(y) wk(x);
Serial(S2) = Ti.Tj.Tk 🡪Ti < Tj < Tk
S2 =
Ti Tj Tk
r(x)
w(x)
r(y)
r(x)
w(y)
r(y)
w(x)
Oi
Oj
Ok
Oi < Oj < Ok , i.e.,
operation Oi precedes
Oj and Oj precedes Ok.
Read and write
operations on data
objects x and y.
11. ■ As serial execution of transactions are time-
consuming, inefficient and not cost-effective,
transactions should execute as concurrently as
possible with correct execution, i.e., we define
the concept of serializability as “a schedule is
correct if it is serializable, i.e., it is
computationally equivalent to a serial
schedule.”
Serializability of a set of transactions
12. Definition of correctness for a non-serial schedule
Given three transactions, T1, T2 and T3 as follows:
T1 = r1(x).r1(z).w1(x)
T2 = r2(y).r2(z).w2(y)
T3 = w3(x).r3(y).w3(z)
The above set of transactions are associated with the schedules as follows:
S1 = w3(x).r1(x).r3(y).r2(y).w3(z).r2(z).r1(z).w2(y).w1(x);
Or
S1′ = w3(x).r1(x).w1(x).r3(y).r2(y).w2(y).w3(z).r2(z).r1(z);
T3 T2
T1
S1′ and S2′
both are
conflict
serializable.
S2 = w3(x).r3(y).w3(z).r2(y).r2(z).w2(y).r1(x).r1(z).w1(x);
Or
S2′ = w3(x).r1(x).w1(x).r3(y).r2(y).w2(y).w3(z).r2(z).r1(z);
13. Equivalence of two schedules:
Condition 1: Each read operation reads data values
which are produced by the same write operations in
both schedules.
Condition 2: The final write operation on each data
item is the same in both schedules.
In order to apply these two conditions in the analysis of
concurrency control mechanisms, the conflict between operations
is defined as:
1. Two operations are in conflict if they operate on the same
data item.
2. One of them is a write operation.
3. The operations/actions are issued by different transactions.
14. Serializability of schedules
❑ When several transactions are executing concurrently then the
order of execution of various instructions is known as a
schedule.
❑ The concept of serializability of schedules is used to identify
which schedules are correct when transaction executions have
interleaving of their operations in the schedules.
Types of schedules
❑Serial schedules
❑Non-serial schedules
❑Conflicting schedules
❑View Schedules
15. Serial Schedules
Serial Schedule A Serial Schedule B
T1:
Read-item(X)
X:=X-N
Write-item(X)
Read-item(Y)
Y:=Y+N
Write-item(Y)
T2:
Read-item(X)
X:X+M
Write-item(X)
T2:
Read-item(X)
X:=X+M
Write-item(X)
T1:
Read-item(X)
X:X+N
Write-item(X)
Read-item(Y)
Y:=Y-N
Write-item(Y)
16. ■ Two schedules A and B are called serial
schedule if the operations of each
transaction are executed consecutively,
without any interleaved operations from the
other transaction. T1 is performed first,
then T2 follows T1 (T1<T2) or T2 is
performed, then T1 follows T2 (T2<T1).
Serial Schedules
18. Serial vs Non-Serial Schedules
Serial Schedule Non-Serial Schedule
A serial schedule is a sequence of
operation by a set of concurrent
transaction that preserves the
order of operations in each of the
individual transactions.
A non-serial schedule is a
schedule where the operations of
a group of concurrent
transactions are interleaved.
Transactions are performed
in serial order.
Transactions are performed
in non-serial order, but
result should be same as
serial.
EXAMPLE:
If some transaction T is long, the
other transaction must wait for T to
complete all its operations.
EXAMPLE:
In this schedule the execution of
other transaction goes on without
waiting the completion of T
19. Conflict Serializability examples:
Consider two transactions T1 and T2 and four schedules S1, S2, S3,
S4 of T1 and T2 as given below:
T1: r1[x] w1[x] w1[y]
T2: r2[x] r2[y] w2[y]
S1: r1[x] r2[x] r2[y] w1[x] w1[y] w2[y]
S2: r1[x] r2[x] r2[y] w1[x] w2[y] w1[y]
S3: r1[x] w1[x] r2[x] w1[y] r2[y] w2[y]
S4: r2[x] r2[y] r1[x] w1[x] w1[y] w2[y]
Which of the above schedules are conflict serializable?
a) S1 and S2 b) S2 and S3 c) S3 only d) S4 only
20. Conflict Serializability examples (continued):
S1: Check out conflicting actions:
1. r1(x) : Read action on data item x is the starting point (from
transaction T1), but no conflicting actions between T1 and T2 on
data-item x, {r1(x), r2(x), w1(x)}.
2. {r2(x), w1(x)} 🡪 Conflict T2 and 1 on data-item=x, T2 < T1
or T2 🡪 T1, i.e, T2 precedes T1.
3. Data-item y: {r2(y), w1(y), w2(y)}
Conflicts 🡪 {r2(y), w1(y)} 🡪 T2 < T1 🡪 T2 🡪 T1
Conflicts 🡪 {w1(y), w2(y)} 🡪 T1 < T2 🡪 T1 🡪 T2
The above analysis denotes that S1 is NOT conflict serializable,
because serialization graph is Cyclic.
T
1
T
2
y
y
21. Conflict Serializability examples (continued):
S2: Grouping of events: {r1(x), r2(x), w1(x)} and {r2(y), w2(y), w1(y)}
Conflicting operations involving T1 and T2 with data-item x 🡪 {r2(x),
w1(x)} 🡪 T2 🡪 T1 (T2 < T1).
In the same transaction, read – write operations on the same data-item is
OK, i.e., {r2(y), w2(y)} is without conflict.
Conflicting operations involving T1 and T2 with data-item y 🡪 {r2(y),
w1(y)} and {w2(y), w1(y)}🡪 (T2 🡪 T1) 🡪 (T2 < T1).
Thus, S2 is conflict serializable.
T2 T1
Serialization
Graph
22. Conflict Serializability examples (continued):
S3: Grouping of events: {r1(x), w1(x), r2(x)} and {w1(y), r2(y), w2(y)}
Conflicting operations involving T1 and T2 with data-item x 🡪 {w1(x),
r2(x)} 🡪 T1 🡪 T2 (T1 < T2).
Conflicting operations involving T1 and T2 with data-item y 🡪 {w1(y),
r2(y)} and {w1(y), w2(y)}🡪 (T1 🡪 T2) 🡪 (T1 < T2).
Thus, S3 is conflict serializable.
T1 T2
Serialization
Graph
23. Conflict Serializability examples (continued):
S4: Grouping of events: {r2(x), r1(x), w1(x)} and {r2(y), w1(y), w2(y)}
Conflicting operations involving T1 and T2 with data-item x 🡪 {r2(x),
w1(x)} 🡪 T2 🡪 T1 (T2 < T1).
Conflicting operations involving T1 and T2 with data-item y 🡪 {r2(y),
w1(y)} and {w1(y), w2(y)}🡪 Edges created for the serialization graph
(SG) (T1 🡪 T2) and (T2 🡪 T1).
Thus, S4 is NOT conflict serializable because SG is cyclic.
T1 T2
Serialization
Graph
Ans: (b) S2 and S3; (c.) S3
24. Conflict Serializability examples (continued):
Consider the following schedules, S1 and S2
involving two transactions, T1 and T2.
S1: r1(x), r1(y), r2(x), r2(y), w2(y), w1(x)
S2: r1(x), r2(x), r2(y), w2(y), r1(y), w1(x)
Select the correct option:
(a) S1 is not conflict serializable and S2 is conflict
serializable.
(b) Both S1 and S2 are conflict serializable.
(c) S1 is conflict serializable and S2 is not conflict
serializable.
(d) Both S1 and S2 are not conflict serializable.
25. Conflict Serializability examples (continued):
S1: Grouping actions involving T1 and T2 on data-item
x 🡪 {r1(x), r2(x), w1(x)}; {r1(y), r2(y), w2(y)};
Conflicts: {r2(x), w1(x)}; {r1(y), w2(y)}
Edges: T2 🡪 T1; T1 🡪 T2
Serialization Graph: Cyclic T
1
T
2
S2: Grouping actions involving T1 and T2 on data-item
x 🡪 {r1(x), r2(x), w1(x)}; {r2(y), w2(y), r1(y)};
Conflicts: {r2(x), w1(x)}; {w2(y), r1(y)}
Edges: T2 🡪 T1; T2 🡪 T1
Serialization Graph: Not Cyclic.
T
1
T
2
Ans: (a)
26. Conflict Serializability examples (continued):
“In a concurrent schedule, set of transactions may conflict” -- Justify
Conflicting operations in concurrent schedule (type consistent), T1
initiating W(B) [write on data-item B], without commit, if T2
initiates read operation on the same data-item B [R(B)]. Similarly,
in “inconsistent”-concurrent schedule, T1🡪W(A) and T2🡪R(A)
[without commit]; T2🡪R(B) and T1🡪W(B) are conflicting
operations.
27. • When are two schedules conflict equivalent?
• What is a conflict serializable schedule?
• What is a strict schedule?
What is a precedence graph or serializability
graph? How is it related to conflict serializability?
How is it related to two-phase locking?