Skip to main content

Developing with XCC

XA

This program demonstrates using MarkLogic Server in a distributed XA transaction. The sample uses JBoss as a Transaction Manager, with two MarkLogic Server clusters participating in the distributed transaction.

The sample uses libraries from JBossTS. Download and install JBossTS 4.15.0 or later from the following location. The JBoss Application Server is not needed.

http://www.jboss.org/jbosstm

Include the following libraries from the JBossTS package on your classpath. JBOSS_HOME is the directory where JBossTS is installed.

  • JBOSSTS_HOME/lib/jbossjta.jar

  • JBOSSTS_HOME/lib/ext/jboss-transaction-api_1.1_spec.jar (or other JTA implementation)

  • JBOSSTS_HOME/lib/ext/jboss-logging.jar

The participating MarkLogic Server clusters may simply be two XDBC App Servers on the same instance, serving different databases.

The following is a sample command to run the ModuleRunner class. Change XCC_HOME, JBOSSTS_HOME, and the two content base URIs to match your installation.

java -classpath "XCC_HOME/lib/xcc.jar:XCC_HOME/lib/xccexamples.jar:
     JBOSSTS_HOME/lib/jbossjta.jar:
     JBOSSTS_HOME/lib/ext/jboss-transaction-api_1.1_spec.jar:
     JBOSSTS_HOME/lib/ext/jboss-logging.jar"
     com.marklogic.xcc.examples.XA 
     xcc://username1:password1@host1:port1/contentbase1
     xcc://username2:password2@host2:port2/contentbase2

The sample program enlists each contentbase as a resource with the JBoss Transaction Manager, and then inserts a document in each contentbase, as part of a single global transaction. The output from xdmp:host-status relevant to each branch’s transaction is printed out. This information includes the global transaction id and branch qualifer, as well as the local transaction id:

<transaction xmlns="http://marklogic.com/xdmp/status/host">
  <transaction-id>750821115632601886</transaction-id> 
  <host-id>8814043795788656336</host-id>
  <server-id>4366002345564888063</server-id>
  <xid format-id="131076" xmlns="http://marklogic.com/xdmp/xa">
    <global-transaction-id>...825D0000000931</global-transaction-id>
    <branch-qualifier>...825D0000000A</branch-qualifier>
  </xid> 
  <name/>
  <mode>update</mode>
  <timestamp>0</timestamp>
  <state>active</state>
  <database>2901782035623219290</database>
  <canceled>false</canceled>
  ...
</transaction>
<transaction xmlns="http://marklogic.com/xdmp/status/host">
  <transaction-id>4949312806261581854</transaction-id>
  <host-id>8814043795788656336</host-id>
  <server-id>7579943212553445602</server-id>
  <xid format-id="131076" xmlns="http://marklogic.com/xdmp/xa">
    <global-transaction-id>0...825D0000000931</global-transaction-id>
    <branch-qualifier>...825D0000000D</branch-qualifier>
  </xid>
  <name/>
  <mode>update</mode>
  <timestamp>0</timestamp>
  <state>active</state>
  <database>2852559629722654718</database>
  <canceled>false</canceled>
  ...
</transaction>

For details on use XA with MarkLogic Server, see Multi-statement Transactions.