Study Materials of Module 4 DBMS
Study Materials of Module 4 DBMS
Study Materials of Module 4 DBMS
Let us now consider each of the ACID properties. (For ease of presentation, we consider them in an order
different from the order A-C-I-D.)
Consistency: The consistency requirement here is that the sum of A and B be unchanged by the execution
of the transaction. Without the consistency requirement, money could be created or destroyed by the
transaction! It can be verified easily that, if the database is consistent before an execution of the transaction,
the database remains consistent after the execution of the transaction. Ensuring consistency for an
individual transaction is the responsibility of the application programmer who codes the transaction.
Atomicity: Suppose that, just before the execution of transaction Ti, the values of accounts A and B are
$1000 and $2000, respectively. Now suppose that, during the execution of transaction Ti, a failure occurs
that prevents Ti from completing its execution successfully. Further, suppose that the failure happened
after the write(A) operation but before the write(B) operation. In this case, the values of accounts A and
B reflected in the database are $950 and $2000. The system destroyed $50 as a result of this failure. In
particular, we note that the sum A + B is no longer preserved. Thus, because of the failure, the state of the
system no longer reflects a real state of the world that the database is supposed to capture. We term such
a state an inconsistent state. We must ensure that such inconsistencies are not visible in a database system.
Note, however, that the system must at some point be in an inconsistent state. Even if transaction Ti is
executed to completion, there exists a point at which the value of account A is $950 and the value of
account B is $2000, which is clearly an inconsistent state. This state, however, is eventually replaced by
the consistent state where the value of account A is $950, and the value of account B is $2050. Thus, if
the transaction never started or was guaranteed to complete, such an inconsistent state would not be visible
except during the execution of the transaction. That is the reason for the atomicity requirement: If the
atomicity property is present, all actions of the transaction are reflected in the database, or none are. The
basic idea behind ensuring atomicity is this: The database system keeps track (on disk) of the old values
of any data on which a transaction performs a write. This information is written to a file called the log. If
the transaction does not complete its execution, the database system restores the old values from the log
to make it appear as though the transaction never executed.
Durability: Once the execution of the transaction completes successfully, and the user who initiated the
transaction has been notified that the transfer of funds has taken place, it must be the case that no system
failure can result in a loss of data corresponding to this transfer of funds. The durability property guarantees
that, once a transaction completes successfully, all the updates that it carried out on the database persist,
even if there is a system failure after the transaction completes execution. We assume for now that a failure
of the computer system may result in loss of data in main memory, but data written to disk are never lost.
Protection against loss of data on disk is discussed in Chapter 16. We can guarantee durability by ensuring
that either: 1. The updates carried out by the transaction have been written to disk before the transaction
completes. 2. Information about the updates carried out by the transaction and writ ten to disk is sufficient
to enable the database to reconstruct the updates when the database system is restarted after the failure.
Isolation: Even if the consistency and atomicity properties are ensured for each transaction, if several
transactions are executed concurrently, their operations may interleave in some undesirable way, resulting
in an inconsistent state. For example, as we saw earlier, the database is temporarily inconsistent while the
transaction to transfer funds from A to B is executing, with the deducted total written to A and the increased
total yet to be written to B. If a second concurrently running transaction reads A and B at this intermediate
point and computes A+B, it will observe an inconsistent value. Furthermore, if this second transaction
then performs updates on A and B based on the inconsistent values that it read, the database may be left
in an inconsistent state even after both transactions have completed. A way to avoid the problem of
concurrently executing transactions is to execute transactions serially— that is, one after the other.
Transaction Atomicity and Durability:
As we noted earlier, a transaction may not always complete its execution successfully. Such a transaction
is termed aborted. If we are to ensure the atomicity property, an aborted transaction must have no effect
on the state of the database. Thus, any changes that the aborted transaction made to the database must be
undone. Once the changes caused by an aborted transaction have been undone, we say that the transaction
has been rolled back. It is part of the responsibility of the recovery scheme to manage transaction aborts.
This is done typically by maintaining a log. Each database modification made by a transaction is first
recorded in the log. We record the identifier of the transaction performing the modification, the identifier
of the data item being modified, and both the old value (prior to modification) and the new value (after
modification) of the data item. Only then is the database itself modified. Maintaining a log provides the
possibility of redoing a modification to ensure atomicity and durability as well as the possibility of
undoing a modification to ensure atomicity in case of a failure during transaction execution.
A transaction that completes its execution successfully is said to be committed. A committed transaction
that has performed updates transforms the database into a new consistent state, which must persist even
if there is a system failure.
Once a transaction has committed, we cannot undo its effects by aborting it. The only way to undo the
effects of a committed transaction is to execute a compensating transaction. For instance, if a transaction
added $20 to an account, the compensating transaction would subtract $20 from the account. However,
it is not always possible to create such a compensating transaction. Therefore, the responsibility of writing
and executing a compensating transaction is left to the user, and is not handled by the database system.
We need to be more precise about what we mean by successful completion of a transaction. We therefore
establish a simple abstract transaction model. A transaction must be in one of the following states:
• Active, the initial state; the transaction stays in this state while it is executing.
• Partially committed, after the final statement has been executed.
• Failed, after the discovery that normal execution can no longer proceed.
• Aborted, after the transaction has been rolled back and the database has been restored to its state prior
to the start of the transaction.
• Committed, after successful completion.