Unit-4 Transaction MGMT
Unit-4 Transaction MGMT
Active, the initial state; the transaction stays in this state while it is
executing.
Partially committed, after the final statement has been executed.
At this point, the transaction has completed its execution,
but it is still possible that it may have to be aborted, since
the actual output may still be temporarily residing in
main memory, and thus a hardware failure may preclude
its successful completion.
Failed, after the discovery that normal execution can no longer proceed.
Aborted, after the transaction has been rolled back and the database
has been restored to its state prior to the start of the transaction.
• Committed, after successful completion.
A Simple Transaction Model
A: = A – 50
B: = B + 50
2. View Serializability
Conflict Serializability
Let us consider a schedule S in which there are two
consecutive instructions, Ii and Ij , of transactions Ti and
Tj , respectively (i ≠ j).
If Ii and Ij refer to different data items, then we can
swap Ii and Ij without affecting the results of any
instruction in the schedule.
However, if Ii and Ij refer to the same data item Q, then
the order of the two steps may matter.
Since we are dealing with only read and write
instructions, there are four cases that we need to
consider:-
1. li = read(Q), lj = read(Q).
The order of li and lj does not matter, since the same value of Q
is read by Ti and Tj , regardless of the order.
li and lj don’t conflict.
2. li = read(Q), lj = write(Q).
If Ii comes before lj , then Ti does not read the value of Q that is
written by Tj in instruction lj.
If J comes before I, then Ti reads the value of Q that is written
by Tj. Thus, the order of I and J matters.
They Conflict.
3. li = write(Q), lj = read(Q).
They conflict for the same reason
4. li = write(Q), lj = write(Q). They conflict
Swap the read(B) instruction of T1 with the read(A) instruction of T2.
• Swap the write(B) instruction of T with the write(A) instruction of T .
1 2
T1 T2 T1 T2
Read ( A ) Read ( A )
Write ( A ) Write ( A )
Read ( A ) Read ( A )
Write ( A ) Read ( B )
Read ( B ) Write
(A)
Write ( B ) Write ( B )
Read ( B ) Read ( B )
Write ( B ) Write ( B )
Schedule S1 Schedule S2
T1 T2 T1 T2
Read ( A ) Read ( A )
Write ( A ) Write ( A )
Read ( A ) Read ( B )
Read ( B ) Read ( A )
Write Write
(A) (A)
Write ( B ) Write ( B )
Read ( B ) Read ( B )
Write ( B ) Write ( B )
Schedule S2 Schedule S3
T1 T2 T1 T2
Read ( A ) Read ( A )
Write ( A ) Write ( A )
Read ( B ) Read ( B )
Read ( A ) Read ( A )
Write Write ( B )
(A)
Write ( B ) Write ( A )
Read ( B ) Read ( B )
Write ( B ) Write ( B )
Schedule S3 Schedule S4
T1 T2 T1 T2
Read ( A ) Read ( A )
Write ( A ) Write ( A )
Read ( B ) Read ( B )
Read ( A ) Write ( B )
Write ( B ) Read ( A )
Write ( A ) Write ( A )
Read ( B ) Read ( B )
Write ( B ) Write ( B )
Conflict Serializability
• 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 nonconflicting instructions,
we say that S and S´ are conflict equivalent.
Conflict Serializability
Example of a schedule that is not conflict
serializable:
commits.
Recoverable schedule
Shared mode
In shared mode, Transactions can only read the Data item.
Shared-lock is requested using lock-S instruction. This
mode is used when transaction wants to read data in the
database.
Exclusive mode
In Exclusive mode, Transactions can read as well as write
the Data item. Exclusive-lock is requested using lock-X
instruction.
Two phase locking protocol
Write(A)
UNLOCK(A)
UNLOCK(B)
LOCK-X(A)
Read(A)
Write(A)
UNLOCK(A)
LOCK-S(A)
Read(A)
Time stamp based protocol
1. System Clock
2. Logical Counter
1. Suppose Ti Reads
a. if TS(Ti) < W-TS(Q) Reject read
b. if TS(Ti) >= W-TS(Q) read operation executed
2. Suppose Ti Writes
a. if TS(Ti) < R-TS(Q) reject write
b. if TS(Ti) < W-TS(Q) reject Write
Validation based protocol (optimistic)
For many read transactions, concurrency control scheme
not needed, bcz it causes overhead.