A TC TX usage example with Oracle

Figure 7.1. Deployment model of two example applications with Oracle DBMS

Deployment model of two example applications with Oracle DBMS

This example shows how two application programs can take part in the same global transaction when using the same Resource Manager coordinated by the LIXA Transaction Manager. Please make sure that you are comfortable with previous sections and examples before setting this up.

The following relates to the figure above:

This example was developed using the following configuration:

The environment should be prepared following these steps:

Important

LIXA must be configured to support the Oracle Resource Manager as explained in the section called “Linking third party resource managers”.

Set the environment variables

Set up the required environment variables:

[Shell terminal session]
[pieter.jvrensburg@centos-linux ~]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
[pieter.jvrensburg@centos-linux ~]$ export ORACLE_SID=XE
[pieter.jvrensburg@centos-linux ~]$ export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
[pieter.jvrensburg@centos-linux ~]$ export PATH=$ORACLE_HOME/bin:$PATH
[pieter.jvrensburg@centos-linux ~]$ export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
              
And for LIXA:
[pieter.jvrensburg@centos-linux ~]$ export PATH=/opt/lixa/bin:/opt/lixa/sbin:$PATH
[pieter.jvrensburg@centos-linux ~]$ export LD_LIBRARY_PATH=/opt/lixa/lib:$LD_LIBRARY_PATH
              

Build the client programs

Prepare the client (Application Program) using the below commands:

[Shell terminal session]
[pieter.jvrensburg@centos-linux tmp]$ cp /opt/lixa/share/doc/lixa/X.Y.Z/examples/example15_transaction_coupling.c .
[pieter.jvrensburg@centos-linux tmp]$ cc $(lixa-config -c -f -l) -L$ORACLE_HOME/lib -lclntsh -lnnz11 example15_transaction_coupling.c
              

Next, verify the executable produced by cc:

[Shell terminal session]
[pieter.jvrensburg@centos-linux tmp]$ ldd a.out 
	linux-vdso.so.1 =>  (0x00007ffce4b13000)
	liblixac.so.0 => /opt/lixa/lib/liblixac.so.0 (0x00007f39938f6000)
	libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1 (0x00007f39910aa000)
	libnnz11.so => /u01/app/oracle/product/11.2.0/xe/lib/libnnz11.so (0x00007f3990ce2000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f3990919000)
	libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f3990714000)
	libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f3990512000)
	libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f39901a8000)
	liblixab.so.0 => /opt/lixa/lib/liblixab.so.0 (0x00007f398ff8a000)
	libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f398fc53000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f398fa37000)
	libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f398f831000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f398f52f000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f398f32b000)
	libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f398f111000)
	libaio.so.1 => /lib64/libaio.so.1 (0x00007f398ef0f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f3993b17000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f398ecf9000)
	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f398ead2000)
              

Configure the LIXA environment

Set up the LIXA_PROFILE environment variable:

[Shell terminal session]
[pieter.jvrensburg@centos-linux ~]$ export LIXA_PROFILE=ORA_STA
[pieter.jvrensburg@centos-linux ~]$ echo $LIXA_PROFILE 
ORA_STA
              

See the section called “Some checks before program execution” for additional information on creating the profile configuration file.

Test program execution

This shows how a transaction was suspended and resumed within the same thread of control. The example in example15_transaction_coupling.c does not interact with the actual Oracle database, but loads the switch file.

Important

Make sure that the LIXA state server (lixad) is running before executing the example application, as explained in the section called “Starting the state server (lixad)”.

Successful execution

The transaction is suspended, resumed and then rolled back:

[Shell terminal session]
[pieter.jvrensburg@centos-linux tmp]$ LIXA_CONFIG_FILE=./lixac_conf.xml LIXA_PROFILE=ORA_STA ./a.out 
tx_open(): 0
tx_begin(): 0
tx_end(TMSUSPEND): 0
tx_info(): 1
tx_resume(): 0
tx_commit(): 0
tx_begin(): 0
tx_end(TMSUSPEND): 0
tx_info(): 1
tx_resume(): 0
tx_rollback(): 0
tx_close(): 0
              

Conclusion

This example shows a basic usage of the extended TX interface API calls. A more elaborate use case will include developing two application programs that communicate with each other and share the XID obtained from tx_info so that the second application program can join the existing transaction.