4.1 Basic Concept of Transaction
4.1.1 Transaction
- A transaction is a series of operations performed as a single logical unit of work on the Database Management System. Transaction leads to modification in the database contents.
- A transaction is initiated by a user program written in the high level data manipulation languages like SQL or programming language like java. The transaction consists of all the operations executed between begin transaction and end transaction.
Transactions in a database environment have two main purposes :
(I) To provide reliable units of work that allow correct recovery from failures and keep a database consistent even in cases of system failure, when execution stops (completely or partially) and many operations upon a database remain uncompleted, with unclear status.
For example, in a baking system, transferring money from one account to another leads to change in balance values of both accounts. To keep the database in consistent state both changes must succeed or fail together.
(2) To provide isolation between programs accessing a database concurrently. If lf:,i isolation is not provided, the programs outcomes are possibly incorrect.
Process of Transaction
The execution of transaction leads to perform series of read and write operations on database objects, which are explained below:
(A) Read Operation Syllabus Topic : Properties of Transaction
To perform transaction on a data which 1s present in main memory Read ( ) operation is used.
Read (X);
This statement states that value of X is read from main memory (i.e. from local buffer).
If it is not present in the main memory then:
(1) It is first brought into i:nain memory from disk, using Input ( ) operation.
Like Input (X);
(B) Write Operation
To write a database object. an in-memory copy of the object is first modified and then written to disk.
Write(X);
This statement states that value of_,K is written to local buffer which is in main OJ.C'mory. And then this updated value is copied appropriate disk block, so that the changes are"done permanently as shown in Fig. 4.1.2.
4.2 Properties of Transaction:
In computer science, ACID (Atomicity, i Consistency, Isolation, Durability) is a set of properties of database transactions. In the context of databases, a f
(2) Then its value is copied into variable as shown in Fig. 4.1.l.
LOCll:I buffer a program sequence of database operations that satisfies the I ACID properties and thus, can be perceived as single I logical operation on the data is called a transaction.
(A) Atomicity
o Atomicity is based on the concept that each transaction be "all or nothing" : if any one part of. the transaction in a sequence fails, then the entire transaction fails, and there will be no change in database state.
o An atomic system must guarantee atomicity
in every situation, including power failures,errors and crashes. For the outside world, a committed transaction appears completely by its effects on the database. That means it should be indivisible ("atomic"), and ana aborted transactiOn does not happen. i
o This property states that. either all operations contained by a transaction are done i successfully or none of them complete at all.
To maintain the consistency of data this property is very useful.
(B) Consistency
o The consistency property ensures that the transaction executed on the database system
will bring the database from one valid state to another..
o The data which is written by the transaction must be valid according to the all standard rules and regulations regarding constraints, cascai::les, triggers etc. Consistency does not guarantee accuracy of the transaction as per the expectations of programmer.
(C) Isolation
0 When transactiom are performed in a sequence, the state of a system is always valid without any problem. But sometimes we may have to perform multiple transactions concurrently.
0 In case of concurrent transactions, the isolation property ensures that the system state should be same that would be obtained if transactions were executed sequentially i.e., one after the other. The effect of any incomplete transaction should be invisible to
other transaction by means of isolation. '
(D) Durability
0 The durability property assures that after transaction committed successfully the updates made should remain permanent in the database even in the event of power loss, crashes or errors.
o For example in a database management system, · when a series of transaction is executed, the modification done should be stored permanently even if the databs.se crashes just after the transaction. To avoid problem because of power loss, the states of database after every transaction must be recorded in a non-volatile memory.
A complete example of transaction
Consider a banking system having number of accounts stored in the database.
- To access the database followj6g operations are used in transaction:
Read(X), which transfer data X from database to I h)cal buffer & Write(X), which transfer the data X ' frnn local buffer to database.
- Atomicity : If any failure occurs in the system during transaction proceeded up to Write (M); and further operations does not executed due to failure occurrence, it will leads the banking database system in inconsistent state if atomicity property is not provided.
- But if the atomicity property is provided then if all operations are not executed, then the operations which are executed before failure get cancelled.
_ Consistency : If consistency is provided, then in above example the sum of balance in account M
and N will be same before transaction Ti perform and after Ti completes. That is, in initial situation M + N gives $1500. If transaction committed successfully then M h:olds $350 and N holds
$1150. Addition of amount will give $1500. If transaction cioes not committed successfully then M holds $500 and N holds $WOO. Addition of amount' will give $I500.
- Isolation : This property takes care of no other transactions should interfere with transaction Ti during its execution.
Durability : It ensures that the data modification done by transaction- Ti will persist in database even if any failure occurs during ystem after (;Ommitting the transaction.
4.3 Transaction States
During execution, transaction will be in one of the following state.
Active
- This is the first state of transaction. In this state the transaction is being executed. This state is entry point to every transaction. Transactions
which are in active state
execution has been started.
Partially Committed:
- When a transaction completes all operations, it will enter into partially committed state. Even the last operation has been performed; data is still not saved to the database.
Failed
If execution of transaction cannot proceed due to failure of the System or failure in database, then the transaction is said to be in failed state.
Abort
In case of the failed transaction, the. modification done !n database during transaction processing must be rolled back .to ensure the atomicity and consistency of database.
- The transaction enters into 'Abort' this state after roll back operation is performed. It is the end of transaction when any fault occurs.
Committed
If without any error transaction completed successfully it will come into committed state
· which will allow to made changes pennan nt into database. This is the last step of a transac n, if it executes without fail.
- Every transaction goes through at least three states among of five. Either transaction may g9es through active -partially commiped - committed
or through active - Failed - ,aborted, or through active - partially committed !failed - abort.
4.4 Transaction Management
To ensure database integrity it is important to control transactions. Transactions can be controlled using TCL commands which we have studied in previous Chapter 2.
Operations performed on transactions
Commit and roll back operations are performed on transaction to manage transaction
· Commit operation allow transaction to update database permanently. It will ensure the updates done by transaction will persist even if failure occurs. Commit opera.ion leads the transaction
into committed state.
Rollback operation helps to maintain the atomicity property of transaction. If any failure occurs during transaction processing which leads the transaction to failed state. In this situation roll back operation cancels the changes made by that transaction in database to maintain consistency. And then the transaction will be aborted.
In general three utilities are used to manage transactions.
(1) Transaction manager
o Ensures that database proceed from one consistent state to another consistent state.
o Ensures that the transaction should not violet integrity constraints.
(2) Scheduler
o. Provides a specific strategy for the execution of transaction and corresponding concurrency control.
o Avoid or resolves conflicts during concurrent data access.
(3) Recover manager
Restore the state of database it was in before the failure of transaction.
Comments
Post a Comment