The Stanford Rapide Project

RAPIDE

X/Open Architecture Rapide Code

Architectures

Local Instance Architecture

[Local Instance Architecture]

A particular instance of the X/Open architecture, which X/Open calls a local instance architecture, consists of one application program (AP), one transaction manager (TM), and one or more resource managers (RMs) connected together as shown in the above figure. The boxes indicate the generic component interfaces, and the lines indicate the communication between them.

This architecture is coded in Rapide as:

Component Interfaces

Application Program Interface

The interface of an AP component includes two services: a native RM service(s) through which the AP communicates with the RMs and a TX (transaction demarcation) service through which the AP communicates with a TM.

Transaction Manager Interface

The interface of a TM component includes NumRMs XA services, one for each RM the TM may call, an AX service that ll the RMs may call, and a TX service that the AP may call.

Resource Manager Interface

The interface of a RM component includes a native service for the AP and a XA service and an AX service through which the RM communicates with a TM.

Services

TX (Transaction Demarcation) Interface

TX is the name of the service shared by the AP and the TM. The TX functions are provided by TMs and are called by APs. APs demarcate global transactions via the TX interface and perform recoverable operations via RMs' native interfaces.

Transaction Characteristics
The state of an application thread of control includes several characteristics. The AP specifies these by calling tx_set_*() functions.
Commit Return Characteristic
The commit_return characteristic determines the stage in the commitment protocol at which the tx_commit() call returns to the AP.

Transaction Control Characteristic
The transaction_control characteristic determines whether the completion of one transaction automatically begins a new transaction (called chained mode).

Transaction Timeout Characteristic
The transaction_timeout characteristic specifies the time period in which the transaction must complete before becoming susceptible to transaction timeout. The interval is expressed as a number of seconds.

Transaction Information
The TXInfo record is used to return information about the thread state, including the state of all characteristics, the thread's association, if any, to a global transaction, and transaction state information.

Transaction State
The AP may call tx_info() to obtain information regarding the state of the transaction it is in; that is, to determine whether the transaction is alive, has timed-out (and been marked rollback-only), or has beeen marked rollback-only (for a reason other than transaction timeout).

Return Codes

XA Interface

XA is the name of the services shared by the TM and the RM. XA consists of two services, ax and xa. The xa services are provided by RMs and are called by TMs, while the ax services are provided by TMs and are called by RMs.

XA Service
Each RM provides a XA_Service that gives the TM access to the RM's xa_ routines.

RM Flags

Info_Type

Resource Manager Identifier

XA Flags

XA Interface Return Codes

AX Service
The TM provides an AX_Service that gives the RMs access to the TM's ax_ routines. All TMs must provide these routines. These routines let a RM dynamicall control its participation in a transaction branch.

AX Routine's Return Codes

Native Application to Resource Manager Interface

Global Types

Thread of Control (Pid_t)

A thread of control (or a thread) is the entity, with all its context, that is currently in control of a processor. A thread of control is an operating system process: an address space and single thread of control that executes within that address space, and its required system resources.

There are several constraints associated with threads.

Transaction Branch Identifier (Xid_t)

The X/Open standard uses transaction branch identifiers (or xids) to associate individual operations with a global transaction. An xid is a string that identifies a global transaction and als identifies a specific transaction branch which is the set of operations between the TM and one RM. Each xid is generated by the TM and given to a RM. The RM may use this information to optimize its use of shared resources and locks.

The xid structure is specified in the Xid_t interface (see the Rapide code below). The xid contains a format identifier, two length fields and a data field. The data field comprises at most two contiguous components: a global transaction identifier (gtrid) and a branch qualifier (bqual). The gtrid_length field specifies the number of bytes that constitute gtrid. The bqual_length field specifies the number of bytes that constitute bqual. A value of -1 in FormatID means that the xid is null.

Commentary: The X/Open documents discuss the passing of pointers to xids, since many of the functions pass them. These pointers are valid only for the duration of the call. If the xid is needed after it is returned from the call, a local copy must be made before returning. In the reference architecture, the passing of references to xids has the same restriction.

Selected Constraints

Thread of Control Constraints

One property of threads is that all events generated by a thread are causally ordered.

The thread concept is central to the TM's coordination of RMs. APs call RMs to request work, while TMs call RMs to delineate transaction branches. The way the RM knows that a given work request pertains to a given branch is that the AP and the TM both call it from the same thread.

This protocol can be expressed in Rapide as the following constraint:

Atomicity Constraint

Transactions are not guaranteed to execute to completion, but instead are insured to a weaker but still sufficient property. Transactions are performed entirely or not at all; they cannot be only partially done at termination.

The following Rapide constraint expresses that a global transaction identifier (i.e., a process identifier) should never be the argument of a commit event for one RM and an abort event for another RM. As a consequence, any transaction is either committed by all RM's or none.

Coordination Constraint

The following Rapide constraint expresses that all commit call events from the TM to the RMs must depend upon all the prepare returns from the RMs.

Selected Behaviors

Transaction Manager

The transaction manager's primary purpose is to ensure atomicity. The most common approach to achieving atomicity is the two phase commit protocol. It is so called, because the commitment protocol is divided into two phases. Commitment refers to whether the transaction can end successfully, i.e., can do what it was requested to do.

In Phase 1, the polling phase, the manager for each resource is asked whether it can commit its part of the transaction, if it is requested to do so. If a resource manager can commit its work, it replies affirmatively. This positive response is a promise, guaranteeing that if asked to commit, it will. A negative reply reports failure for any reason. Thus, the poll is asking whether the resource can commit its transaction branch, and if so, prepare the branch for commitment.

When all the resource managers have responded, the decision phase, Phase 2, is entered. If all resource managers responded affirmatively, then all of the resource managers are requested to commit (otherwise they are all requested to undo their parts of the transaction thereby restoring the database to a consistent state. Thus, the entire transaction is ensured of being either atomically committed or undone.

Exemplary Execution

[Architecture Execution]

The independent, and possibly concurrent execution of the two resource managers is explicitly visible by the two sides of the poset. Width in a poset expresses independence. Dependencies between the two sides indicate synchronization or coordination between the components occurred. The executions of the resource managers was synchronized two times in the execution. First, when the application decided to attempt to commit the transaction. This decision was based upon the good work results of both resource managers. Presumably, if either of the transaction branches' work was not favorable, the decision would have been made to abort the transaction.

The second time the execution of the resouce managers was synchronized occurred when the application program made the decision to actually commit the transaction. This is easily visible in the poset where the dependencies criss cross near the bottom of the poset. This criss crossing is quite typical of the two phase commit protocol, and is an indication of a complex coordination between the resource managers.


8/5/97/lp