ADBMSUnit3pptx 2023 10 06 09 10 59
ADBMSUnit3pptx 2023 10 06 09 10 59
COMPUTER
ENGINEERING
Unit 3
Advance
Transaction and Database
Management
Concurrency System
(09CE1502)
Transactions are a set of operations that are used to
perform some logical set of work.
Operation
Initial balance in both the banks before the start of the
s in transaction
Transactio Account1 - ₹ 5000 Account2 - ₹ 2000
n
This data before the start of the transaction is stored in
the secondary memory (Hard disk) which once initiated
is bought to the primary memory (RAM) of the system
for faster and better access.
Now for a transfer of ₹ 500 from Account1 to Account2
to occur, the following set of operations will take place.
Operation Read (Account1) --> 5000
s in Account1 = Account1 - 500
Transactio Write (Account1) --> 4500
Active
If all the read and write operations are performed
state without any error then it progresses to the partially
committed state, if somehow any operation fails, then
it goes to a state known as failed state.
Partially After all the read and write operations are completed,
the changes which were previously made in the main
Committe memory are now made permanent in the database,
after which the state will progress to committed state
d State but in case of a failure it will go to the failed state.
If the transaction completes all sets of operations
successfully, all the changes made during the
Committe partially committed state are permanently stored and
d state the transaction is stated to be completed, thus the
transaction can progress to finally get terminated in
the terminated state.
If any operation during the transaction fails due to
some software or hardware issues, then it goes to the
Failed failed state . The occurrence of a failure during a
state transaction makes a permanent change to data in the
database. The changes made into the local memory
data are rolled back to the previous consistent state.
If the transaction fails during its execution, it goes
from failed state to aborted state and because in the
previous states all the changes were only made in the
Aborted main memory, these uncommitted changes are either
deleted or rolled back.
state
The transaction at this point can restart and start
afresh from the active state.
If the transaction gets aborted after roll-back or the
Terminate transaction comes from the committed state, then the
database comes to a consistent state and is ready for
d state further new transactions since the previous
transaction is now terminated.
Transactio
n states
It is important to ensure that the database remains
consistent before and after the transaction.
To ensure the consistency of database, certain properties
are followed by all the transactions occurring in the system.
Atomicity
If the transaction fails after completion of T1 but
before completion of T2.( say, after write(X) but
before write(Y)), then amount has been deducted
from X but not added to Y.
This results in an inconsistent database state.
Therefore, the transaction must be executed in
entirety in order to ensure correctness of database
state.
This property ensures that integrity constraints are
maintained.
In other words, it ensures that the database remains
Consistenc consistent before and after the transaction.
y It is the responsibility of DBMS and application
programmer to ensure consistency of the database.
Consistenc Referring to the example above,
y The total amount before and after the transaction
must be maintained.
Total before T occurs = 500 + 200 = 700.
Total after T occurs = 400 + 300 = 700.
Therefore, database is consistent. Inconsistency
occurs in case T1 completes but T2 fails. As a result T
is incomplete.
This property ensures that multiple transactions can
occur simultaneously without causing any
inconsistency.
During execution, each transaction feels as if it is
getting executed alone in the system.
A transaction does not realize that there are other
transactions as well getting executed parallelly.
transaction
Concurren
cy Unrepeatable
problems read
in DBMS
Lost update
The dirty read problem in DBMS occurs when a
transaction reads the data that has been updated by
another transaction that is still uncommitted. It arises
due to multiple uncommitted transactions executing
simultaneously.
This read is called as dirty read because-
Dirty read There is always a chance that the uncommitted
problem transaction might roll back later.
Thus, uncommitted transaction might make other
transactions read a value that does not even
exist.
This leads to inconsistency of the database.
Consider two transactions A and B performing
read/write operations on a data DT in the database
DB. The current value of DT is 1000: The following
table shows the read/write operations in A and B
transactions.
Dirty read
problem
Transaction A reads the value of data DT as 1000 and
modifies it to 1500 which gets stored in the
temporary buffer.
Unrepeata
ble read
problem
Transaction A and B initially read the value of DT as
1000.
Unrepeata Transaction A modifies the value of DT from 1000 to
ble read 1500 and then again transaction B reads the value
and finds it to be 1500.
problem Transaction B finds two different values of DT in its
two different read operations.
Lost The Lost Update problem arises when an update in
update the data is done over another update but by two
different transactions.
problem
Example: Consider two transactions A and B
performing read/write operations on a data DT in the
database DB. The current value of DT is 1000: The
following table shows the read/write operations in A
and B transactions.
Lost
update
problem
Transaction A initially reads the value of DT as 1000.
locking T4 …… ……
protocol T5
T6
UNLOCK (A)
LOCK-X (C)
T7 UNLOCK (B)
T8 UNLOCK (A)
T9 UNLOCK (C)
T10 …… ……
This is just a skeleton transaction which shows how
unlocking and locking works with 2-PL. Note for:
Transaction T1:
Growing Phase is from steps 1-3.