Professional Documents
Culture Documents
For example , if you are sending $100 from your account to your
friend's account, then the money deducted from your account should
be reflected to your friend's account.
States Of Transaction
A transaction goes through any different states throughout its
lifecycle. These states also known as transaction state are as
follows:
1. Active State: This is the first state of the transaction and any
transaction which is being executed is in this state. The changes
made are stored in the buffer in the main memory.
2. Partially Committed: After the last operation is executed the
transaction enters into the partially committed state. This is
said partially committed because the changes made are still in
the buffer in the main memory.
3. Failed State: A transaction enters into the failed state if some
checks fail in the active state, some error occurs in the active or
partially committed state and the transaction cannot be
executed further.
4. Aborted State: If any transaction has reached the failed state
then the recovery manager rollback the database to its original
state from where the execution had started.
5. Committed State: A transaction from the partially committed
state enters into the committed state if all the operations are
executed successfully. It is not possible to rollback from this
state and it is a new consistent state.
ACID Properties
For maintaining the integrity of data in the database the certain
properties are followed by all the transactions that take place in the
database. These properties are popularly known as ACID properties
where A is for Atomicity, C for Consistency, I for Isolation
and D for Durability.
Atomicity
This property states that the transaction should either occur
completely or doesn't occur at all. The transaction should not occur
partially. Each transaction is treated as a unit and the execution is
completed else the transaction is aborted. If any transaction is
aborted all the changes made are reversed back. If the transaction
occurs completely then only it is committed.
Now, let's consider a situation where the first operation has occurred
successfully i.e. Rs 200 was debited from Account A and the balance
in Account A is now Rs 800. But, the second transaction failed .
So, the Rs 200 was not added to Account B. This can lead to
inconsistency in the database. So, either the transaction should fail or
both the operations should occur if the transaction has to be
successful. The atomicity thus helps in ensuring the correctness of the
database.
Consistency
This property ensures that the integrity of the database is maintained
before and after the transaction. It ensures that when any transaction
is executed then the database should move from one consistent state
to another consistent state.
Isolation
This property tells that each transaction is executed in the system
such that it is the only transaction in the system. If more than one
transaction is taking place in parallel, then the occurrence of one
transaction will not affect the other transaction. If any transaction is
using a data item then it can’t be used by other transactions until the
first transaction ends.
Transaction 1: T1
BEGIN
Read(X)
X=X+50
Write(X)
Read(Y)
Y=Y-10
Write(Y)
END
Transaction 2: T2
BEGIN
Read(X)
Read(Y)
Z=X*Y
Write(Z)
END
Let X = 40, Y = 20.
Durability
This property ensures that once the changes are made in the database
these changes persist in the database even if any system failure
occurs. These changes are saved permanently in the non-volatile
memory. It is the responsibility of the recovery manager to ensure the
durability in the database.