Transaction Management: Example
Transaction Management: Example
Transaction Management: Example
Transaction Management
Transactions are a set of operations used to perform a logical set of work. It is the
bundle of all the instructions of a logical operation. A transaction usually means
that the data in the database has changed. One of the major uses of DBMS is to
protect the user’s data from system failures. It is done by ensuring that all the
data is restored to a consistent state when the computer is restarted after a
crash. The transaction is any one execution of the user program in a DBMS. One
of the important properties of the transaction is that it contains a finite number of
steps. Executing the same program multiple times will generate multiple
transactions.
Example: Consider the following example of transaction operations to be
performed to withdraw cash from an ATM vestibule.
Stages of Transaction
The transaction has four properties. These are used to maintain consistency in a
database, before and after the transaction.
Property of Transaction:
Atomicity
Consistency
Isolation
Durability
Atomicity
States that all operations of the transaction take place at once if not, the
transactions are aborted.
There is no midway, i.e., the transaction cannot occur partially. Each
transaction is treated as one unit and either run to completion or is not
executed at all.
Atomicity involves the following two operations:
Abort: If a transaction aborts, then all the changes made are not visible.
Commit: If a transaction commits then all the changes made are visible.
Consistency
The integrity constraints are maintained so that the database is consistent
before and after the transaction.
The execution of a transaction will leave a database in either its prior stable
state or anew stable state.
The consistent property of database states that every transaction sees a
consistent database instance.
The transaction is used to transform the database from one consistent state to
another consistent state.
Isolation
It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
In isolation, if the transaction T1 is being executed and using the data item X,
then that data item can’t be accessed by any other transaction T2 until the
transaction T1ends.
The concurrency control subsystem of the DBMS enforced the isolation
property
Durability
The durability property is used to indicate the performance of the database’s
consistent state. It states that the transaction made the permanent changes.
Transaction States
Transactions can be implemented using SQL queries and Servers. In the diagram,
you can see how transaction states work.
Transaction States
CREATED BY: PROF.VISHAL SHARMA Page 4
DBMS – II Unit- 2
rows,consequently it
avoids non-repeatable read.
Serializable: This is the Highest isolation level. A serializable execution is
guaranteed to be serializable. Serializable execution is defined to be an
execution of operations in which concurrently executing transactions appears
to be serially executing.
Failure Classification
To find that where the problem has occurred, we generalize a failure into the
following categories:
Transaction failure
System crash
Disk failure
1. Transaction failure
The transaction failure occurs when it fails to execute or when it reaches a point
from where it can’t go any further. If a few transactions or process is hurt, then
this is called as transaction failure.
Reasons for a transaction failure could be –
1. Logical errors: If a transaction cannot complete due to some code error or an
internal error condition, then the logical error occurs.
2. Syntax error: It occurs where the DBMS itself terminates an active transaction
because the database system is not able to execute it. For example, The system
aborts an active transaction, in case of deadlock or resource unavailability.
2. System Crash
System failure can occur due to power failure or other hardware or software
failure. Example: Operating system error.
Fail-stop assumption: In the system crash, non-volatile storage is assumed not
to be corrupted.
3. Disk Failure
It occurs where hard-disk drives or storage drives used to fail frequently. It was
a common problem in the early days of technology evolution.
Disk failure occurs due to the formation of bad sectors, disk head crash, and
unreachability to the disk or any other failure, which destroy all or part of disk
storage.
Serializability