2130703-DBMS-Unit-6 (1)
2130703-DBMS-Unit-6 (1)
Transaction
Management
Prof. Firoz Sherasiya
9879879861
[email protected]
Database Management System (2130703) Darshan Institute of Engineering & Technology
Topics to be covered
• Transaction concepts
• Properties of transactions
• Serializability of transactions
• Testing for serializability
• System recovery
• Two-phase commit protocol
• Recovery and atomicity
• Log-based recovery
• Concurrent executions of transactions and related problems
• Locking mechanism
• Solution to concurrency related problems
• Deadlock
• Two-phase locking protocol
• Isolation
• Intent locking
Unit – 6: Transaction Management 2 Darshan Institute of Engineering & Technology
What is transaction?
A transaction is a sequence of operations performed as a single
logical unit of work.
A transaction is a logical unit of work that contains one or more
SQL statements.
Works as a single
Example of transaction logical unit
read (A)
A = A – 50
Transaction write (A)
Operations
read (B)
B = B + 50
write (B)
Read (A)
Temp = A * 0.1
A = A - temp
Write (A)
Read (B)
B = B + temp
Write (B)
Commit
Read (A)
A = A - 50
Write (A)
Read (B)
B = B + 50
Write (B)
Commit
Read (A)
Temp = A * 0.1
A = A - temp
Write (A)
Read (B)
B = B + temp
Write (B)
Commit
3. li = write(Q), lj = read(Q) T1 T2 T1 T2
li and lj conflict write(Q) read (Q)
read (Q) write(Q)
4. li = write(Q), lj = write(Q) T1 T2 T1 T2
li and lj conflict write(Q) write(Q)
write(Q) write(Q)
Read (A)
Read (B) Temp = A * 0.1
B = B + 50 A = A - temp
Write (B) Write (A)
Commit Read (B) Read (B)
B = B + temp B = B + temp
Write (B) Write (B)
Commit Commit
S1 S2
T1 T2 T3 T1 T2 T3
Write (A) Read (A)
Read (A) Write (A)
Write (A) Write (A)
Reque
st to pr
ep are
Prepare
Phase Prepared
Comm
it/Abo
r t
Commit
Phase D on e
Coordinator
Coordinator
Participant
Send toinform
send
“ack” send to do
reply
inform
commit
request asking
whether ready for
commit readyor
todone
to commit
commit
not or not
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.
Unit – 6: Transaction Management 48 Darshan Institute of Engineering & Technology
Page table structure
• The database is partitioned into 1 2 1
fixed-length blocks referred to as 2 1 2
PAGES. 3 4 3
• Page table has n entries – one for 4 101 4
each database page. 5 202 :
• Each entry contain pointer to a . :
page on disk. n n 101
:
Page Table :
201
Pages 202
n
Pages on disk
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
0
1
Database
T1
Transaction
T begin T end Time
Unit – 6: Transaction Management 65 Darshan Institute of Engineering & Technology
Strict two phase locking protocol
In this protocol, a transaction may release all the shared locks
after the Lock Point has been reached, but it cannot release any
of the exclusive locks until the transaction commits or aborts.
It ensures that if data is being modified by one transaction, then
other transaction cannot read it until first transaction commits.
This protocol solves dirty read problem.
Wait-Die
O needs a resource held by Y O waits
Y needs a resource held by O Y dies