Unit 4
Unit 4
Branch - CSE
Database Management System
UNIT - IV, Lecture – 1
Serial Schedule
The Schedules S1 & S2 execute the transactions T1 and T2 serially i.e. T1 followed by
T2 in Schedule S1 and T2 followed by T1 in Schedule S2. Such Schedules are called
serial schedules. Execution of Serial Schedules would preserve consistency of the
database; without requiring any additional mechanism. But, such schedules do not
exploit the potential parallelism amongst the transactions.
Concurrent Schedules
When more than one Transaction are taken up for execution at the same time (concurrently),
the system would schedule one of the concurrent transactions (say Ti) to take control of the
CPU. During the execution, when Ti request I/O, then Ti would go to a ‘wait’ state, waiting for
completion of its I/O. since, the CPU would now be free, the system would schedule another
concurrent transaction (say Tj) that may be ready to take control of CPU.
Execution Schedule of Transactions
Concurrent Schedules
Execution Schedule of Transactions
Concurrent Schedules
Execution Schedule of Transactions
Equivalent Schedules
Two Schedules S and S’ are said to be Equivalent, if when
executed independently, each of the schedules transforms the
affected database from a consistent state S1 to another
consistent state S2.
Serializable Schedules
Suppose S is a Concurrent Schedule and there exists a
Schedule S’, which is serial and logically equivalent to S,
then S is said to be a Serializable Schedule.
THANK YOU
Serialization
If left entirely to the Operating System, to decide on the interleaving
of the concurrent transactions, it would not be possible to predict the
end results and the database may be left in an inconsistent state. So, it
is to be ensured by the DBMS that any schedule that executes, must
leave the database in a consistent state. The database component that
ensures this aspect is called concurrency-control-component. The
schedule should in some sense be equivalent to a serial schedule.
This process is called serialization.
Types of Serializability
Types of Serializability The serializability of schedules is of two types:-
• Conflict Serializability
• View Serializability
Conflict Serializability
A conflict-serializable schedule will also be view-serializable, but reverse may not be true.
Cascading Rollbacks
Suppose a Transaction Ti modifies a data item Q and the modified value of Q is read by another
Transaction Tj before transaction Ti COMMITS. Now, suppose Ti fails during its execution and it has to
be rolled-back. So, the value of data item Q, which Tj has read is undone by the rolling-back of Ti.
Thus, any computation performed by Tj , based on this value of Q, would cause database
inconsistencies. Thus, when transaction Ti fails during its execution, and it has to be rolled back, we
also have to rollback those transactions, which might have read the data items modified by Transaction
Ti. Such a Rollback is called a Cascading Rollback.
Cascading Rollbacks
In the Schedule S10, Since T2 reads the value of data item A, after
it has been already modified by T1, but before T1 commits and also
T3 reads the value of data item A as modified further by T2 but
before T1 commits and T2 commits. In this case, if T1 fails during
its subsequent execution before it Commits, then T2 and T3 also
must rollback along with T1. This kind of rollback is called
Cascading Rollback.
Cascade-less Schedules
The need of Cascading Rollbacks can be effectively obviated by imposing a restriction on the
schedules that the data items, modified by a Transaction Ti, must not be permitted to be read by other
concurrent transactions, till Ti Commits. Such Schedules are called Cascade-less Schedules. The
Cascade-less Schedules obviate the need of Cascading Rollbacks.
Recoverable Schedules
AND
It is a Cascade-less.
THANK YOU
DR. APJ ABDUL KALAM TECHNICAL UNIVERSITY
Branch - CSE
Database Management System
UNIT - IV, Lecture – 3
1. All the updates, made by the program since the previous COMMIT POINT, are
committed i.e. are made PERMANENT.
2. All database pointers (i.e. addressability to certain tuples) and all tuple- locks
will be released.
System Recovery
There are two types of System Failures:-
A local failure affects only the transaction, during the execution of which the
failure has occurred.
A global failure affects all the transactions that may be in progress at the time of
failure. Such failure fall into two broad categories:-
1. System Failure (e.g. Power Failure) This affects all transactions currently in
progress but does not physically damage the database. This failure is called soft
crash.
2. Media Failure (e.g. Disk Head Crash) It causes damage to the database, or to
some portion of it, and affects those transactions currently using that portion of
the database. A media failure is called hard crash.
Modes of Database Updates
Immediate Update
When an active Transaction Ti updates a data item Q, the update is immediately
reflected in the database (on stable storage) even before Ti Commits. In this case,
there will be a requirement to UNDO the updates of those transactions, which fail
before Commit Point is reached. Another limitation of this mode of update is that
for each update, the system has to perform a Disk-Write, that too on sectors which
may be widely separated. This involves significant overheads of Disk Seek Time.
There may be some transactions, which might have already committed prior to the
system failure, but not managed to get their updates transferred from the database
buffers to the physical database. Such transactions will need to be redone.
Recovery from System Failures.
Which failed transactions to be UNDONE and which transactions to be
REDONE?
1. Physically writing (force-writing) the contents of the database buffers into the
physical database.
Lock-X (A);
Lock-X (C);
Lock-X (F);
Access (F);
Unlock (F);
Unlock (C);
Lock-X (B);
Lock-X (E);
Access( E);
Unlock (E);
Access (B);
Unlock (B);
Unlock (A);
Deadlock Detection & Recovery
Deadlock Recovery will involve Roll-back of some of the
transactions involved in the Deadlock; but before that a
deadlock needs to be detected.
Deadlock Detection
1. Selection of Victims for Roll-Back: The Criteria for selection of victim would take into
consideration:-
- The amount of work already completed by the transaction. Since this work will be undone during
the roll-back, so a transaction which has completed lesser work should be a preferred as a victim.
- The amount of work yet to be completed. This information is difficult to get. However, if this
information is available, then the transaction, which is still farther from the end, should be preferred as a
victim. A Transaction, which is near its end, should not be rolled-back.
- The Number of resources locked by the Transaction . If a transaction with large number of
resources locked by it is rolled back, then large number of resources will get free, which may meet the
need of large number of waiting transaction.
Deadlock Recovery
2. Roll Back the selected Transaction. With the help of log file entries, the data items
modified by this transaction will be reverted back to their old values. Also, the data items,
currently locked by this transaction, will be unlocked. So, the other transactions, awaiting
lock on such data items, will be able to proceed and the deadlock will be broken.
3. Restart the Rolled-Back Transaction. Once the deadlock is broken, the rolled-back
transaction is restarted.
1. The work already performed by the rolled-back transaction is undone. In fact, undoing
it also needs more work to be performed. So, system throughput gets affected
adversely.
2. There is always a possibility that a Transaction may face roll-back again and again and
may never get completed; thus facing starvation.
THANK YOU
DR. APJ ABDUL KALAM TECHNICAL UNIVERSITY
Branch - CSE
Database Management System
UNIT - IV, Lecture – 4
• Geographically dispersed
• Vary in size & function (may vary from workstation to mainframe)
• Separately administered
• Inter-connected by WAN/LAN using different communication media.
Node or Site
(a) Local Transaction A transaction, which accesses only the database that is
stored at the local site i.e. the site where the transaction was initiated.
(a) Transaction Manager Each site will have a local Transaction Manager,
whose function will be to ensure ACID properties of those transactions (or
sub-transactions) that execute at that site. Various Transaction Managers
cooperate with each other, to execute the Global Transactions. It is responsible
for:-
• Maintaining a log, for recovery purposes.
• Participating in an appropriate concurrency-control scheme, to coordinate
the concurrent execution of transactions executing at that site.
System Structure for Distributed Transaction
Processing
(b) Transaction Coordinator It coordinates the execution of transactions
(both local and global) initiated at that site. For each such transaction, the
coordinator is responsible for:-
A distributed system will have all those failure modes, which occur in
centralized systems. In addition, it will have some failure modes, which are
typical only to distributed environment:-
- For Read, the data item can be read from any of the sites, where replica of
the data item exists.
- For Write, all replicas of the data item have to be updated.
For unlock, only a single message is required to be sent from the site releasing
a lock to the site Si.
Advantages:-
Simple implementation.
Simple deadlock handling, since all data items are centrally controlled.
Disadvantages:-
Site Si becomes a bottle-neck, since all requests have to be processed there.
Locking Protocols
(b) Distributed Lock Manager The lock manager function is distributed over
several sites. Each site administers the lock management of data items stored
at that site. Here, since the lock manager function is distributed over a large
number of sites, the approach is free of the limitations of a centralized
approach. However, deadlock handling is complex in this case.
THANK YOU