Seata Transaction

Background

Apache ShardingSphere provides BASE transactions that integrate the Seata implementation.

Procedure

  1. Start Seata Server
  2. Create the log table
  3. Add the Seata configuration

Sample

Start Seata Server

Refer to seata-work-shop to download and start the Seata server.

Create undo_log table

Create the undo_log table in each shard database instance (take MySQL as an example).

  1. CREATE TABLE IF NOT EXISTS `undo_log`
  2. (
  3. `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
  4. `branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
  5. `xid` VARCHAR(100) NOT NULL COMMENT 'global transaction id',
  6. `context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
  7. `rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
  8. `log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
  9. `log_created` DATETIME NOT NULL COMMENT 'create datetime',
  10. `log_modified` DATETIME NOT NULL COMMENT 'modify datetime',
  11. PRIMARY KEY (`id`),
  12. UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
  13. ) ENGINE = InnoDB
  14. AUTO_INCREMENT = 1
  15. DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';

Modify configuration

Add the seata.conf file to the classpath.

  1. client {
  2. application.id = example ## Apply the only primary key
  3. transaction.service.group = my_test_tx_group ## The transaction group it belongs to.
  4. }

Modify the file.conf and registry.conf files of Seata as required.