What is Atomicity in DBMS?

This property make sure that for a particular transaction either all the instruction will get executed or none.

Example:

Let Ti be a transaction that transfers $50 from account A to account B. This transaction

can be defined as:

read(A);

A := A − 50;

write(A);

read(B);

B := B + 50;

write(B).

Lets assume 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 happened after the write(A) operation but before the write(B) operation, that prevents Ti from completing its execution successfully.

Examples of such failures include power failures, hardware failures, and software errors.

In this case, the values of accounts A and B reflected in the database are $950 (A := A − 50; write(A);) and $2000 (because of failure before write B). 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 all instructions, 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, and, if the transaction does not complete its execution, the database system

restores the old values to make it appear as though the transaction never

executed.

Ensuring Atomicity is the responsibility of the database system itself; specifically, it is handled by a component called the transaction-management component.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.