Transactions

A transaction is the most important concept you should be aware of when dealing with enterprise applications. To a user, a transaction is a single change event that either happens or doesn't happen. To system implementers, a transaction is a programming style that enables them to code modules that can participate in distributed computations.

To illustrate this concept, assume you want to transfer money from a savings account into a checking account. In this scenario, it is critical that both accounts are changed by a successful transaction and neither account is affected by an unsuccessful one. You cannot afford to have your money vaporize if crediting your checking account fails for any reason after the debit on your savings account succeeds. Although this may sound like a fairly straightforward request, making this work in a distributed system without deploying some form of transaction control is hard – computers can fail and messages can easily get lost.

Important 

Transactions are essential for distributed applications. Further, transactions provide modular execution, which complements a component technology's modular programming.

Transactions provide a way to bundle a set of operations into an atomic execution unit. This atomic, all-or-nothing property is not new: it appears throughout life. For example, a minister conducting a marriage ceremony first asks the bride and groom, "Do you take this person to be your spouse?" Only if they both respond "I do" does the minister pronounce them married and commit the transaction. In short, within any transaction, several independent entities must agree before the deal is done. If any party disagrees, the deal is off and the independent entities are reverted back to their original state. In transactions, this is known as a rollback operation.

Two-phase Commits

The two-phase commit protocol ensures all the resource managers either commit a transaction or abort it. In the first phase, the transaction service asks each resource manager if it is prepared to commit. If all the participants affirm, then, in the second phase, the transaction service broadcasts a commit message to all of them. If any part of the transaction fails, in other words, if a resource manager fails to respond to the prepare request or if a resource manager responds negatively, then the transaction service notifies all the resource managers and the transaction is aborted. This is the essence of the two-phase commit protocol.

The ACID Properties

All transactions subscribe to the following "ACID" properties:

Atomicity

A transaction either commits or rollbacks. If a transaction commits, all its effects remain. If it rollbacks, then all its effects are undone. In other words, each part of a transaction must complete successfully for the transaction to commit. For example, in renaming an object, both the new name is created and the old name is deleted (commit), or nothing changes (rollback).

Consistency

A transaction always leads to a correct transformation of the system state by preserving the state invariance. For example, within a transaction adding an element to a doubly linked list, all four forward and backward pointers are updated, thus maintaining a consistent state.

Isolation

Concurrent transactions are isolated from the updates of other incomplete transactions. This property is also often called serializability. For example, a second transaction traversing a doubly linked list already undergoing modification by a first transaction will see only completed changes and is isolated from any non-committed changes of the first transaction. Note that a transaction should not be dependent on another to prevent deadlocks, in other words, two processes that are sharing some resource (such as read access to a table) both decide to wait for exclusive (write) access.

Durability

If a transaction commits, its effects will be permanent after the transaction commits. In fact, the effects remain even in the face of system failures.

The application must decide what consistency is and bracket its computation to delimit these consistent transformations. The job of the transactional resource managers is to provide consistent, isolated, and durable transformations of the objects they manage. If the transactions are distributed among multiple computers, the two-phase commit protocol is used to make these transactions atomic and durable.



Professional JMS
Professional JMS
ISBN: 1861004931
EAN: 2147483647
Year: 2000
Pages: 154

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net