DBMS - Transactions Management
DBMS - Transactions Management
DBMS - Transactions Management
Chapter Outline
1 Introduction to Transaction Processing
2 Transaction States
3 Properties of Transactions
4 Recovery Management
4 Characterizing Schedules based on Recoverability
5 Characterizing Schedules based on Serializability
6. Concurrency Control ( Locking )
Introduction to Transaction Processing
Single-User System:
At most one user at a time can use the system.
Multiuser System:
Many users can access the system concurrently.
Concurrency
Interleaved processing:
Concurrent execution of processes is interleaved in
a single CPU
Parallel processing:
Processes are concurrently executed in multiple
CPUs.
What is a Transaction ?
A Transaction:
Logical unit of database processing that includes
one or more access operations (read -retrieval,
write - insert or update, delete).
Transaction boundaries:
Begin and End transaction.
Open_Account(B)
Old_Balance = B.balance
New_Balance = Old_Balance + 500
B.balance = New_Balance
Close_Account(B)
Basic Operations of a Transaction
Active state
Committed state
Failed state
Terminated State
State transition diagram illustrating
the states for transaction execution
Active: In this state the transaction is being executed. This is the initial
state of every transaction.
Partially Committed: When a transaction executes its final operation, it is
said to be in this state. After execution of all operations, the database
system performs some checks e.g. the consistency state of database after
applying output of transaction onto the database.
Failed: If any checks made by database recovery system fails, the
transaction is said to be in failed state, from where it can no longer proceed
further.
Aborted: If any of checks fails and transaction reached in Failed state, the
recovery manager rolls back all its write operation on the database to make
database in the state where it was prior to start of execution of transaction.
Transactions in this state are called aborted. Database recovery module
can select one of the two operations after a transaction aborts:
Re-start the transaction
Kill the transaction
5. Disk failure:
Some disk blocks may lose their data because of a read
or write malfunction or because of a disk read/write head
crash. This may happen during a read or a write
operation of the transaction.
Roll Back :
Needed for transactions that have a [start_transaction,T]
entry into the log but no commit entry [commit,T] into the
log.
Transaction Schedule ( or history )
Transaction schedule:
When transactions are executing concurrently in an
interleaved fashion, the order of execution of
operations from the various transactions forms what
is known as a transaction schedule (or history).
read_item(x); read_item(x);
x:=x-n; x:=x+m;
write_item(x); write_item(x);
read_item(y);
Y:=y+n; read_item(x);
write_item(y); x:=x-n;
read_item(x); write_item(x);
x:=x+m; read_item(y);
write_item(x); Y:=y+n;
write_item(y);
Non Serial Schedules example
Schedule C Schedule D
T1 T2 T1 T2
read_item(x); read_item(x);
x:=x-n; x:=x-n;
read_item(x); write_item(x);
x:=x+m;
write_item(x); read_item(x);
read_item(y); x:=x+m;
write_item(x); write_item(x);
Y:=y+n; read_item(y);
write_item(y); Y:=y+n;
write_item(y);
Result equivalent Schedules example
S1 S2
read_item(x); read_item(x);
x:=x+10; x:=x*1.1;
write-item(x); write_item(x);
Testing for conflict serializability: Algorithm
Looks at only read_Item (X) and write_Item (X)
operations
Constructs a precedence graph (serialization
graph) - a graph with directed edges
An edge is created from Ti to Tj if one of the
operations in Ti appears before a conflicting
operation in Tj
The schedule is serializable if and only if the
precedence graph has no cycles.
For each Ti in S, create a node labeled Ti in
precedence graph.
Create an edge from Ti->Tj when Tj executes
read-item(x) after Ti executes write_item(x).
Create an edge from Ti->Tj when Tj executes
write-item(x) after Ti executes read_item(x).
Create an edge from Ti->Tj when Tj executes
write-item(x) after Ti executes write _item(x).
S is serializable if the graph has no cycles.
Slide 17- 28
Constructing the precedence graphs for schedules A
and D and to test for conflict serializability.
(a) Precedence graph for serial schedule A.
(b) Precedence graph for serial schedule B.
(c) Precedence graph for schedule C (not serializable).
(d) Precedence graph for schedule D (serializable, equivalent to
schedule A).
Another Example of Serializability testing.
(a) The read and Write operations of three transactions T1, T2, and T3.
(b) Schedule E.
(c) Schedule F.
Two schedules are said to be view equivalent if
the following three conditions hold:
1. The same set of transactions participates in S
and S’, and S and S’ include the same
operations of those transactions.
2. For any operation Ri(X) of Ti in S, if the value of
X read by the operation has been written by an
operation Wj(X) of Tj (or if it is the original value
of X before the schedule started), the same
condition must hold for the value of X read by
operation Ri(X) of Ti in S’.
3. If the operation Wk(Y) of Tk is the last operation
to write item Y in S, then Wk(Y) of Tk must also
be the last operation to write item Y in S’.
Concurrency Control Techniques ( Locking )
( Purpose of Concurrency Control )
Read Write
Read Write
Y N
N N
Conflict matrix
Database requires that all transactions should be well-
formed. A transaction is well-formed if:
• It must lock the data item before it reads or writes to it.
• It must not lock an already locked data items and it must
not try to unlock a free data item.