A transaction in a database is a sequence of DB operations that is performed as
a single logical unit of work. Typically this means that the logical sequence of
operations must happen together or not at all. But there is more to this than
just that. What is the meaning of this logical unit of work ? For a long time
I thought transaction means making a bunch of actions an atomic operation, but
it is not. This logical unit of work must exhibit four properties called the
atomicity, consistency, isolation, and durability (ACID) properties. Only when
a sequence of operations satisfy the "ACID test" ( or should I say litmus test,
pardon the pun) they can be collectively a "transaction".
Atomicity
A transaction must be an atomic unit of work; This means
if the operations A,B,C,D are performed in a transaction then all of A,B,C and
D are done, or none of them are performed. So, while performing operation
B, if there is a failure, due to a wrong query, for example, then whole
transaction is aborted and none of the result of actions A,B,C and D are
persisted. But what about the operation A which was already performed ? This
operation A is "rolled-back". However, If all of them are completed without any
errors, then the transaction is committed and the its effects are persisted.
Consistency
This brings us to the next item, which is consistency.
When completed, a transaction must leave all data in a consistent state. This
means that whatever modifications are performed in the operations A,B,C and D;
the data integrity of the relational database must be maintained. All the rules
that govern this consistency in the database must be passed. Moreover, All
internal data structures, such as B-tree indexes or doubly-linked lists, must be
correct at the end of the transaction.
Isolation
In today's world filled with massive software which are driven by high data
processing needs, concurrent access to databases and data is not uncommon.
In-fact it is foolish in today's world to not allow concurrent access to data.
Thus it not weird to have concurrent transactions running on the same database.
It is also common sense to understand that one transaction, if it has to have
the "Atomicity" and "Consistency" property, must be impervious to the
modifications made by another concurrent transaction. A piece of data, which
a transaction must work on, either for reading or modification, must either be
in the state it was in before another concurrent transaction modified it, or
after the second transaction has completed, but it never will be in an
intermediate state. This is referred to as serializability. What is
Serializability ? Consider a situation in which there are 3 transactions tA, tB
and tC that can run. Assuming that there may be dependencies among them, if the
3 transaction run concurrently and they produce the same outcome, as if they
were run in serial in the same order they completed when they were run
concurrently, then it means that they satisfy the serializability property.
Durability
After a transaction has completed, its effects are permanently stored in the
system. The modifications persist even in the event of a system failure. For
instance, if a transaction is already completed, then even if there is a system
crash, the transaction will remain in the state in which it was completed and
its state can be recovered from the database.
a single logical unit of work. Typically this means that the logical sequence of
operations must happen together or not at all. But there is more to this than
just that. What is the meaning of this logical unit of work ? For a long time
I thought transaction means making a bunch of actions an atomic operation, but
it is not. This logical unit of work must exhibit four properties called the
atomicity, consistency, isolation, and durability (ACID) properties. Only when
a sequence of operations satisfy the "ACID test" ( or should I say litmus test,
pardon the pun) they can be collectively a "transaction".
Atomicity
A transaction must be an atomic unit of work; This means
if the operations A,B,C,D are performed in a transaction then all of A,B,C and
D are done, or none of them are performed. So, while performing operation
B, if there is a failure, due to a wrong query, for example, then whole
transaction is aborted and none of the result of actions A,B,C and D are
persisted. But what about the operation A which was already performed ? This
operation A is "rolled-back". However, If all of them are completed without any
errors, then the transaction is committed and the its effects are persisted.
Consistency
This brings us to the next item, which is consistency.
When completed, a transaction must leave all data in a consistent state. This
means that whatever modifications are performed in the operations A,B,C and D;
the data integrity of the relational database must be maintained. All the rules
that govern this consistency in the database must be passed. Moreover, All
internal data structures, such as B-tree indexes or doubly-linked lists, must be
correct at the end of the transaction.
Isolation
In today's world filled with massive software which are driven by high data
processing needs, concurrent access to databases and data is not uncommon.
In-fact it is foolish in today's world to not allow concurrent access to data.
Thus it not weird to have concurrent transactions running on the same database.
It is also common sense to understand that one transaction, if it has to have
the "Atomicity" and "Consistency" property, must be impervious to the
modifications made by another concurrent transaction. A piece of data, which
a transaction must work on, either for reading or modification, must either be
in the state it was in before another concurrent transaction modified it, or
after the second transaction has completed, but it never will be in an
intermediate state. This is referred to as serializability. What is
Serializability ? Consider a situation in which there are 3 transactions tA, tB
and tC that can run. Assuming that there may be dependencies among them, if the
3 transaction run concurrently and they produce the same outcome, as if they
were run in serial in the same order they completed when they were run
concurrently, then it means that they satisfy the serializability property.
Durability
After a transaction has completed, its effects are permanently stored in the
system. The modifications persist even in the event of a system failure. For
instance, if a transaction is already completed, then even if there is a system
crash, the transaction will remain in the state in which it was completed and
its state can be recovered from the database.
No comments:
Post a Comment