Programming distributed transactions

The two-phase commit service allows an application to coordinate updates among two or more Adaptive Servers. This initial implementation of distributed transactions treats separate transactions (which may be on separate Adaptive Servers) as if they were a single transaction. The commit service uses one Adaptive Server, the “commit server,” as a central record-keeper that helps the application determine whether to commit, or whether to roll back transactions in case of failure. Thus, the two-phase commit guarantees that either all or none of the databases on the participating servers are updated.

A distributed transaction is performed by submitting Transact-SQL statements to the Adaptive Servers through DB-Library routines. An application program opens a session with each server, issues the update commands, and then prepares to commit the transaction. Through DB-Library, the application issues the following to each participating server:

After the updates have been performed on all the servers participating in the distributed transaction, the two-phase commit begins. In the first phase, all servers agree that they are ready to commit. In the second phase, the application informs the commit service that the transaction is complete (that is, the commit will take place), and a commit transaction is then issued to all of the servers, causing them to commit.

If an error occurs between phase one and phase two, all servers coordinate with the commit service to determine whether the transaction should be committed or aborted.

NoteIf certain types of errors occur during a two-phase transaction, Adaptive Server may need to mark a two-phase process as “infected.” Marking the process as infected rather than killing it aids in later error recovery. To ensure that Adaptive Server is able to mark processes as infected, boot Adaptive Server with the flag -T3620 passed on the command line.