DBMS - Unit 4 (Database Transaction Management)
DBMS - Unit 4 (Database Transaction Management)
Database Transaction
Management
Introduction- Transaction
Collections of operations that form a single logical
unit of work are called transactions.
OR
A transaction is a unit of program execution that
accesses and possibly updates various data items.
At the end of transaction database must be in
consistence state.
A transaction is delimited by statements (or function
calls) of the form begin transaction and end
transaction.
The transaction consists of all operations executed
between the begin transaction and end transaction.
Introduction- Transaction
Two main issues to deal with:
Failures of various kinds, such as hardware failures and
system crashes
Concurrent execution of multiple transactions
Conflict serializability
View serializability
Conflict Serializability
Consider a schedule S in which there are two consecutive
instructions Li and Lj of transactions Ti and Tj
respectively
Schedule 5
Conflict Serializability (Contd…)
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.
Example of a schedule-7
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’.
View Serializability
Lock-Based Protocols
Timestamp-Based Protocols
Lock-Based Protocols
One way to ensure serializability is to require that
data items be accessed in a mutually exclusive
manner.
A lock is a mechanism to control concurrent access
to a data item.
Data items can be locked in two modes :
Deadlock Prevention
Deadlock Detection
Deadlock Recovery
Deadlock Prevention
Deadlock prevention protocols ensure that the system
will never enter into a deadlock state.
Select a victim
Rollback –
a. Total Rollback
b. Partial Rollback
Starvation
Recovery System
Recovery system can restore the database to the
consistent state that existed before the failure.
Failure Classification
Transaction Failure – Logical Error , System Error
System Crash
Disk Failure
Recovery Methods
To recover from transaction failure following
recovery schemes are used -
Shadow paging
Log-Based Recovery
Log is the most widely used structure for recording
database modifications.
The log is a sequence of log records, recording all the
update activities in the database.
Types of Log -
Start Log Record - < Ti, start >
Update Log Record - < Ti, Xj, V1, V2 >
Commit Log Record - < Ti, commit >
Abort Log Record - < Ti, abort >
Log-Based Recovery
Whenever a transaction performs a write, a log record for
that write is created.
Example - Log
T0: Read(A) <T0,start>
A = A – 50
Write(A) <T0,A,1000,950>
Read(B)
B = B+50
Write(B) <T0,B,2000,2050>
In above case redo(T0) wiil be done as both start and commit of T0 appear
in log, and as no commit log record of T1 appears in the log system will
ignore the log.
Deferred Database Modification
Failure occur – <T1,commit>
Example - Log
T0: Read(A) <T0,start>
A = A – 50
Write(A) <T0,A,1000,950>
Read(B)
B = B+50
Write(B) <T0,B,2000,2050>
<T0,commit>
In above case redo(T0) and redo(T1) wiil be done as both start and commit
of T0 and T1 appears in log.
Immediate Database Modification
The immediate modification technique allows
database modifications to be output to the database
while the transaction is still in the active state.
Example - Log
T0: Read(A) <T0,start>
A = A – 50
Write(A) <T0,A,1000,950>
Read(B)
B = B+50
Write(B) <T0,B,2000,2050>
In above case redo(T0) wiil be done as both start and commit of T0 appear
in log, and as no commit log record of T1 appears in the log system will
undo(T1).
Immediate Database Modification
Failure occur – <T1,commit>
Example - Log
T0: Read(A) <T0,start>
A = A – 50
Write(A) <T0,A,1000,950>
Read(B)
B = B+50
Write(B) <T0,B,2000,2050>
<T0,commit>
In above case redo(T0) and redo(T1) wiil be done as both start and commit
of T0 and T1 appears in log.
Checkpoints
Log based recovery required to search entire log to
determine which transaction need to be undone or
redone.
Difficulties -
The search process is time consuming.
Most of the transaction need to be redone, have already
written their updates into the database.