home *** CD-ROM | disk | FTP | other *** search
- .H1 "Programming Distributed Transactions"
- .Ih "distributed transactions"
- .Ih "transactions, distributed"
- .Ih "two-phase commit service"
- .Ih "commit service"
- The two-phase commit service
- allows an application to coordinate
- updates among two or more \*Ss.
- This initial implementation of distributed transactions
- treats separate transactions (which may be on separate
- \*Ss) as if they were a single transaction.
- The commit service uses one \*S, the ``commit server,''
- .Ih "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 the databases on the participating
- servers are updated or that none of them are.
- .LP
- A distributed transaction is performed by submitting
- \*N
- statements to the \*Ss via \*L routines.
- An application
- program opens a session with each server, issues the
- update commands, and then prepares to commit the transaction.
- Through \*L, the application issues to each participating server:
- .By
- a BEGIN TRANSACTION
- with identifying information on the application, the
- transaction, and the commit server.
- .By
- the \*N update statements.
- .By
- a PREPARE TRANSACTION statement that
- indicates that the updates have been performed and that the
- server is prepared to commit.
- .Bz
- .LP
- 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
- (\f2i.e.,\f1 that the commit will take place),
- and a COMMIT TRANSACTION is then issued to all of the servers, causing them to commit.
- .LP
- 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.
- .H2 "The Commit Service and the Application Program"
- The role of the commit service is to be a single place of record that
- helps the application decide whether
- the transaction should be committed or aborted.
- .LP
- If the \*Ss are all prepared to commit,
- the application notifies the commit service to mark
- the transaction as committed.
- Once this happens,
- the transaction is committed despite any failures that
- might subsequently happen.
- .LP
- If any \*S or the application program
- fails before the PREPARE TRANSACTION statement,
- the \*S will ROLLBACK the transaction.
- If any \*S or the application program fails after
- the PREPARE but before the COMMIT,
- the \*S will communicate with the server functioning as the commit service and ask it
- whether to ROLLBACK or COMMIT.
- .LP
- The role of the application program is to deliver the \*N statements
- to the \*Ss in the proper order, using the proper \*L routines.
- The role of the commit service is to provide a single place where the
- commit/rollback status is maintained.
- The \*Ss communicate with the commit service only
- if a failure happens during the two-phase commit.
- .LP
- The commit service needs its own DBPROCESS, separate from the
- DBPROCESSes used for the distributed transaction, to perform its record-keeping.
- Note, however, that the server handling the commit service can also be
- one of the servers participating in the transaction, as long as the
- commit service has its own DBPROCESS.
- In fact, all the servers involved in the transaction can be one and the same.
- .H2 "The Probe Process"
- .Ih "probe process, in two-phase commit"
- If any server must recover the transaction,
- it initiates a process, \f2probe\f1, that determines the last known
- status of the transaction.
- After it returns the status of that transaction to the commit service,
- the \f2probe\f1 process dies.
- The \f2probe\f1 process makes use of \f2stat_xact()\f1,
- the same status-checking routine
- that the commit service uses to check
- on the progress of a distributed transaction.
- .H1 "The Two-Phase Commit Routines"
- The routines that make up the two-phase commit service are:
- .By
- \f2open_commit()\f1 - opens a connection with the commit service.
- The routine is given the login ID of the user initiating the
- session and the name of the commit service.
- It returns a pointer to a DBPROCESS structure used in subsequent
- commit service calls.
- .By
- \f2start_xact()\f1 - records the start of a distributed transaction,
- and stores initial information about the transaction (DBPROCESS id,
- application name, transaction
- name, and number of sites participating) in a lookup table on the commit
- server.
- It returns the \f2commid\f1 identifying number for the transaction.
- .By
- \f2build_xact_string()\f1 - builds a name string for use by each
- participating \*S for its BEGIN TRANSACTION and PREPARE
- TRANSACTION statements.
- This string
- encodes the application's transaction name, the commit service name,
- and the \f2commid\f1.
- .By
- \f2commit_xact()\f1 - tells the commit service to commit the transaction.
- .By
- \f2abort_xact()\f1 - tells the commit service to abort the transaction.
- .By
- \f2remove_xact()\f1 - decrements the count of servers
- still participating in the transaction.
- .By
- \f2close_commit()\f1 - closes the connection with the commit service.
- .Bz
- .LP
- Two additional routines are used for ongoing status reports:
- .By
- \f2scan_xact()\f1 - returns the status of a single or all distributed transactions.
- .By
- \f2stat_xact()\f1 - returns the completion status of a distributed transaction.
- .Bz
- .LP
- During the course of a session,
- the diagnostic routines \f2scan_xact()\f1 and
- \f2stat_xact()\f1 are
- used to check that the commit service carried out the
- request.
- .LP
- The \f2scan_xact()\f1 routine uses the
- commit service lookup table, \f2spt_committab\f1,
- .Ih "commit service lookup table"
- which holds the values of:
-
- .nf
- - the transaction id
- - the time the transaction started
- - the last time the row was updated
- - the number of servers initially involved in the transaction
- - the number of servers that still have not completed
- - the status ('a'-abort, 'c'-commit, 'b'-begin)
- - the application name
- - the transaction name
- .sp
- .LP
- The two-phase commit routines
- call internal stored procedures (\f2e.g.\f1, \f2sp_start_xact\f1)
- that are created in each server's master database.
- The \f2installmaster\f1 script creates the commit service
- lookup table and stored procedures in each server's master database,
- for use whenever that server becomes a commit server.
- .H2 "Specifying the Commit Server"
- .mc |
- The commit server must have an entry in the \f2interfaces\f1 file
- .Ih "interfaces file for commit server"
- .Ih "commit server, interfaces file for"
- on each machine participating in the distributed transaction.
- On the machine on which the commit server is actually running, the commit server
- entry must specify the usual ports described in the \f2Installation Guide\f1,
- including a query port.
- For example:
- .SD
- .ne 6
- .ta +8n +8n
- .in +3n
- SERVICE
- console tcp sun-ether rose 2002
- master tcp sun-ether rose 2001
- debug tcp sun-ether rose 2003
- query tcp sun-ether rose 2001
- .in -3n
- .ED
- On any additional machines containing other servers participating in the distributed
- transaction, the commit server entry need specify only the query port:
- .SD
- .ne 8
- .ta +8n +8n
- .in +3n
- SERVICE
- query tcp sun-ether rose 2001
-
- SITEA
- console tcp sun-ether gaia 2012
- debug tcp sun-ether gaia 2013
- master tcp sun-ether gaia 2011
- query tcp sun-ether gaia 2011
- .in -3n
- .ED
- The name of the commit server (in these examples, ``SERVICE'') is used as a parameter in calls to
- the \f2open_commit()\f1 and \f2build_xact_string()\f1 routines.
- The commit server name must be the same on all machines participating in
- the transaction.
- The name cannot contain a period (``.'') or a colon (``:'').
- .H2 "Two-Phase Commit Example Program"
- The \f2\*L Reference Supplement\f1 contains an example program illustrating
- the two-phase commit service.
- .mc
-