Docker搭建Seata环境

Docker搭建Seata环境

  1. 添加seata需要的数据库表

直接点击
mysql数据库
oracle数据库
postgresql数据库

  1. 为业务数据库也添加一个undo_log表

Seata的AT模式下之所以在第一阶段直接提交事务,依赖的是需要在每个RM创建一张undo_log表,记录业务执行前后的数据快照。

如果二阶段需要回滚,直接根据undo_log表回滚,如果执行成功,则在第二阶段删除对应的快照数据。

直接点击
mysql数据库
oracle数据库
postgresql数据库

  1. 拉取seata镜像
docker pull seataio/seata-server:1.4.0
  1. 临时启动seata容器,复制出来registry.conf配置文件
docker run -d --name seata-server -p 8091:8091 seataio/seata- server:1.4.0

docker cp seata-server:/seata-server/resources/registry.conf /seata/config
  1. 删除刚才的临时容器
docker rm -f seata-server
  1. 修改registry.conf配置文件,服务注册和配置读取设置成nacos
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server"
    serverAddr = "47.96.234.28:8848"
    group = "DEFAULT_GROUP"
    namespace = "mom_dev"
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"

  nacos {
    serverAddr = "47.96.234.28:8848"
    group = "DEFAULT_GROUP"
    namespace = "seata_config"
    username = "nacos"
    password = "nacos"
  }
  file {
    name = "file.conf"
  }
}

  1. 推送seata配置到nacos

!!!如果现有nacos已经配置好了seata,那么就不需要再执行此步骤!

由于新版本的seata不带config.txt 和推送脚本文件 nacos-config. sh,所以需要直接在GitHub上下载。

下载地址

文件目录位置:

├── config.txt
└── nacos
    └── nacos-config.sh

如果进不去GitHub,可以直接点 config.txtnacos-config.sh。自己创建文件复制进去即可。

修改config.txt文件中的事务组和MySQL连接信息,修改信息如下:

client.undo.logSerialization=kryo

service.vgroupMapping.mom_tx_group=default

store.mode=db
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://47.96.234.28:3303/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=123456

默认的日志序列化程序不可用, jackson 的新特性找不到,Seata 要求 jackson 版本2.9.9+,但是使用 jackson 2.9.9+ 版本会导致Spring Boot中使用的jackson API找不到,也就是jackson本身的向前兼容性存在问题。因此,这里将Seata的序列化方式切换到非 jackson 序列化方式,比如 kryo,配置项为client.undo.logSerialization = “kryo”。

推送到nacos

bash nacos-config.sh -h 127.0.0.1 -p 8848 -g DEFAULT_GROUP -t seata_config -u nacos -w nacos
  • p:端口
  • h:nacos地址
  • g:配置组
  • t:命名空间id
  • u:账号
  • w:密码

推送成功后会有以下配置文件

在这里插入图片描述

  1. 启动Seata

docker-compose.yml

version: "3"
services:
  seata-server:
    image: seataio/seata-server:1.4.0
    container_name: seata-server
    hostname: seata-server
    ports:
      - "8091:8091"
    environment:
      - SEATA_PORT=8091
      - SEATA_IP=47.96.234.28
      - SEATA_CONFIG_NAME=file:/seata-server/resources/registry.conf
    volumes:
      - ./config/registry.conf:/seata-server/resources/registry.conf

SEATA_IP一定要写成外网ip,不然会访问不了

然后直接启动即可。

Spring Cloud端配置

  1. 添加pom依赖
        <!--seata-->
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-all</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.seata</groupId>
                    <artifactId>seata-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>
            <version>1.4.0</version>
        </dependency>

        <!--        kryo集成-->
        <dependency>
            <groupId>com.esotericsoftware.kryo</groupId>
            <artifactId>kryo</artifactId>
            <version>2.24.0</version>
        </dependency>
        <dependency>
            <groupId>de.javakaffee</groupId>
            <artifactId>kryo-serializers</artifactId>
            <version>0.45</version>
        </dependency>
        <dependency>
            <groupId>com.esotericsoftware</groupId>
            <artifactId>kryo</artifactId>
            <version>4.0.2</version>
        </dependency>

需要指定seata版本和seata-server版本一致,这里也就是1.4.0

  1. yml文件配置

bootstrap.yml,自己根据自己的nacos、seata配置。

