HP OpenVMS Systems Documentation |
OpenVMS Programming Concepts Manual
30.6 Communication Resource Manager InterfaceA Communication Resource Manager (CRM) is a special resource manager that acts as a gateway between DECdtm and another TM. Typically, the other TM would be on a system other than an OpenVMS system. You can also write a CRM to link two DECdtm systems using an otherwise unsupported communication mechanism such TCP/IP. A CRM in a subordinate branch of a DECdtm transaction is indistinguishable from a normal RM. It responds to DECdtm events normally, except that internally it forwards the events to the remote TM instead of dealing with them directly. A CRM may create a DECdtm subordinate branch using the $JOIN_RM service as follows:
The new TID is derived from the remote TM and must be a universal
unique identifier (UUID). If the remote TM does not use UUIDs for its
TIDs, the CRM must generate a new TID (using the $CREATE_UID service)
and maintain a mapping between remote TM TIDs and DECdtm TIDs. If
multiple branches of the same transaction are created, you must use the
same DECdtm TID on all branches. Otherwise, RMs may detect spurious
lock collisions between branches of the same transaction.
The DECdtm XA interface allows a transaction manager (TM) to coordinate transactions performed by a resource manager (RM). For an overview and documentation of the XA interface, see the X/Open CAE Specification document Distributed Transaction Processing: The XA Specification. The DECdtm XA interface provides the following levels of support for the XA interface:
Figure 30-2 XA Veneer Example Figure 30-3 XA Gateway Example Figure 30-4 TX Wrapper Example For the convenience of application writers, the DECdtm XA Interface also provides an implementation of the X/Open TX (Transaction Demarcation) interface. This is a simple set of function wrappers for DECdtm system services. (See Figure 30-4.) The following sections describe the DECdtm XA interface:
30.7.1 Using the XA Veneer
This section describes how to write an application program that uses an
XA-compliant RM in transactions coordinated by DECdtm.
Application programs can use the $START_TRANS, $END_TRANS, and $ABORT_TRANS system services to control transactions. XA RMs can participate only in the default transaction, because the XA interface model does not allow for explicit transaction IDs passed to RMs by APs. DECdtm does not support DECthreads or POSIX threads. That is, you can use threading within an application, but the default transaction is managed per process, not per thread. The XA Veneer does not support the use of $SET_DEFAULT_TRANS to change the current default transaction. That is, an application program may attempt to change the current default transaction, but XA RMs will continue to perform operations in the context of the original default transaction. The Veneer reports RM xa_start() errors on $START_TRANS by an SS$_ABORT exception. Any RM error also causes the transaction to be aborted and a reason code to be returned from $END_TRANS. RM return codes are translated to reason codes as follows:
The XA Veneer implements the functions ax_open_decdtm() and ax_close_decdtm(). They are identical to the X/Open TX functions tx_open() and tx_close. If ax_open_decdtm() is not called, XA RMs are automatically opened at the start of the first transaction.
Application programs can use the X/Open TX functions instead of DECdtm
system services. The TX functions are available in an object module
that can be used with the XA Veneer. The tx_begin() function includes
an exception handler that maps XA Veneer exceptions to tx_begin()
return codes. While the TX wrapper module requires the XA Veneer, the
TX functions apply equally to XA and DECdtm RMs.
A transaction may access an RM from more than one process. The XA
Veneer creates a separate branch of the transaction for each process.
This requests the RM to treat each process as a loosely coupled thread
as defined by the XA specification. The RM takes locks to isolate
access to a resource in one process from access in another process.
Consequently, the processes may deadlock against each other if they
attempt to access the same resource within a single transaction.
Before a resource manager can take part in transaction processing, it must be bound to the XA interface. The XA interface requires the following:
DECdtm supports the following methods of binding:
You can find definitions of the data structures and constants required to use the XA interface in SYS$LIBRARY:XA.H. This is the "xa.h" as listed in the XA specification. Additional nonstandard functions and flags are defined in SYS$LIBRARY:DDTM_XA.H. To use an XA compliant RM, you must link the application with the following:
You can also link an application against SYS$LIBRARY:DDTM$TX.OBJ to use the TX transaction demarcation interface instead of DECdtm system service calls.
You must install the privileged shareable image
SYS$LIBRARY:DDTM$XA_SS.EXE. It provides system services for internal
use by the XA interface.
You bind resource managers by creating and linking a small object module. The object module places references to the XA Switch and xa_info string in the predefined PSECT DDTM$AX_RM. Consider the following Compaq C sample:
To bind the resource manager, make the following changes to the sample file:
If you prefer to code the RM definition in another language, such as VAX MACRO, note the full attributes of the PSECT as follows:
To make the xa_info strings configurable, the XA Veneer attempts to translate the strings in the SYS$DECDTM_XA_RM logical name table. If the strings cannot be translated, they are passed unchanged to the resource manager. When you use static binding, the XA Veneer calls xa_recover() either when tx_open() is called or at the start of the first transaction in the image lifetime.
You can use ax_close_decdtm() to close statically bound resource
managers.
An application program can bind additional RMs to the XA Veneer by calling ax_bind_decdtm_2(). Dynamic binding requests the XA Veneer to call xa_recover(), which allows recovery to be initiated earlier than with static binding.
Note that ax_open_decdtm() and ax_close_decdtm() have no effect on
dynamically bound resource managers.
You must specify the resource manager instance name if the resource manager implements multiple instances (or databases) that may be recovered independently. You cannot bind a resource manager into a single process multiple times, unless each binding is for a different named instance. You must also specify a resource manager instance name if the resource manager instance name in the XA Switch structure is longer than 24 characters. Otherwise, if the resource manager does not support multiple instances, the instance name may be set null, and DECdtm uses the resource manager name in the XA Switch structure as the instance name. The definition of resource manager instances controls the following features of the XA Veneer:
When you choose the instance name, you must set it identically in all processes. It has a maximum size of 24 characters (excluding the null terminator). Compaq recommends that the first part of the name is the same as the resource manager name in the XA Switch structure, provided that this is possible within the overall limit of 24 characters. You can bind a maximum of 1024 resource manager instances in a process.
In this manual, the term "resource manager instance" is used in the
same sense as "Oracle Instance" in the Oracle documentation. In the
OpenVMS System Services Reference Manual, the DECdtm services descriptions use the same term in a
different context and with a different meaning.
You may find the following hints to be of help:
30.7.1.4 Implementation CharacteristicsThis section provides information for developers of XA-compliant RMs that are to be used with the DECdtm XA Veneer. The DECdtm XA Veneer does not use some features of the XA interface that must normally be provided by resource managers. This information is provided for the convenience of RM developers, to help them decide if an existing implementation is likely to work with DECdtm. Future implementations of DECdtm XA may make use of these features.
This section also describes possible deviations from the XA standard or
common interpretations of the standard.
DECdtm does not support DECthreads or POSIX p-threads. That is, the default transaction is managed per process, not per thread. When reading the XA specification, you must regard a thread as equivalent to a process. The Veneer assumes there is a single default transaction per process and does not attempt to suspend or migrate the association of a transaction branch with a thread or process. Thus, it never sets the TMSUSPEND or TMMIGRATE flags on a call to xa_end(), and never sets TMRESUME on a call to xa_start().
The Veneer never sets the TMJOIN flag on a call to xa_start().
DECdtm does not support heuristic decisions. If the RM reports a
heuristic decision on xa_commit() or xa_rollback(), the Veneer records
the decision in a log file. The xa_forget() function is called
immediately and the transaction is treated as if it committed or
aborted normally.
The XA Veneer always calls XA functions at non-AST level in user mode. The Veneer never interrupts an XA call with another XA call. The Veneer may interrupt application processing to call the following functions:
However, such calls are not made while the process has an active transaction, that is, between xa_start() and xa_end(). Therefore, they cannot interrupt the RM while it is executing a call from the application. TP frameworks, implemented using the earliest version of the DECdtm interface, may run application code in concurrent DECdtm unsynchronized branches. This is not recommended (see the OpenVMS DECdtm Services Reference Manual), partly because the Veneer cannot determine when branch processing ends, and may therefore make xa_end() and xa_rollback() calls asynchronously while an XA RM is processing a call from the application. This occurs only when a transaction is aborted by another DECdtm branch. This problem does not occur with ACMS, because ACMS executes branches serially, not concurrently.
If the version of the TP framework in use does not make a clear
statement that synchronized branches are used, and transactions have
multiple branches, Compaq recommends that applications protect XA RM
calls against asynchronous events using the nonstandard functions
ax_lock_decdtm() and ax_unlock_decdtm(). The Veneer may be locked at
the start of branch processing and unlocked at the end, or individual
RM calls may be protected by paired lock/unlock calls.
This implementation does not use asynchronous operations.
The RM Switch flag TMUSEASYNC is ignored. The TMASYNC flag is never set
on calls to the resource manager. The xa_complete() function is never
called.
An RM can ensure that a future version of the Veneer preserves
restrictions and possible nonstandard behavior by setting the
nonstandard flag TM_DDTM_V1 in the flags field of the XA Switch data
structure.
No XA functions are called directly when an image or process terminates. The RM is dissociated from any active transaction, and the transaction is aborted.
After an image terminates, a process terminates, or a cluster node
fails, DECdtm calls xa_recover() on any one of the surviving processes
in the cluster that is bound to the same resource manager instance.
In this implementation, formatID is set to 223585243, gtrid_length is
16 and bqual_length is 36. However, RMs should not make assumptions
about the values of these fields.
In most cases, the return values XAER_INVAL and XAER_PROTO are treated as failures of the XA Veneer. An SS$_BUGCHECK exception is reported. See xa_close() and xa_open() in Section 30.7.1.4.9 for exceptions.
In most cases, XAER_RMERR and XAER_RMFAIL have a common interpretation
by the Veneer. The current transaction is aborted, but the RM continues
to participate in new transactions. The error return values differ only
in that they cause different DECdtm reason codes to be returned to the
application. See xa_commit() below for an exception.
|