Chapter 6. Transaction

Table of Contents

6.1. Overview
6.2. Distributed Transaction
6.2.1. XA Mode
6.2.2. Non-XA Mode
6.3. Transaction Errors
6.3.1. TX Error
6.3.2. XA Error

This chapter describes transaction processing and defines transaction process management.

6.1. Overview

A transaction is a unit of work that transforms the state of a resource from one valid state to another valid state.

Tmax supports local and global transactions.

  • Local Transaction

    A Local Transaction is when a single resource manager (database) participates.

  • Global Transaction

    A Global Transaction is when multiple resource managers (databases) and physical entities participate in processing one logical unit. Tmax regards all transactions as global transactions. Currently, the Tmax system does not support nested transactions.

Tmax transaction processing preserves ACID (Atomicity, Consistency, Isolation, and Durability) properties when executing tasks. Transactions comply with the TX standard of the X/Open DTP model.

The following are the features of ACID.

  • Atomicity

    Each transaction is "all or nothing". If one part of the transaction fails, the entire transaction fails and the no data is committed.

  • Consistency

    A completed transaction changes the database from one valid state to another valid state.

  • Isolation

    Transactions executed concurrently have the same result as transactions executed serially.

  • Durability

    Once a transaction result is returned and committed, it maintains the same state even if a system or media failure occurs.

6.2. Distributed Transaction

Global transactions that involve two or more databases use 2PC (Two-Phase Commit) to guarantee ACID properties of the transaction. The following describes the two phases of 2PC.

  • Prepare Phase

    The commit manager checks whether the databases participating in the transaction are ready to commit. When all databases are ready, a ready signal is sent.

  • Commit Phase

    When all databases send a ready signal, the transaction is committed. If a database fails to send a ready signal, the transaction is rolled back.

[Figure 6.1] 2PC (2 Phase Commit) Protocol

2PC (2 Phase Commit) Protocol

Data integrity is guaranteed when processing transactions with 2PC (two phase commit), and multiple function (tx_begin, tx_commit, tx_rollback, etc.) are supported to enable global transactions. In addition, a multi-thread transaction manager ensures improved resource efficiency and dynamic error logging. Dynamic error logging enables a quick response to errors and supports reliability through Recovery/Rollback. All transactions are monitored through a single interface to facilitate easy scheduling and management of transactions.

Processing Mechanism

The Tmax distributed transaction processing mechanism complies with the TX standards of the X/Open DTP model, an international standard for distributed transaction processing.

The following is the of X/Open DTP structure.

[Figure 6.2] X/Open DTP Structure

X/Open DTP Structure

The following describes X/Open DTP components.

ClassificationDescription
APAP (Application Program) provides the boundary of a distributed transaction.
RMRM (Resource Manager) supports access resources such as a database.
TMTM (Transaction Manager) manages the process by creating an ID for each database. TM also supports recovery when failure occurs.
CRMCRM (Communication Resource Manager) manages communication between applications that have operations distributed among different computers or databases from different vendors.
OSI-TPOSI-TP (Open System Interconnection-Transaction Processing) handles communication with other TM areas.

X/OPEN ATMI processes transactions that occur between heterogeneous DBMSs that comply with X/OPEN DTP by grouping them. The following is how distributed transactions are processed.

[Figure 6.3] The Process of Distributed Transactions

The Process of Distributed Transactions


A transaction starts when tx_begin() is called and ends when tx_commit() or tx_rollback() is called.

tx_begin() is called to start a transaction; the process that calls tx_begin() becomes a transaction initiator. The transaction initiator also ends the transaction by calling tx_commit() or tx_rollback(). The transaction participants can affect the results of the transaction through the return values of tpreturn(). If tx_begin() attempts to starts another transaction while a transaction is being processed, the attempt fails and tperrno is set to TPEPROTO. However, the original transaction continues to be processed.

A client participating in a transaction can exclude a server from the transaction by setting flags to TPNOTRAN when calling tpcall() or tpacall(). In other words, an excluded server cannot influence the result of the transaction currently being processed.

There are two ways to declare a transaction: explicitly, when developers write transaction functions (e.g., tx_begin and tx_commit, etc.) and implicitly , when a database is defined in SVRGROUP of the Tmax configuration file.

Checklist for DBMS

The following is a DBMS integration checklist.

  • Check the installation of the client module provided by the DBMS vendor.

  • Database related items - Check the number of sessions allowed per client.

  • The development tool module required to create a Tmax server application is required.

  • Check the XA / Non-XA settings.

    The use of XA mode must be determined at the application design phase. XA and Non-XA can be divided based on the distributed transaction processing technique and the connections between the DBMS and the Tmax system.

    ModeDescription
    XAA DBMS connection is established based on the Tmax configuration file. X/OPEN ATMI functions are used to commit or roll back XA transactions, and the relevant processes are completed through TMS.
    Non-XADBMS connections, transaction commits, and rollbacks are processed via the developer's ESQL statement.