spring:
  application:
    name: mom-tms-server

  cloud:
    nacos:
      discovery:
        username: ${NACOS_USER:nacos}
        password: ${NACOS_PWD:nacos}
        server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
        group: DEFAULT_GROUP
        namespace: ${NACOS_NAMESPACE:mom_dev}
        enabled: true
        register-enabled: true
      config:
        username: ${NACOS_USER:nacos}
        password: ${NACOS_PWD:nacos}
        server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
        group: DEFAULT_GROUP
        namespace: ${NACOS_NAMESPACE:mom_dev}
        file-extension: yml
        refresh-enabled: true

# 分布式事务配置
seata:
  tx-service-group: mom_tx_group
  enable-auto-data-source-proxy: true
  registry:
    type: nacos
    nacos:
      username: ${NACOS_USER:nacos}
      password: ${NACOS_PWD:nacos}
      server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
      namespace: ${NACOS_NAMESPACE:mom_dev}
      group: DEFAULT_GROUP
  config:
    type: nacos
    nacos:
      username: ${NACOS_USER:nacos}
      password: ${NACOS_PWD:nacos}
      server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
      namespace: ${NACOS_NAMESPACE_SEATA:seata_config}
      group: DEFAULT_GROUP
  service:
    vgroup-mapping:
      mom_tx_group: default
  • tx-service-group: mom_tx_group 配置事务群组,其中群组名称 mom_tx_group 需和服务端的配置 service.vgroupMapping.mom_tx_group=default 一致
  • enable-auto-data-source-proxy: true 自动为Seata开启了代理数据源,实现集成对undo_log表操作
  • namespace: mom_dev 和seata-server一致
  • group: DEFAULT_GROUP 和seata-server一致
  1. 启动类

启动类添加@EnableAutoDataSourceProxy注解来开启seata事务配置。

  1. 为需要的业务添加@GlobalTransactional注解
@GlobalTransactional(rollbackFor = Exception.class, name = "mom_tx_group")
public boolean submit() {
    // 各种操作
    return ...;
}




下面先了解一下seata的基本工作原理,然后看一个详细的案例。

Seata术语

  • Transaction ID - XID:全局唯一事务ID

  • TC (Transaction Coordinator) - 事务协调者
    维护全局和分支事务的状态,驱动全局事务提交或回滚。

  • TM (Transaction Manager) - 事务管理器
    定义全局事务的范围:开始全局事务、提交或回滚全局事务。

  • RM (Resource Manager) - 资源管理器
    管理分支事务处理的资源,与TC交谈以注册分支事务和报告分支事务的状态,并驱动分支事务提交或回滚。

seata分布式事务处理过程

在这里插入图片描述

  1. TM向TC申请开启一个全局事务,全局事务开启,并生成一个全局唯一的XID。
  2. XID在微服务在微服务调用链路的上下文中传播。
  3. RM向TC注册分之事务,将其纳入XID对应全局事物的管辖。
  4. TM向TC发起针对XID的全局提交或回滚协议。
  5. TC调度XID下管辖的全局分之事务完成提交或回滚请求。

分布式交易案例

此处引用seata官方的一个案例:用户购买商品的业务逻辑。整个业务逻辑由3个微服务提供支持:

  • 仓储服务:对给定的商品扣除仓储数量。
  • 订单服务:根据采购需求创建订单。
  • 帐户服务:从用户帐户中扣除余额。

架构图

在这里插入图片描述

仓储服务

public interface StorageService {

    /**
     * 扣除存储数量
     */
    void deduct(String commodityCode, int count);
}

订单服务

public interface OrderService {

    /**
     * 创建订单
     */
    Order create(String userId, String commodityCode, int orderCount);
}

账户服务

public interface AccountService {

    /**
     * 从用户账户中借出
     */
    void debit(String userId, int money);
}

主要业务逻辑

public class BusinessServiceImpl implements BusinessService {

    private StorageService storageService;

    private OrderService orderService;

    /**
     * 采购
     */
    public void purchase(String userId, String commodityCode, int orderCount) {

        // 减库存
        storageService.deduct(commodityCode, orderCount);
        
        // 创建订单、更新账户余额
        orderService.create(userId, commodityCode, orderCount);
    }
}
public class OrderServiceImpl implements OrderService {

    private OrderDAO orderDAO;

    private AccountService accountService;

