Progress
Database Administration
Guide and Reference


Distributed Transactions

Two-phase commit ensures that distributed transactions occur consistently across all databases. A distributed transaction is a single transaction that updates two or more databases. The following 4GL procedure is an example of a distributed transaction:

disttran.p 
DO TRANSACTION: 
   FIND FIRST sports1.customer. 
   sports1.customer.credit-limit = sports1.customer.credit-limit - 10. 
   FIND sports2.customer WHERE sports2.customer.cust-num = 
       sports1.customer.cust-num. 
   sports2.customer.credit-limit = sports2.customer.credit-limit + 10. 
END. 

The following scenario illustrates how inconsistencies can occur during a distributed transaction. A bank has two accounts, one on database sports1 and another on database sports2. The bank runs an application that starts a transaction to withdraw a sum of money from sports1 and deposit it into sports2. To keep the accounts in balance, it is critical that both operations—the withdrawal and the deposit—succeed, or that they both fail. For example, if sports1 commits its part of the transaction and sports2 does not, there is an inconsistency in the data, as shown in Figure 12–1.

Figure 12–1: Data Inconsistency

Two-phase commit protects against this type of inconsistency by making sure that all databases commit the transaction, or that none commit. To ensure database integrity across all involved databases, the database engine commits database updates in two distinct phases. During the first phase, the database engine checks each database involved in a transaction to verify that it is ready to commit the transaction. During the second phase, the database engine directs the databases to commit the transaction and then verifies that they committed it properly.

If there is an inconsistency, the database engine displays error messages and allows you to complete or roll back the inconsistent transaction to return the data to a consistent state.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095