DBMS Unit-4
DBMS Unit-4
CS3CO39 DBMS
Session: Jan-Jun 2021
Presented By:
Trishna Panse
Prepared by: Trishna Panse, Asst. Asst. Prof., CSE 1
Professor, CSE
Unit-4
Database Transactions Processing: Introduction to Transaction Processing,
Transaction Concepts, Desirable Properties of Transactions, Schedules,
Concepts of Recoverability and Serializability, Concurrency control:
introduction, locking protocols.
Consider the following transaction T consisting of T1 and T2: Transfer of 100 from
account X to account Y.
Isolation:
• This property ensures that multiple transactions can occur concurrently without leading
to the inconsistency of database state.
• Changes occurring in a particular transaction will not be visible to any other transaction
until that particular change in that transaction has been committed.
Durability:
• This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored in and written to disk and they persist even if a
system failure occurs.
• These updates now become permanent and are stored in non-volatile memory.
• Partially Committed –After completion of all the read and write operation the changes
are made in main memory or local buffer. If the changes are made permanent on the Data
Base then state will change to “committed state” and in case of failure it will go to “failed
state”.
• Failed State –When any instruction of the transaction fails it goes to “failed state”.
• Aborted State –After having any type of failure the transaction goes from “failed state”
to “aborted state” and in before states the changes are only made to local buffer or main
memory and hence these changes are deleted or rollback.
• Committed Stage –It is the stage when the changes are made permanent on the Data
Base and transaction is complete and therefore terminated in “terminated state”.
• Terminated State –If there is any roll back or the transaction come from “committed
state” then the system is consistent and ready for new transaction and the old transaction
is terminated. Prepared by: Trishna Panse, Asst.
Professor, CSE
Types of Schedules
T1 T2
R(A)
A B
A=A-50
2000 2000
W(A) 1950 2050
R(B) 1850 2150
B=B+50
W(B)
T1 T2
R(A)
A B A B
A=A-100
2000 2000 1950 2050
W(A)
1950 2050 1850 2150
R(B)
B=B+100
W(B)
R(A) R(A)
A=A-50 A=A-50
R(A)
W(A)
A=A-100
R(A) Serializabl
e W(A)
A=A-100
Concurren W(A)
W(A)
t Schedule R(B)
R(B)
B=B+50
B=B+50 Non
Serializabl W(B)
W(B)
e R(B)
R(B)
Concurrent
B=B+100 B=B+100
Schedule
W(B)
W(B)
A B A B
2000 2000 2000 2000
1950 2050 1900 2050
1850 2150 1950 2150
T2 T1 T2
T1
A B A B A B
A B
1950 2050 2000 2000 2000 2050
2000 2000
1850 2150 2050 1900 2150
19 2050
50
Serializable Concurrent Schedules
The Non-Serial Schedule can be divided further into Serializable and Non-Serializable.
Serializable:
• The non-serial schedule is said to be in a serializable schedule only when it is equivalent
to the serial schedules.
• This is used to maintain the consistency of the database. It is mainly used in the Non-
Serial scheduling to verify whether the scheduling will lead to any inconsistency or not.
• A serializable schedule helps in improving both resource utilization and CPU
throughput.
T1 T2
R(X)
X=X-100
W(X)
R(X)
X=X+50
W(X)
Commit
Commit
This is a recoverable schedule since T1 commits before T2, that makes the value read by
T2 correct.
T1 T2
R(X)
X=X-100
W(X)
R(X)
X=X+50
W(X)
Commit
(Fail)
T2 read the value of A written by T1, and committed. T1 later aborted, therefore the
value read by T2 is wrong, but since T2 committed, this schedule is non-recoverable.
Conflicting operations: Two operations are said to be conflicting if all conditions satisfy:
• Schedule S can be transformed into Schedule S`, a serial schedule where T2 follows T1,
by series of swaps of non-conflicting instructions. Therefore Schedule S is conflict
serializable.
2. For each case where Ti Write(X) then Tj Read(X) , create an edge from Ti to Tj
3. For each case, where Ti Read(X) then Tj Write(X) , create an edge from Ti to Tj
4. For each case, where Ti Write(X) then Tj Write(X) , create an edge from Ti to Tj
T1 T2
R(X) T1 executes W(X) after T2
X=X-50 executes R(X), then edge T2->T1
R(X)
X=X-100
W(X)
R(Y)
T1 T2
W(X)
Y=Y+50
W(Y)
T2 executes W(X) after T1
executes W(X), then edge T1->T2
Cycle is created in graph, so given schedule is non serializable concurrent
schedule.
R(Y) W(X)
R(Y) Can not be
W(X)
interchanged, since
Y=Y+50 W(X)
W(X) and W(X)
W(Y) W(Y) are not compatible
Step2- Try to convert this given schedule into its equivalent serial schedule by swapping
all instructions of a transactions at one place.
Step3- Since, operations can not be interchanged, so given schedule is non serializable
concurrent schedule.
View Equivalent-
• Two schedules S1 and S2 are said to be view equivalent if they satisfy the
following 3 conditions:
• Above two schedules are view equivalent because Initial read operation in S1 is
done by T1 and in S2 it is also done by T1.
• Above two schedules is view equal because Final write operation in S1 is done
by T3 and in S2, the final write operation is also done by T3.
• Above two schedules are not view equal because, in S1, T3 is reading
A
updated by T2 and in S2, T3 is reading A updated by T1.
Schedule S
Schedule S1
The schedule S1 satisfies all 3 conditions. Hence, view equivalent serial schedule is:
T1 → T2 → T3
Prepared by: Trishna Panse, Asst.
Professor, CSE
Outline
■ Lock-Based Protocols
■ Timestamp-Based Protocols
■ Validation-Based Protocols
read_lock(x)
B: if lock(x)=“unlocked”
then, lock(x)= “readlock”
no_of_reads(x) 1 end;
else
wait (until lock(x)=“unlocked”) and lock manager wakeup
transaction
goto B;
end;
write_lock(x)
B: if lock(x)=“unlocked”
then, lock(x)= “writelock”
end;
else
wait (until lock(x)=“unlocked”) and lock manager wakeup
transaction
goto B;
end;
unlock(x)
B: if lock(x)=“writelock”
then, lock(x)= “unlocked”
end;
else if lock(x)= “readlock”
then, no_of_reads(x) no_of_reads(x) -1
if (no_of_reads(x) =0)
end;
■ Disadvantages-
● Not free from deadlock
● Not free from cascading rollback
● May not free from irrecoverable schedule
T1 T2
R(X)
X=X-100
W(X)
R(X)
X=X+50
W(X)
Commit
(Fail)
PrepPare repdparbaeyrde: d a n d c o
P re
Database System Concepts - 6th Edition 15.43 Bhupendr
m pPrP
©Silberschatz, a
Korth l eass
and
i ofe norbc, ChSEal , A ss
dSudarshan
Recoverable Schedule:
• A transaction performs a dirty read operation from an uncommitted
transaction and its commit operation is delayed till the uncommitted
transaction either commits or roll backs then such a schedule is known as
a Recoverable Schedule.
T1 T2
R(X)
X=X-100
W(X)
R(X)
X=X+50
W(X)
Commit
Commit
Method-01:
Method-02:
Check if there exists any dirty read operation.
Case-01:
• If the commit operation of the transaction
performing the dirty read occurs before the commit
or abort operation of the transaction which
updated the value, then the schedule is
irrecoverable.
Case-02: PrePpraerpeadrebdy:aTnrdischonm
ConceptsPa-P6nrcEdition
©Silberschatz, Korth and Sudarshan15.46Database SystemBhupendra o hfaels, sAosrs, tC.
Types of Recoverable Schedules-
1. 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 Casc a
ding Rollback or Cascading
In this sch e d u le ,
• ofI transaction
• The failure t s i mT1 ply leadsbort.
toA
causes the transaction T2 to
rollback. the wastage of CPU time.
• The rollback of transaction T2
causes the transaction T3 to
rollback.
allows o
3. Strict Schedule
• If in a schedule, a transaction is neither allowed
to read nor write a data item until the last
transaction is committed or aborted, then such a
hedule.trictasSc
schedule is called aS
• In other word
s, Strict nly schedule
committed re
allows o ad and
write operations.
■ System crash: a power failure or other hardware or software failure causes the
system to crash.
■ Physical Problems: including fire, power failure, theft, overwriting disks/taps etc.
■ For this, system keeps update information that are made to database into a system
log.
■ System log contains information about start and end of each transaction and any updates
which occur in the transaction.
■ Redo of a log record <Ti, X,V1, V2> writes the new value V2 to X
● redo(Ti) sets the value of all data items updated by Ti to the new
values, going forward from the first log record for Ti
■ This involves examining a transaction for the log entry write_item (T, X, V1, V2) and
setting the value of item x in the database to old-value.
There are two major techniques for recovery from transaction failures:
■ Deferred update
■ Immediate update
■ Before reaching commit, all transaction updates are recorded in the local
transaction workspace.
■ If a transaction fails before reaching its commit point, it will not have
changed the database in any way so UNDO is not needed.
■ However, these operations are recorded in a log on disk before they are applied
to the database, making recovery still possible.
■ If a transaction fails to reach its commit point, the effect of its operation must
be undone i.e. the transaction must be rolled back hence we require both
undo and redo.