    public Order create(String userId, String commodityCode, int orderCount) {

        int orderMoney = calculate(commodityCode, orderCount);

        // 更新账户yue余额
        accountService.debit(userId, orderMoney);

        Order order = new Order();
        order.userId = userId;
        order.commodityCode = commodityCode;
        order.count = orderCount;
        order.money = orderMoney;

        // 创建订单
        return orderDAO.insert(order);
    }
}
SEATA 的分布式交易解决方案

在这里插入图片描述

我们只需要使用一个 @GlobalTransactional 注解在业务方法上:

 @GlobalTransactional
    public void purchase(String userId, String commodityCode, int orderCount) {
        ......
    }

我们的MOM统一把事务加在了controller层,所以只需要在controller层的方法上添加@GlobalTransactional即可。

下面几点需要注意:

  • 如果调用服务只是用来查询,比如服务A调用服务B、服务C来查询某些数据,所有的更新操作都在服务A上,那么就不用集成seata来引用全局事务。直接采用@Transactional注解即可。
  • queryDSL不支持seata,如果有涉及到用queryDSL进行更新操作的,大家在集成seata的时候,记得要保留原来的@Transactional。如果queryDSL只是用在查询上,就不用保留原来的@Transactional。建议修改使用JPA来操作。
  • 严禁catch捕获异常之后不抛出,不允许异常捕获之后手动回滚事务。




副本文件

config.txt

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=true
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
store.mode=file
store.lock.mode=file
store.session.mode=file
store.publicKey=
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=username
store.db.password=password
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

nacos-config.sh

#!/usr/bin/env bash
# Copyright 1999-2019 Seata.io Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at、
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

while getopts ":h:p:g:t:u:w:" opt
do
  case $opt in
  h)
    host=$OPTARG
    ;;
  p)
    port=$OPTARG
    ;;
  g)
    group=$OPTARG
    ;;
  t)
    tenant=$OPTARG
    ;;
  u)
    username=$OPTARG
    ;;
  w)
    password=$OPTARG
    ;;
  ?)
    echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
    exit 1
    ;;
  esac
done

