Module 5
Module 5
1. Transaction: 2. Schedule:
• Definition • Types of Schedule
• ACID Properties • Serializability
• Transaction States
MODULE
DISCUSSION
Transaction
It is a collection of operations.
T1
Update Bank DB Select
T3
T2
Insert
1
4/3/2025
ACID Properties
1. 2.
ATOMICITY CONSISTENCY
3. 4.
ISOLATION DURABILITY
1.Atomicity
Transaction must be atomic (all transaction is completed or none)
Read(A)
A:A-100
Write(A)
Read(B)
B:B+100
Write(B)
Commit
2
4/3/2025
2. Consistency
Logically correct which means that the integrity constraint must be maintained so that DB
is in maintained. Example:-
SUM(A,B) SUM(A,B)
Before After
500+200 400+300
3. Isolation 700 700
Transaction will be isolation means before completing a transaction, it should not be visible
to another transaction.
A: 500 B: 200
OR T1 T2
Read(A) Read(B)
Action performed by a transaction will be isolated or A-100 B:B+100
hidden from outside transaction unless until its Write(A)
In T1,
terminal.
A+B= Read(B) Read(A) In T2,
400+300 A+B=
Note:- “The resource data used during B+100 Read(B)
= 700 400+20
execution of first transaction can’t used for Write(B)
0=600
Second transaction unless the first one is completed. ”
4. Durability
All updates done by transactions must become permanent until we changes the values in
DB will not be removed.
Only valid Written data
data is saved will not be
lost
A 0
C 0I 0
D
Transactions Transactions
are all or don’t effect
nothing each other
3
4/3/2025
Transaction state
PARTIAL permanent
COMMITED
COMMITED state
STATE
STATE
ACTIVE TERMINATED
Failure
SATAE STATE
Schedule
“When transaction run concurrently then the higher order of execution is
known as schedule.”
OR
“Schedule is nothing but a representation, it represents the order in which
the operations of the transactions are executed.”
Is it
possible?
T1 T2 T1 T2 T1 T2 T1 T2
T1 O1 O2 O1 A1 O1 O2
O2 A2 A1 O1
T2 A1 A2 A1 O1 O2 A2
A2 O2 A2 A1
Note:-
“All the instructions of each individual transaction will appear in the schedule contact
switching can be done but we cannot change the order of execution.”
4
4/3/2025
Concurrency Control
Concurrency:-executing multiple transactions at a time in a shared DB.
concurrency control deals with interleaved execution of more than one transaction.
Advantage of concurrency :
1. Reduce or decreased waiting time, response or turn around time.
2. Increase throughput or resource utilization.
3. Increase efficiency.
5
4/3/2025
6
4/3/2025
T1 T2
R(X)
R(X)
W(X)
R(X)
7
4/3/2025
Types of Schedule
Conflict
Serializable
Serial View
Schedule
Non-serial Cascading
Recoverable
Cascade less
Non- scheduler
serializable Non
Strict
recoverable
SERIAL SCHEDULE
In serial schedule, a transaction does not start execution until the currently
running transaction finished execution.
This type of execution of transaction is also known as non-interleaved execution.
T1 T2
R(A)
A=A+20
W(A)
Commit
R(A)
A=A+50
W(A)
Commit
8
4/3/2025
DISADVANTAGE:
• Less degree of concurrency
• Throughput is very less
• Resource utilization is not good
NON-SERIAL SCHEDULE
If interleaving of operations is allowed, then there will be non-serial
schedule.
It contains many possible orders in which the system can execute the
individual operations of the transactions.
T1 T2
READ(A)
A=A-10
READ(A)
A=A+50
WRITE(A)
READ(B)
WRITE(A)
B=B+10
WRITE(B)
9
4/3/2025
Conflict serializable
• A schedule is said to be conflict serializable if it can transform into a
serial schedule after swapping of non-conflicting operations.
10
4/3/2025
T1 T2 T3
R(X) T1 T2
W(A)
W(A)
W(A)
T3
T1 T2 T3
A=100 R(A) T1 T2
A-40 W(A)
A-40 W(A)
A-20 W(A)
AFTER A= 0 T3
T1 T2 T3
A=100 R(A)
A-40 W(A) Note: Conflict pairs
NOTE:- BEFORE and AFTER for the same data
A-40 W(A)
are view equivalent item are: RW, WW
A-20 W(A) and WR
A= 0
11
4/3/2025
View serializable
• A schedule will view serializable if it is view equivalent to a serial schedule.
• The view serializable which does not conflict serializable contains blind writes.
NOTE
Conflict Serializable
YES NO
12
4/3/2025
S1: T1 T2 S2: T1 T2
R(A) R(A)
A=A+10 A=A+10
W(A) W(A)
R(A) R(B)
A=A+10 B=B+20
W(A) W(B)
R(B) R(B)
B=B+20 B=B+20
W(B) W(B)
R(B) R(B)
B=B*10 B=B*10
W(B) W(B)
13
4/3/2025
S: T1 T2 T3
R(A)
W(A)
W(A)
W(A)
Non-Serializable
A non-serial schedule which is not serializable is called as a non-serializable
schedule.
14
4/3/2025
Recoverable schedule
“Schedules in which transactions commit only after all transactions whose
changes they read commit are called recoverable schedules.”
Irrecoverable Schedule
If in a schedule,
15
4/3/2025
16
4/3/2025
Recoverable Schedule
Cascading Schedule
If in a schedule, failure of one transaction causes several other dependent
transactions to rollback or abort, then such a schedule is called as
a Cascading Schedule or Cascading Rollback or Cascading Abort.
17
4/3/2025
Cascadeless Schedule
If in a schedule, a transaction is
not allowed to read a data item until the
last transaction that has written it is
committed or aborted, then such a
schedule is called as a Cascadeless
Schedule.
Strict Schedule
If in a schedule, a transaction is
neither allowed to read nor write a
data item until the last transaction that
has written it is committed or aborted,
then such a schedule is called as a Strict
Schedule.
18
4/3/2025
19
4/3/2025
Lock-Based Protocol
In this type of protocol, any transaction cannot read or write data until it
acquires an appropriate lock on it. There are two types of lock:
1. Shared lock (lock-S):
It is also known as a Read-only lock. In a shared lock, the data item can
only read by the transaction. It can be shared between the transactions because
when the transaction holds a lock, then it can't update the data on the data
item.
2. Exclusive lock (lock-X):
In the exclusive lock, the data item can be both reads as well as written
by the transaction. This lock is exclusive, and in this lock, multiple transactions
do not modify the same data simultaneously. S_LOCK(A) X_LOCK(A)
S_LOCK(A) T F
X_LOCK(A) F F
20
4/3/2025
5 lock-S(A)
6 read(A)
7 lock-S(B)
8 lock-X(A)
9 …… ……
21
4/3/2025
Strict 2pl
This requires that in addition to the lock being 2-Phase all Exclusive(X)
locks held by the transaction be released until after the Transaction
Commits.
Advantage:
• Recoverable
• Cascadeless
Hence, it gives us freedom from Cascading Abort which was still there in
Basic 2-PL and moreover guarantee Strict Schedules but still, Deadlocks
are possible!(disadvantage)
Rigorous 2-PL
This requires that in addition to the lock being 2-Phase all Exclusive(X)
and Shared(S) locks held by the transaction be released until after the
Transaction Commits.
Advantage:
• strict Recoverable
• Cascadeless
22
4/3/2025
Conservative 2-PL
This protocol requires the transaction to lock all the items it access
before the Transaction begins execution by predeclaring its read-set
and write-set.
23
4/3/2025
Advantage:
• Ensures Conflict Serializable Schedule.
• Ensures Deadlock Free Schedule
• Unlocking can be done anytime
Disadvantage:
• Unnecessary locking overheads may happen sometimes.
• Cascading Rollbacks is still a problem.
24
4/3/2025
Deadlock
Deadlock
25
4/3/2025
Deadlock Avoidance
Deadlock Detection
26
4/3/2025
The wait for a graph for the above scenario is shown below:
Deadlock Prevention
27
4/3/2025
Wait-Die scheme
If a transaction requests for a resource which is already held with a conflicting
lock by another transaction then the DBMS simply checks the timestamp of
both transactions. It allows the older transaction to wait until the resource is
available for execution.
Let's assume there are two transactions Ti and Tj and let TS(T) is a timestamp
of any transaction T. If T2 holds a lock by some other transaction and T1 is
requesting for resources held by T2 then the following actions are performed by
DBMS:
1. Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held
some resource, then Ti is allowed to wait until the data-item is available for
execution. That means if the older transaction is waiting for a resource which is
locked by the younger transaction, then the older transaction is allowed to wait
for resource until it is available.
2. Check if TS(Ti) < TS(Tj) - If Ti is older transaction and has held some
resource and if Tj is waiting for it, then Tj is killed and restarted later with the
random delay but with the same timestamp.
28