Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DB Transaction-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

UNIT – 4

INTRODUCTION TO TRANSACTION PROCESSING CONCEPTS & THEORY


Introduction to Transaction Processing
A transaction in database is a logical unit of work that must succeed or fail in its entirely. That means, a
transaction may involve number of sub-steps, which should either all be carried out successfully or all be
ignored if any failure occurs.
Hence, a transaction in DBMS is an atomic process that is either performed into completion entirely or is
not performed at all.
• Generally, the operations performed in a transaction include one or more of database operations
like insert, delete, update or retrieve data.
• A transaction involving only data retrieval without any data update is called read-only transaction.
Each high-level operation can be divided into a number of low-level tasks or operations. For example, a
data update operation can be divided into three tasks −
• read_item () − reads data item from storage to main memory.

• modify_item () − change value of item in the main memory.

• write_item () − write the modified value from main memory to storage.

Operations of Transaction
A user can make different types of requests to access and modify the contents of a database. So, we have
different types of operations relating to a transaction. They are discussed as follows.
i) Read(X)
A read operation is used to read the value of X from the database and store it in a buffer in the main
memory for further actions such as displaying that value. Such an operation is performed when a user
wishes just to see any content of the database and not make any changes to it. For example, when a user
wants to check his/her account’s balance, a read operation would be performed on user’s account balance
from the database.
ii) Write(X)
A write operation is used to write the value to the database from the buffer in the main memory. For a write
operation to be performed, first a read operation is performed to bring its value in buffer, and then some
changes are made to it according to the user’s request, then to store the modified value back in the
database, a write operation is performed. For example, when a user requests to withdraw some money
from his account, his account balance is fetched from the database using a read operation, then the
amount to be deducted from the account is subtracted from this value, and then the obtained value is
stored back in the database using a write operation.
iii) Commit
This operation in transactions is used to maintain integrity in the database. To ensure that further
operations of any other transaction are performed only after work of the current transaction is done, a
commit operation is performed to the changes made by a transaction permanently to the database.
iv) Rollback
This operation is performed to bring the database to the last saved state when any transaction is
interrupted in between due to any power, hardware, or software failure. In simple words, it can be said that
a rollback operation does undo the operations of transactions that were performed before its interruption
to achieve a safe state of the database and avoid any kind of ambiguity or inconsistency.

Transaction and System Concepts


1. Transaction States / States of a database transaction
Although a transaction is an atomic unit of work, it passes through various states during its lifetime.
The state of a transaction is defined by the current activity it is performing. Let’s consider the following
diagram.

Active:
It is the first stage of any transaction when it has begun to execute. Operations such as insertion,
deletion, or updation are performed during this state. During this state, the data records are under
manipulation and they are not saved to the database, rather they remain somewhere in a buffer in the
main memory.
Partially Committed:
This state of transaction is achieved when it has completed most of the operations and is executing its
final operation (result yet to come). It can be a signal to the commit operation. If some kind of error
occurs during this state, the transaction goes into a failed state, else it goes into the Committed state.
Committed:
This state of transaction is achieved when all the transaction-related operations have been executed
successfully along with the Commit operation, i.e. data is saved into the database after the required
manipulations in this state. This marks the successful completion of a transaction.
Failed:
If any of the transaction-related operations cause an error during the active or partially committed state,
further execution of the transaction is stopped and it is brought into a failed state. Here, the database
recovery system makes sure that the database is in a consistent state. A failed transaction can no longer
proceed further.
Aborted:
If the error is not resolved in the failed state, then the transaction is aborted and a rollback operation is
performed to bring database to the last saved consistent state. When the transaction is aborted, the
database recovery module either restarts the transaction or kills it.
2. The System Log
To be able to recover from failures that affect transactions, the system maintains a log to keep track
of all transaction operations that affect the values of database items, as well as other transaction
information that may be needed to permit recovery from failures. The log is a sequential, append-only
file that is kept on disk, so it is not affected by any type of failure except for disk or catastrophic failure.
3. Commit Point of a Transaction
A transaction reaches its commit point when all its operations that access the database have been
executed successfully and the effect of all the transaction operations on the database have been
recorded in the log. Beyond the commit point, the transaction is said to be committed, and its effect
must be permanently recorded in the database. The transaction then writes a commit record into the
log.

Properties of Transactions
In order to maintain consistency in a database, before and after the transaction, certain properties are
followed. These are called ACID properties.

Atomicity:
This property ensures that either the entire transaction takes place at once or doesn’t happen at all.
There is no midway i.e. transactions do not occur partially. It involves the following two operations.
Abort: If a transaction aborts, changes made to the database are not visible.
Commit: If a transaction commits, changes made are visible.
Consistency:
This means that integrity constraints must be maintained so that the database is consistent before and
after the transaction. It refers to the correctness of a database.
Isolation:
This property ensures that multiple transactions can occur concurrently without leading to the
inconsistency of the database state. Transactions occur independently without interference. Changes
occurring in a particular transaction will not be visible to any other transaction until that particular
change in that transaction is written to memory or has been committed.
Durability:
This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored in and written to disk and they persist even if a system failure
occurs. These updates now become permanent and are stored in non-volatile memory.

You might also like