urlencode() {
  for ((i=0; i < ${#1}; i++))
  do
    char="${1:$i:1}"
    case $char in
    [a-zA-Z0-9.~_-]) printf $char ;;
    *) printf '%%%02X' "'$char" ;;
    esac
  done
}

if [[ -z ${host} ]]; then
    host=localhost
fi
if [[ -z ${port} ]]; then
    port=8848
fi
if [[ -z ${group} ]]; then
    group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
    tenant=""
fi
if [[ -z ${username} ]]; then
    username=""
fi
if [[ -z ${password} ]]; then
    password=""
fi

nacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"

echo "set nacosAddr=$nacosAddr"
echo "set group=$group"

failCount=0
tempLog=$(mktemp -u)
function addConfig() {
  curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$(urlencode $1)&group=$group&content=$(urlencode $2)&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
  if [[ -z $(cat "${tempLog}") ]]; then
    echo " Please check the cluster status. "
    exit 1
  fi
  if [[ $(cat "${tempLog}") =~ "true" ]]; then
    echo "Set $1=$2 successfully "
  else
    echo "Set $1=$2 failure "
    (( failCount++ ))
  fi
}

count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
  (( count++ ))
	key=${line%%=*}
    value=${line#*=}
	addConfig "${key}" "${value}"
done

echo "========================================================================="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "========================================================================="

if [[ ${failCount} -eq 0 ]]; then
	echo " Init nacos config finished, please start seata-server. "
else
	echo " init nacos config fail. "
fi

mysql数据库

/*
 Navicat Premium Data Transfer

 Source Server         : 47.96.234.28_3303
 Source Server Type    : MySQL
 Source Server Version : 50733
 Source Host           : 47.96.234.28:3303
 Source Schema         : seata

 Target Server Type    : MySQL
 Target Server Version : 50733
 File Encoding         : 65001

 Date: 04/07/2021 22:42:44
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for branch_table
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `client_id` varchar(64) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime(6) DEFAULT NULL,
  `gmt_modified` datetime(6) DEFAULT NULL,
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table` (
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(32) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `begin_time` bigint(20) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`xid`),
  KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
  `row_key` varchar(128) NOT NULL,
  `xid` varchar(96) DEFAULT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `branch_id` bigint(20) NOT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `table_name` varchar(32) DEFAULT NULL,
  `pk` varchar(36) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`row_key`),
  KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
  `branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id',
  `xid` varchar(100) NOT NULL COMMENT 'global transaction id',
  `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
  `rollback_info` longblob NOT NULL COMMENT 'rollback info',
  `log_status` int(11) NOT NULL COMMENT '0:normal status,1:defense status',
  `log_created` datetime NOT NULL COMMENT 'create datetime',
  `log_modified` datetime NOT NULL COMMENT 'modify datetime',
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table';


SET FOREIGN_KEY_CHECKS = 1;

oracle数据库

-- Create table
create table UNDO_LOG
(
  id            NUMBER(20) not null,
  branch_id     NUMBER(20) not null,
  xid           VARCHAR2(100) not null,
  context       VARCHAR2(128) not null,
  rollback_info BLOB,
  log_status    INTEGER,
  log_created   DATE,
  log_modified  DATE
);
-- Create/Recreate indexes 
create index IDX_XRID on UNDO_LOG (BRANCH_ID, XID);
-- Create/Recreate primary, unique and foreign key constraints 
alter table UNDO_LOG
  add constraint PK_UNDO primary key (ID);
create sequence UNDO_LOG_SEQ
minvalue 1
maxvalue 9999999999999999999999999
start with 1
increment by 1
cache 20;



create table GLOBAL_TABLE (
  xid varchar2(128)  not null,
  transaction_id NUMBER(20),
  status NUMBER(10) not null,
  application_id varchar2(64),
  transaction_service_group varchar2(64),
  transaction_name varchar2(128),
  timeout NUMBER(10),
  begin_time NUMBER(20),
  application_data varchar2(2000),
  gmt_create DATE,
  gmt_modified DATE
);


create table BRANCH_TABLE (
  branch_id NUMBER(20) not null,
  xid varchar2(128) not null,
  transaction_id NUMBER(20) ,
  resource_group_id varchar2(128),
  resource_id varchar2(256) ,
  lock_key varchar2(256) ,
  branch_type varchar2(8) ,
  status NUMBER(10),
  client_id varchar2(64),
  application_data varchar2(2000),
  gmt_create DATE,
  gmt_modified DATE
);


create table LOCK_TABLE (
  row_key varchar2(128) not null,
  xid varchar2(128),
  transaction_id NUMBER(20) ,
  branch_id NUMBER(20),
  resource_id varchar2(256) ,
  table_name varchar2(64) ,
  pk varchar2(128) ,
  gmt_create DATE ,
  gmt_modified DATE
);

postgresql数据库

-- Create table
create table UNDO_LOG (
    id            NUMERIC(20) not null,
    branch_id     NUMERIC(20) not null,
    xid           VARCHAR(100) not null,
    context       VARCHAR(128) not null,
    rollback_info text,
    log_status    INTEGER,
    log_created   DATE,
    log_modified  DATE
);

-- Create/Recreate indexes
create index IDX_XRID on UNDO_LOG (BRANCH_ID, XID);

-- Create/Recreate primary, unique and foreign key constraints
alter table UNDO_LOG  add constraint PK_UNDO primary key (ID);

create sequence UNDO_LOG_SEQ minvalue 1 maxvalue 9223372036854775807 start with 1 increment by 1 cache 20;

create table GLOBAL_TABLE (
    xid varchar(128)  not null,
    transaction_id NUMERIC(20),
    status NUMERIC(10) not null,
    application_id varchar(64),
    transaction_service_group varchar(64),
    transaction_name varchar(128),
    timeout NUMERIC(10),
    begin_time NUMERIC(20),
    application_data varchar(2000),
    gmt_create DATE,  gmt_modified DATE
);

create table BRANCH_TABLE (
    branch_id NUMERIC(20) not null,
    xid varchar(128) not null,
    transaction_id NUMERIC(20) ,
    resource_group_id varchar(128),
    resource_id varchar(256) ,
    lock_key varchar(256) ,
    branch_type varchar(8) ,
    status NUMERIC(10),
    client_id varchar(64),
    application_data varchar(2000),
    gmt_create DATE,
    gmt_modified DATE
);

create table LOCK_TABLE (
    row_key varchar(128) not null,
    xid varchar(128),
    transaction_id NUMERIC(20) ,
    branch_id NUMERIC(20),
    resource_id varchar(256) ,
    table_name varchar(64) ,
    pk varchar(128) ,
    gmt_create DATE ,
    gmt_modified DATE
);
  • 16
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值