Distributed Transaction

ShardingSphere-Proxy supports LOCAL, XA, BASE transactions, LOCAL transaction is default value, it is original transaction of relational database.

XA transaction

Default XA transaction manager of ShardingSphere is Atomikos. Users can customize Atomikos configuration items through adding jta.properties in conf catalog of ShardingSphere-Proxy. Please refer to Official Documents of Atomikos for detailed configurations.

  • Use Narayana XA Transaction Manager。
  1. Copy the jar file required by Narayana to conf/lib. The reference package is as follows:
<properties>
    <narayana.version>5.9.1.Final</narayana.version>
    <jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
    <jboss-logging.version>3.2.1.Final</jboss-logging.version>
</properties>
<dependency>
    <groupId>org.jboss.narayana.jta</groupId>
    <artifactId>jta</artifactId>
    <version>${narayana.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.narayana.jts</groupId>
    <artifactId>narayana-jts-integration</artifactId>
    <version>${narayana.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jboss-transaction-spi</artifactId>
    <version>${jboss-transaction-spi.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <version>${jboss-logging.version}</version>
</dependency>
  1. Configure xa-transaction-manager-type in conf/server.yaml
- !TRANSACTION
  defaultType: XA
  providerType: Narayana
  1. Add jbossts-properties.xml to customize Narayana configuration. The order of path loading is user.dir (pwd) > user.home > java.home > classpath. Please refer to Narayana official documentation for more details.
  • Use Bitronix XA Transaction Manager。
  1. Copy the jar file required by Bitronix to conf/lib. The reference package is as follows:
<properties>
    <btm.version>2.1.3</btm.version>
</properties>

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-transaction-xa-bitronix</artifactId>
    <version>${shardingsphere.version}</version>
</dependency>

<dependency>
    <groupId>org.codehaus.btm</groupId>
    <artifactId>btm</artifactId>
    <version>${btm.version}</version>
</dependency>
  1. Configure xa-transaction-manager-type in conf/server.yaml
- !TRANSACTION
  defaultType: XA
  providerType: Bitronix
  1. Please refer to Bitronix official documentation for more details.

BASE Transaction

Since we have not packed the BASE implementation jar into ShardingSphere-Proxy, you should copy relevant jar which implement ShardingSphereTransactionManager SPI to conf/lib, then switch the transaction type to BASE.