Unit-IV
Unit-IV
o The system should ensure that updates of a partially executed transaction are not reflected in
the database
Durability requirement — once the user has been notified that the transaction has completed (i.e., the
transfer of the $50 has taken place), the updates to the database by the transaction must persist even if
there are software or hardware failures.
o A schedule for a set of transactions must consist of all instructions of those transactions
o Must preserve the order in which the instructions appear in each individual transaction.
A transaction that successfully completes its execution will have a commit instructions as the last statement
A transaction that fails to successfully complete its execution will have an abort instruction as the last
statement
Schedule 1
Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B.
Schedule 2
Schedule 3
Let T1 and T2 be the transactions defined previously. The following schedule is not a serial schedule, but
it is equivalent to Schedule 1.
Schedule 4
The following concurrent schedule does not preserve the sum of “A + B”.
Serializability
Basic Assumption – Each transaction preserves database consistency.
Thus, serial execution of a set of transactions preserves database consistency.
A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of
schedule equivalence give rise to the notions of:
1. conflict serializability
2. view serializability
4|Page PRAMOD KUMAR(ASST.PROF.)
Conflicting Instructions
Let li and lj be two Instructions of transactions Ti and Tj respectively. Instructions li and lj conflict if and
only if there exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q.
1. li = read(Q), lj = read(Q). li and lj don’t conflict.
2. li = read(Q), lj = write(Q). They conflict.
3. li = write(Q), lj = read(Q). They conflict
4. li = write(Q), lj = write(Q). They conflict
Intuitively, a conflict between li and lj forces a (logical) temporal order between them.
o If li and lj are consecutive in a schedule and they do not conflict, their results would remain the
same even if they had been interchanged in the schedule.
If a schedule S can be transformed into a schedule S´ by a series of swaps of non-conflicting instructions,
we say that S and S´ are conflict equivalent.
We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule
Schedule 3 can be transformed into Schedule 6 -- a serial schedule where T2 follows T1, by a series of
swaps of non-conflicting instructions. Therefore, Schedule 3 is conflict serializable.
We are unable to swap instructions in the above schedule to obtain either the serial schedule < T3, T4
>, or the serial schedule < T4, T3 >.
Recoverable Schedules
Recoverable schedule — if a transaction Tj reads a data item previously written by a transaction Ti ,
then the commit operation of Ti must appear before the commit operation of Tj.
The following schedule is not recoverable if T9 commits immediately after the read(A) operation.
If T8 should abort, T9 would have read (and possibly shown to the user) an inconsistent database state.
Hence, database must ensure that schedules are recoverable.
Cascadeless Schedules
Cascadeless schedules — 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.
Every cascadeless schedule is also recoverable
It is desirable to restrict the schedules to those that are cascadeless
Example of a schedule that is NOT cascadeless
E={e1,e2,e3………………em}.
The graph contains one node for each Transaction Ti. An edge ei is of the form Tj –> Tk where Tj is the starting
node of ei and Tk is the ending node of ei. An edge ei is constructed between nodes Tj to Tk if one of the operations
in Tj appears in the schedule before some conflicting operation in Tk.
2. For the conflicting pair r1(x) w2(x), where r1(x) happens before w2(x), draw an edge from T1 to T2.
3. For the conflicting pair w2(x) w1(x), where w2(x) happens before w1(x), draw an edge from T2 to T1.
Since the graph is cyclic, we can conclude that it is not conflict serializable to any schedule serial schedule.
2. Consider the schedule S1 S1: r1(x) r3(y) w1(x) w2(y) r3(x) w2(x)
View Serializability
Let S and S´ be two schedules with the same set of transactions. S and S´ are view equivalent if the
following three conditions are met, for each data item Q,
1. If in schedule S, transaction Ti reads the initial value of Q, then in schedule S’ also transaction Ti
must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was produced by transaction Tj (if
any), then in schedule S’ also transaction Ti must read the value of Q that was produced by the
same write(Q) operation of transaction Tj .
7|Page PRAMOD KUMAR(ASST.PROF.)
3. The transaction (if any) that performs the final write(Q) operation in schedule S must also perform
the final write(Q) operation in schedule S’.
As can be seen, view equivalence is also based purely on reads and writes alone.
Every view serializable schedule that is not conflict serializable has blind writes.
o Extension to test for view serializability has cost exponential in the size of the precedence graph.
The problem of checking if a schedule is view serializable falls in the class of NP-complete problems.
However, practical algorithms that just check some sufficient conditions for view serializability can still
be used.
Failure Classification
Transaction failure:
o Logical errors: transaction cannot complete due to some internal error condition
o System errors: the database system must terminate an active transaction due to an error
condition (e.g., deadlock)
System crash: a power failure or other hardware or software failure causes the system to crash.
o Fail-stop assumption: non-volatile storage contents are assumed to not be corrupted as result
of a system crash
Database systems have numerous integrity checks to prevent corruption of disk data
Disk failure: a head crash or similar disk failure destroys all or part of disk storage
Log-based Recovery
Log is a sequence of records, which maintains the records of actions performed by a transaction. It is important
that the logs are written prior to the actual modification and stored on a stable storage media, which is failsafe.
Deferred database modification − All logs are written on to the stable storage and the database is
updated when a transaction commits.
Immediate database modification − Each log follows an actual database modification. That is, the
database is modified immediately after every operation.
Recovery with Concurrent Transactions
When more than one transaction are being executed in parallel, the logs are interleaved. At the time of recovery,
it would become hard for the recovery system to backtrack all logs, and then start recovering. To ease this situation,
most modern DBMS use the concept of 'checkpoints'.
Checkpoint
Keeping and maintaining logs in real time and in real environment may fill out all the memory space
available in the system.
As time passes, the log file may grow too big to be handled at all.
Checkpoint is a mechanism where all the previous logs are removed from the system and stored
permanently in a storage disk.
Checkpoint declares a point before which the DBMS was in consistent state, and all the transactions were
committed.
Recovery
When a system with concurrent transactions crashes and recovers, it behaves in the following manner –
The recovery system reads the logs backwards from the end to the last checkpoint.
It maintains two lists, an undo-list and a redo-list.
If the recovery system sees a log with <Tn, Start> and <Tn, Commit> or just <Tn, Commit>, it puts the
transaction in the redo-list.
10 | P a g e PRAMOD KUMAR(ASST.PROF.)
11 | P a g e PRAMOD KUMAR(ASST.PROF.)