Transactions
Transactions
SYSTEMS (Transaction
Management)
INSTRUCTOR : FARHAN SARWAR
Topics to Cover
What is Transaction?
Transaction States
Properties of Transactions
Types of failures
Transaction
Using this simplified database model, the basic database access operations that
a transaction can include are as follows:
read_item(X,Access). Reads a database item named X into a program
variable.
PARTIALLY COMMITTED, which occurs after the final statement has been
executed.
At this point, it may be found that the transaction has violated an integrity
constraint and the transaction has to be aborted.
Alternatively, the system may fail and any data updated by the transaction may
not have been safely recorded on secondary storage.
In such cases, the transaction would go into the FAILED state and would have
to be aborted.
FAILED, which occurs if the transaction cannot be committed or the
transaction is aborted while in the ACTIVE state, perhaps due to the user
aborting the transaction.
Properties of Transactions (ACID)
Transactions have the following four standard properties, usually referred to by the
acronym ACID.
Atomicity(Either all or None) − ensures that all operations within the work unit are
completed successfully. Otherwise, the transaction is aborted at the point of failure
and all the previous operations are rolled back to their former state.
Consistency − ensures that the database properly changes states upon a successfully
committed transaction. For example, Before transaction start and after the
transaction completed sum of the money should be same.
Isolation − enables transactions to operate independently of and transparent to each
other. In which multiple transaction runs parallel.
Durability − In which all the changes are permanent and ensures that the result or
effect of a committed transaction persists in case of a system failure.
Concurrency Control
The system begins executing the first transaction until it reaches an I/O
operation.
While the I/O is being performed, the CPU suspends the first transaction and
executes commands from the second transaction.
When the second transaction reaches an I/O operation, control then returns to
the first transaction and its operations are resumed from the point at which it
was suspended.
Why Concurrency Control Is
Needed?
The first transaction continues until it again reaches another I/O operation.
In this way, the operations of the two transactions are interleaved to achieve
concurrent execution. In addition, throughput ( the amount of work that is
accomplished in a given time interval ) is improved as the CPU is executing
other transaction instead of being in an idle state waiting for I/O operations to
complete.
Why Concurrency Control Is
Needed?
With concurrency control, the database would detect the conflict and resolve it
using techniques like locking, time-stamping, or versioning.
The correct sequence would be:
1. Transaction 1 reads the initial balance ($1000)
2. Transaction 1 subtracts $500, leaving a balance of $500
3. Transaction 2 reads the updated balance ($500)
4. Transaction 2 adds $300, leaving a balance of $800
Concurrency control ensures that transactions occur in a predictable and
reliable order, maintaining data integrity and consistency.
Problems due to Concurrency
A lost update occurs when two different transactions are trying to update the
same column on the same row within a database at the same time.
Typically, one transaction updates a particular column in a particular row,
while another that began very shortly afterward did not see this update before
updating the same value itself.
The result of the first transaction is then “lost”, as it is simply overwritten by
the second transaction.
The Lost Update Problem
Example 1
The Lost Update Problem
Example 2
The Uncommitted Dependency
(dirty read) Problem
Serializability
Recoverability
Algorithms to remove
concurrency problems