6.2.1. XA Mode

In XA mode, the TMS server provided by Tmax manages transactions.

Tmax regards all transactions as global transactions and uses 2PC (Two Phase Commit) to ensure data integrity. A separate configuration for connections to the resource manager must be defined in the Tmax configuration file. Transactions are managed using the Tmax API, which is necessary when processing databases in a distributed environment. The following is the program processing algorithm in XA mode.

[Figure 6.4] XA Mode

XA Mode


A separate logic for connecting to (and disconnecting from) the database is not necessary for tpsvrinit() / tpsvrdone() logic. Similar to Non-XA mode, when a Tmax server application is booted through tmboot, the Tmax system establishes a connection to the database. TMS, which manages commits and rollbacks of global transactions, also connects to the database. Any commit, rollback, or rollback cancellation requests of a global transaction must be made via the TX API of the Tmax system or according to the Tmax configuration file settings. To enable XA mode, check the server group, which includes the server application to be connected to DBMS in the SVRGROUP section of Tmax configuration file, and specify the XA setting for the server group.

The following is the SVRGROUP section configuration in XA mode.

*SVRGROUP
svg1        NODENAME = tmax,
            DBNAME = ORACLE,
            OPENINFO = "ORACLE_XA+Acc=P/scott/tiger+SesTm=600",
            TMSNAME = svg1_tms
*SERVER
svr1        SVGNAME  = svg1

Note

For more information about server group configuration environment, refer to "Tmax Administrator's Guide".

6.2.2. Non-XA Mode

The Tmax system in Non-XA mode allows each application to directly send a transaction command to the resource manager, but cannot be used for global transactions in the distributed environment. An additional setting is required to enable Non-XA mode. Non-XA mode is available by writing applications to directly connect to RDBMS and defining transactions in each application.

Non-XA mode adopts a server program mode that uses native SQL, and has transaction control linked to the RDBMS. Non-XA mode can only use local transactions. Server programs running in Non-XA mode are suitable for executing simple Select queries or time consuming batch server programs. Non-XA mode can specify transaction range and control only for a direct connection between Non-XA mode user applications and the RDBMS. Tmax is not involved in this action.

Two points distinguish Non-XA mode from XA mode.

  • SQL in the user application controls the connection with the RDBMS.

  • Server programs can request transactions but client programs cannot. It is recommended that tpsvrinit() be used to connect to a database and tpsvrdone() be used to disconnect from a database.

The following is the program processing order in Non-XA mode.

[Figure 6.5] Non-XA Mode

Non-XA Mode

  1. Create the logic to access the DBMS in the tpsvrinit().

  2. Explicitly add DBMS access rollback or release logics to tpsvrdone().

  3. When a Tmax server application is booted through tmboot or tmboot -S svrname, a connection is established between the DBMS and the Tmax server application process.

  4. After a connection is established, the service logic can send a transaction request, commit, or rollback the transaction via ESQL.

The following is the SVRGROUP section configuration in Non-XA mode.

*SVRGROUP
svg1 NODENAME = tmax

*SERVER
svr1 SVGNAME = svg1

Note

For more information about transaction-related functions, refer to "9.9. Transaction Management" or "Tmax Reference Guide".

6.3. Transaction Errors

Transaction errors include TX and XA-related errors.

TX-related errors are defined in <usrinc/tx.h>, while XA-related errors are defined by database vendors. For Oracle related errors, see <$ORACLE_HOME/rdbms/demo/xa.h>.

6.3.1. TX Error

The following is a list of transaction errors.

Error CodeDescription
TX_NOT_SUPPORTED(1)Mode does not support transactions.
TX_OK(0)Transaction completed successfully.
TX_OUTSIDE(-1)Local transaction is being processed.
TX_ROLLBACK(-2)commit cannot be executed. The transaction is rolled back.
TX_MIXED(-3)A part was committed and a part was rolled back.
TX_HAZARD(-4)Transaction did not complete successfully.
TX_PROTOCOL_ERROR(-5)Transaction was called abnormally.
TX_ERROR(-6)Error occurred in the database.
TX_FAIL(-7)Critical error occurred.
TX_EINVAL(-8)Invalid parameter was received.
TX_COMMITTED(-9)Transaction was performed on a database independently.
TX_NO_BEGIN(-10)Transaction was committed but a new transaction cannot be started.

6.3.2. XA Error

The following is a list of XA errors.

Error CodeDescription
XA_OK(0)Transaction completed successfully.
XAER_RMERR(-3)Resource Manager error set in the configured OPENINFO section.
XAER_NOTA(-4)XID is invalid.
XAER_INVAL(-5)Invalid parameter was received.
XAER_PROTO(-6)Transaction called at an improper stage.
XAER_RMFAIL(-7)Failed to connect to database.
XAER_DUPID(-8)Previously assigned XID is used.
XAER_OUTSIDE(-9)Transaction is out of transaction mode.