DBMS GTU Study Material Presentations Unit-7 31102020032310AM
DBMS GTU Study Material Presentations Unit-7 31102020032310AM
GTU # 3130703
Unit-7
Transaction
Processing
Works as a single
logical unit
read (A)
A = A – 50
Transaction write (A) Operations
read (B)
B = B + 50
write (B)
TheThis
Discover isthat
state the normal
initial
after state.
executionhas
the transaction canbeen
no longer
rolledproceed.
back and the
Thea transaction
Once
database has been stays
transaction cannotinbe
restoredthis state while
tocompleted,
its state it to
any
prior ischanges
executing.
that
the start of it
made
the must be undone rolling it back.
transaction.
Ti Tj Ti Tj
1. li = read(Q), lj = read(Q) read (Q) read (Q)
li and lj don’t conflict read (Q) read (Q)
2. li = read(Q), lj = write(Q) Ti Tj Ti Tj
read (Q) write(Q)
li and lj conflict
write(Q) read (Q)
3. li = write(Q), lj = read(Q) Ti Tj Ti Tj
write(Q) read (Q)
li and lj conflict
read (Q) write(Q)
4. li = write(Q), lj = write(Q) Ti Tj Ti Tj
li and lj conflict write(Q) write(Q)
write(Q) write(Q)
T1 T2
Read (A)
Write (A)
Read (A)
We are unable to swap instructions in the above schedule to obtain either the serial schedule
<T1, T2>, or the serial schedule <T2, T1>.
Above two schedules S1 and S3 are not view equivalent because initial read operation in S1 is
done by T1 and in S3 it is done by T2.
Above two schedules S1 and S2 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 S1 and S3 are not view equal because, in S1, T3 is reading A that is
updated by T2 and in S3, T3 is reading A which is updated by T1.
Above two schedules S1 and S2 are view equal because, in S1, T3 is reading A that is updated
by T2 and in S2 also, T3 is reading A which is updated by T2.
Above two schedules S1 and S3 are not view equal because final write operation in S1 is done
by T3 and in S3 final write operation is also done by T1.
Above two schedules S1 and S2 are view equal because final write operation in S1 is done by
T3 and in S2 also the final write operation is also done by T3.
S2 is the serial schedule of S1. If we can prove that they are view equivalent then we can says
that given schedule S1 is view serializable.
In schedule S1, transaction T1 first reads the data item X. In S2 also transaction T1 first reads
the data item X.
In schedule S1, transaction T1 first reads the data item Y. In S2 also the first read operation on Y
is performed by T1.
The initial read condition is satisfied for both the schedules.
Prof. Firoz A Sherasiya #3130703 (DBMS) ⬥ Unit 7 – Transaction Processing 34
View serializable example (Updated Read)
Non-Serial Schedule (S1) Serial Schedule (S2)
T1 T2 T1 T2
Read (A) Read (A)
Write (A) Write (A)
Read (A) Read (B)
Write (A) Write (B)
Read (B) Read (A)
Write (B) Write (A)
Read (B) Read (B)
Write (B) Write (B)
In schedule S1, transaction T2 reads the value of X, written by T1. In S2, the same transaction
T2 reads the X after it is written by T1.
In schedule S1, transaction T2 reads the value of Y, written by T1. In S2, the same transaction
T2 reads the value of Y after it is updated by T1.
The updated read condition is also satisfied for both the schedules.
Prof. Firoz A Sherasiya #3130703 (DBMS) ⬥ Unit 7 – Transaction Processing 35
View serializable example (Final Write)
Non-Serial Schedule (S1) Serial Schedule (S2)
T1 T2 T1 T2
Read (A) Read (A)
Write (A) Write (A)
Read (A) Read (B)
Write (A) Write (B)
Read (B) Read (A)
Write (B) Write (A)
Read (B) Read (B)
Write (B) Write (B)
In schedule S1, the final write operation on X is done by transaction T2. In S2 also transaction
T2 performs the final write on X.
In schedule S1, the final write operation on Y is done by transaction T2. In schedule S2, final
write on Y is done by T2.
The final write condition is also satisfied for both the schedules.
Prof. Firoz A Sherasiya #3130703 (DBMS) ⬥ Unit 7 – Transaction Processing 36
View serializable example
Non-Serial Schedule (S1) Serial Schedule (S2)
T1 T2 T1 T2
Read (A) Read (A)
Write (A) Write (A)
Read (A) Read (B)
Write (A) Write (B)
Read (B) Read (A)
Write (B) Write (A)
Read (B) Read (B)
Write (B) Write (B)
Since all the three conditions that checks whether the two schedules are view equivalent are
satisfied in this example, which means S1 and S2 are view equivalent.
Also, as we know that the schedule S2 is the serial schedule of S1, thus we can say that the
schedule S1 is view serializable schedule.
Reques
t to pre
pare
Prepare
Phase Prepared
Comm
it/Abor
t
Commit
Phase Done
Coordinator
Coordinator
Participant
Send inform
send
send
“ack” to to do
request
reply
inform
commit
asking for
whether ready
ready
commit toto
commit
done or
commit
or
notnot
T1
T2
T3
T4
At failure time:
Ignore the transaction T1 as it has already been committed before checkpoint.
Redo transaction T2 and T3 as they are active after checkpoint and are committed before failure.
Undo transaction T4 as it is active after checkpoint and has not committed.
T1
T2
T3
T4
T5
T6
Exercise Give the name of transactions which has already been committed before checkpoint.
Exercise Give the name of transactions which will perform Redo operation.
Exercise Give the name of transactions which will perform Undo operation.
Two pages - page 2 & 5 - are affected by a transaction and copied to new physical pages. The
current page table points to these pages.
The shadow page table continues to point to old pages which are not changed by the
transaction. So, this table and pages are used for undoing the transaction.
Lock variable
01
Database
A transaction may be granted a lock on an item if the requested lock is compatible with locks
already held on the item by other transactions.
If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks
held by other transactions have been released. The lock is then granted.
Any number of transactions can hold shared locks on an item, but if any transaction holds an
exclusive on the item no other transaction can hold any lock on the item.
Prof. Firoz A Sherasiya #3130703 (DBMS) ⬥ Unit 7 – Transaction Processing 63
Lock based protocol
This locking protocol divides transaction execution phase into three parts:
1. When transaction starts executing, create a list of data items on which they need locks and requests the
system for all the locks it needs.
2. Where the transaction acquires all locks and no other lock is required. Transaction keeps executing its
operation.
3. As soon as the transaction releases its first lock, the third phase starts. In this phase a transaction cannot
demand for any lock but only releases the acquired locks.
Transaction
Lock acquisition execution Lock releasing
phase phase
Transaction
Transaction Transaction Time
begin end
Transaction
Transaction Transaction Time
begin end
A deadlock is a situation in which two or more transactions are waiting for one another to give
up locks.
K C
LO
AD
Suppose now that transaction D is requesting an item held by C.
DE
Then the edge D → C is added to the wait-for graph. C
Now this graph contains the cycle.
B→D→C→B
It means that transactions B, D and C are all deadlocked.
K C
Choosing which transaction to abort is known as victim selection.
LO
AD
In this wait-for graph transactions B, D and C are deadlocked.
DE
C
In order to remove deadlock one of the transaction out of these
three (B, D, C) transactions must be roll backed.
We should rollback those transactions that will incur the minimum
cost.
When a deadlock is detected, the choice of which transaction to
abort can be made using following criteria:
The transaction which have the fewest locks
The transaction that has done the least work
The transaction that is farthest from completion
Prof. Firoz A Sherasiya #3130703 (DBMS) ⬥ Unit 7 – Transaction Processing 73
Deadlock prevention
A protocols ensure that the system will never enter into a deadlock state.
Some prevention strategies :
Require that each transaction locks all its data items before it begins execution (pre-declaration).
Impose partial ordering of all data items and require that a transaction can lock data items only in the order
specified by the partial.
Wait-die Wound-wait
O needs a resource held by Y O waits Y dies
Y needs a resource held by O Y dies Y waits
Thank
You