Unit IV Transaction
Unit IV Transaction
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Transaction
Unit-4
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Introduction
In general terms, a transaction can be defined as a logically related group of operations. A single
operation is the minimum processing unit that cannot be divided further.
Example 1:A teacher is marking the attendance of a student in the attendance system. The set of
operations would be like this:
1. Read the attendance record balance of a student of a subject.
2. Add the new attendance value to the attendance balance.
3. Write the newly updated attendance balance to the attendance record.
Example 2: A parent is transferring money from his bank account to a university bank account. The
set of operations would be like this:
1. Read parent’s account balance.
2. Deduct the amount from the parent's account balance
3. Write the remaining balance to the parent's account
4. Read university bank account balance
5. Add the amount to the university bank account balance
6. Write the newly updated balance to the university bank account
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Introduction (Cont…)
In the above examples, all the operations are logically related for a
defined purpose and any operation cannot be further subdivided into
further sub-operations.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Transaction in DBMS
In terms of DBMS, a transaction is the execution of a program, a sequence of operations that
accesses or updates the contents of a database.
A transaction is a logical, atomic unit of work that contains one or more SQL statements.
The database operations that form a transaction can be embedded within an application
program or specified interactively via a high-level query language such as SQL.
The actions accomplished in a transaction contain one or multiple database actions such as
retrieve, insert, or update data.
A transaction on the database is either completed in its entirety or not done at all. If the
database was in a consistent state before a transaction, then after execution of the
transaction, the database must be in a consistent state.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Main Memory
Disk
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Main Memory
Disk
Block movements between disk and main memory are initiated through the following two
operations:
Input(B) transfers the physical block B to the main memory
Output(B) transfers the buffer block B to the disk and replaces the appropriate physical
block there.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Using our simple model, we write the above example like this:
In example 1, let's say the attendance record of a student is X; the steps of the transaction are:
1. read (X); (Retrieve the student attendance record X)
2. X = X + 2; (Adding the attendance value 2 to the attendance record)
3. write (X); (Updating the attendance value in student record X)
In example 2, your parent's account is A and your university account is B. You are transferring Rs. 50000
from A to B, the steps of the transaction are:
1. read (A); (Retrieve the value of parent’s account A)
2. A = A - 50000; (Deduct the amount Rs. 50000 from parent’s account A)
3. write (A); (Updating the remaining balance to parent’s account A)
4. read (B); (Retrieve the value of university account B)
5. B = B + 50000; (Add the amount Rs. 50000 from parent’s account A)
6. write (B); (Updating the remaining balance to parent’s account A)
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Failed State
If a transaction is executing and a failure occurs, either a hardware failure or a software failure,
the transaction is aborted from the active state or partially committed state and moves into a
failed state. Also, transactions are moved to this state if any consistency checks performed in a
partially committed state fail.
Terminated State
Either the transaction comes from a “failed state" after rollback or the transaction comes from the
"committed state". Then, the system is consistent and ready for a new transaction and the old
transaction is terminated.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
ACID Properties
ACID is a concept (and an acronym) that refers to the four properties of a transaction in a
database system:
A - Atomicity
C - Consistency
I - Isolation
D - Durability
These properties ensure the accuracy and integrity of the data in the database, ensuring that
the data does not become corrupt due to some failure, guaranteeing the validity of the data even
when errors or failures occur.
The ACID properties allow us to write applications without considering the complexity of the
environment where the application is executed. These are essential for processing transactions in
databases. Because of the ACID properties, we can focus on the application logic instead of
failures, recovery, and data sync.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Atomicity
In the context of databases, atomicity means that either:
The execution of the transaction got completed and committed.
No transaction at all means transaction is aborted.
A transaction must be an atomic unit of work, which means that all the modified
data are performed, or none of them will be. The transaction should be executed
completely or fail. If one part of the transaction fails, all the transactions will fail.
Therefore, the transaction should not occur partially.
In the above-mentioned example 2, let suppose parent account A has Rs. 70000
in his account from which he needs to send Rs. 50000 to university account B. In
account B, a sum of Rs. 100000 is already present. When Rs. 50000 is
transferred to account B, the sum will become Rs. 150000.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Atomicity (Cont…)
In this transaction, there will be two operations that will take place to complete this transaction.
The amount of Rs.50000 that the parent wants to transfer will be debited from his account A
The same amount will get credited to college account B.
During the transaction, suppose the first operation of debit executes successfully, but the credit
operation fails. Thus, in parent account A, the value becomes Rs. 20000, and to that of college
account, it remains Rs. 10000 as it was previously present as shown in Figure 7. 4
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Consistency
A transaction should be consistency preserving, meaning that if it is completely executed
from beginning to end without interference from other transactions, it should take the
database from one consistent state to another.
In the above example, Account A and Account B have Rs. 100000 and Rs. 70000
respectively. So, the total amount is Rs. 100000+ Rs. 70000, i.e., Rs. 170000 before the
transaction. When any transaction is executed, then the total amount should also be Rs.
170000. If the transaction occurs, then Rs. 50000 will be deducted from Account A and
added to Account B. The total amount after the transaction will be Rs. 20000 + Rs.
150000 = Rs. 170000. So, this property ensures the consistency of the database.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Isolation
This property tells us that a transaction should appear as though it is being executed in isolation
from other transactions, even though many transactions are executed concurrently. This means, if
more than one transaction is taking place in parallel, then the occurrence of one transaction will
not affect the other transaction. If any transaction is using a data item, then it can't be used by
other transactions until the first transaction ends.
Example: Suppose we have two transactions, T1 and T2, which are defined as follows.
In transaction T1, a parent is transferring an amount of Rs. 50000 from account A to university
account B. The initial balance of account A is Rs. 70000.
In transaction T2, the bank is adding the interest of 10% in account A.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Isolation (Cont…)
Now, consider a situation where T1 has been executed until A=A-50000 and then T2 starts. Due
to this, transaction T2 reads the incorrect value of A. It reads the value as 70000 and the
operations which should have been performed by taking the value as 20000, T2 will perform by
taking the value as 70000 as shown inFigure 7. 5.This leads to inconsistent results. For example,
the output of the transaction T2 should have been 20000 *.1 =2000, but it will produce the output
as 70000*.1 =7000 as T2 has read the incorrect value of A. This problem happened because the
transaction result of T1 was made available for T2. So to avoid any such problem, the
transactions take place in isolation.
Importantly, this doesn't mean two operations can't happen at the same time. On the contrary,
multiple transactions can occur as long as those transactions have no possibility of impacting the
other transactions simultaneously.
Doing this can impact the speed of transactions as it may force many operations to wait before
they can initiate. However, this tradeoff is worth the added data security provided by isolation.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Durability
Durability ensures that changes made to the database (transactions) that are
successfully committed will survive permanently, even in the case of system
failures.
This ensures that the data within the database will not be corrupted by:
Service outages
Crashes
Other causes of failure
For example, in an application that transfers funds from one account to another,
the durability property ensures that the changes made to each account will not be
reversed.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Concept of Concurrency
The database system can be classified according to the number of users who can use
the system concurrently. A DBMS is a single-user if at most one user can use the
system, and it is a multi-user if many users can use the system simultaneously. This
means the computer runs multiple transactions (programs) at the same time.
For example, an airline reservations system is used by hundreds of travel agents and
reservation clerks concurrently. Systems in banks, insurance agencies, stock exchanges
and the like are also operated by many users who submit transactions concurrently to
the system.
In a single-user database, the user can modify data in the database without concern for
other users modifying the same data at the same time. However, in a multi-user
database, the statements within multiple simultaneous transactions can update the
same data.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Let understand the above-mentioned possible ways with the help of an example.
Suppose there are two students, S1 and S2, who are submitting their fees to college at the
same time (using web/mobile application). S1 is submitting Rs. 2000 in college account (X)
and S2 is submitting Rs. 3000 in college account (X). Assume they have already submitted
Rs. 5000 and Rs. 10000 in the college account. Now there are two transactions T1 and T2,
T1 transaction contains the operations of fee submitting by student S1, and the T2
transaction contains the operations of fee submitting by student S2. Both transactions, T1
and T2, are executing at the same time means executing simultaneously.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Timestamp T1 T2 Remarks
With the help of the above example, when multiple transactions are trying to execute at the same
time in serial or sequential order of execution, we can say that database will be 100 % consistent.
However, this approach of serial execution creates some serious issues like waiting time of other
transactions will increase, the response time of other transactions is increased, resource
utilization is less and in summary, system performance will be very poor.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Interleaving of operations: As there is only one CPU, only one program can be
2200321530021
processed. To avoid excessive delays, concurrent systems execute some
operations from one transaction, then suspend that transaction and execute some
operations from the next transaction, and so on. A transaction is resumed at the
point where it was suspended when it gets its turn to use the CPU again. This is
known as interleaving.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
1 read(X)
2 read(X)
3 X = X + 2000
Table 7. 3: Example-1 of Concurrency 4 X = X + 3000
5 write(X)
6 write(Y)
7 Commit
8 Commit
Timestamp T1 T2
1 read(X)
2 X = X + 3000
3 read(X)
Table 7. 4: Example-2 of Concurrency 4 X = X + 2000
5 write(X)
6 write(X)
7 Commit
8 Commit
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
1 read(X)
2 X = X + 2000
3 read(X)
Table 7. 5: Example-3 of Concurrency 4 X = X + 3000
5 write(X)
6 write(X)
7 Commit
8 Commit
Timestamp T1 T2
1 read(X)
2 X = X + 2000
Table 7. 6: Example-4 of Concurrency 3 write(X)
4 read(X)
5 X = X + 3000
6 write(X)
7 Commit
8 Commit
In all the above-mentioned examples, various operations of the transactions T1 and T2 are
interleaved.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
The problem with concurrency is the high risk of database inconsistency. This property of
DBMS allows many transactions to access the same database at the same time without
interfering with each other. The primary goal of concurrency control is to ensure the atomicity of
the execution of transactions in a multi-user database environment.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedules
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedule 1
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedule 2
A serial schedule where T2 is followed by T1
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedule 3
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedule 4
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Serializability
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Conflicting Instructions
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Conflict Serializability
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Schedule 3 Schedule 6
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
View Serializability
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
If the precedence graph for S has a cycle, then schedule S is not conflict
serializable. If the graph contains no cycles, then schedule S is conflict
serializable.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
The set of edges consists of all edges Ti →Tj for which one of three conditions holds:
1. Ti executes write(Q) before Tj executes read(Q).
2. Ti executes read(Q) before Tj executes write(Q).
3. Ti executes write(Q) before Tj executes write(Q).
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Figure 7. 12 shows the precedence graphs for schedules 3 and 5 that do not
contain cycles. The precedence graph for schedule 9, on the other hand, contains a
cycle, indicating that this schedule is not conflict serializable.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Topological Sorting: It is a special method to arrange the elements of a Directed Acyclic Graph
(DAG). It is used to design the scheduling applications where one job needs to be done before the
other.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
It is important to design recoverable schedules. To achieve this, we need to place restrictions on
the type of schedules permitted in the system.
The type of schedules acceptable from the viewpoint of recovery from transaction failure is:
Recoverable schedule
Cascadeless schedule
Strict schedule
Recoverable schedule: A recoverable schedule is one where, for each pair of transactions Ti
and Tj such that Tj reads a data item previously written by Ti, and the commit operation of Ti
appears before the commit operation of Tj.
Table 7. 24 shows an example of a recoverable schedule where T2 reads the data item written by
T1 and the commit of T1 appears before the commit operation of T2 transactions. Hence, T2
reads the committed value of Q. If later T1 fails due to any reason, then no need to rollback the
dependent transaction T2.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Timestamp T1 T2 Remarks Before Execution Q=20
1 read(Q); F1 faculty readds Q=20
2 Q=Q+30; F1 faculty added his class count Q=20+30
3 write(Q); Now updated Q=50
4 read(Q); at timestamp 4, F2 faculty reads the uncommitted value Q as 50
5 Q=Q+35; Q is modfied to 75 Table 7.23: Irrecoverable schedule
6 write(Q); Q=75 updated on Stale storage/Disk
7 commit ; Faculty 2 committed his execution.
8 Fail Due to any reason Faculty1 action's fails. Uncommitted -->rollback & restart later
After Execution Q=75 which is incorrect
Now consider a situation where Faculty1 updated the count in data item Q about his/her class count
but forgot to make his/her action permanent using commit. After faculty 1, faculty2 updated his count
of attendees in Q and permanently updated his action doing commit at the end. Now, after some
time transaction of Faculty1, i.e., T1 gets failed due to any reason. Because changes are not
permanent, hence rollback occurs, but Q is 75 in the database (committed by faculty2). Such types
of schedules are irrecoverable, resulting in incorrect data.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Cascadeless schedule: A cascadeless schedule is one where, for each pair of transactions Ti and
Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before
the read operation of Tj as shown in Figure 7. 15. It is easy to verify that every cascadeless schedule
is also recoverable.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Cascadeless Schedules
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Cascading Rollbacks
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Timestamp T1 T2 Remarks Before Execution Q=20
1 read(Q); F1 faculty readds Q=20
2 Q=Q+30; F1 faculty added his class count Q=20+30
3 write(Q); Q=50 updated on Stale storage/Disk
4 commit ; Faculty1 committed the Q
5 read(Q); Faculty2 reads committed value of Q using read(Q) as 50 Table 7. 24: Recoverable schedule
6 Q=Q+35; Q is modfied to 75
7 write(Q); Q=75 updated on Stale storage/Disk
8 Fail Due to any reason Faculty1 action's fails. No impact on T2
After Execution Q=75 which is correct and recoverable
T5 T6 T7
Note: Even if a schedule is recoverable, read(A);
to recover correctly from the failure of a read(B);
transaction Ti, we may have to roll back write(A);
several transactions. Such situations read(A);
occur if transactions have read data write(A);
written by Ti, as illustrated in Table 7. 25. read(A);
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Cascading rollback is undesirable since it leads to the undoing of a significant amount of work. It
is desirable to restrict the schedules to those where cascading rollbacks cannot occur. Such
schedules are called cascadeless schedules. Therefore, we must design the cascadeless
schedule.
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Strict schedule: If in a schedule, a transaction is neither allowed to read nor write a data item
until the last transaction that has been written it is committed or aborted and then such a schedule
is called a Strict Schedule, an example is shown in Table 7. 26.
In other words,
The strict schedule allows only committed read and write operations.
A strict schedule implements more restrictions than a cascadeless schedule.
T8 T9
write(A);
commit/rollback; Table 7. 26: Strict schedule
read(A)/write(B);
Note: Strict schedules are stricter than cascadeless schedules. Every strict schedule is a
cascadeless schedule, but vice versa is not true. For easy understanding, looks at Figure 7. 16:
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Recoverability (Cont…)
Problem 1: For the given schedule, which schedule is recoverable?
S1: r1(X), w1(X), r2(X), r1(Y), r2(Y), w2(X), w1(Y), c1, c2;S2: r1(X), r2(X), r1(Z), r3(X), r3(Y),
w1(X),w3(Y), r2(Y), w2(Z), w2(Y), c1, c2, c3;
uc
uc
PD
PD
!
!
W
W
t
t
O
O
N
N
y
y
bu
bu
to
to
ww
ww
om
om
k
k
lic
lic
C
C
.c
.c
w
w
tr re tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
Thank You
59
Copyright © 2021, ABES Engineering College