From 0c2efd36cf6cd43329806396c93f49ebe7a2a597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Tue, 18 Jan 2022 10:48:53 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=95=B4=E5=90=88=20seata=201.4.2=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=20nacos=20=E6=B3=A8=E5=86=8C=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=20=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/dev/application.yml | 15 ++-- config/dev/ruoyi-system.yml | 11 ++- config/dev/seata-server.properties | 47 ++++++++++++ docker/seata/registry.conf | 28 +++++++ pom.xml | 7 ++ ruoyi-auth/pom.xml | 5 ++ ruoyi-common/pom.xml | 1 + ruoyi-common/ruoyi-common-bom/pom.xml | 7 ++ ruoyi-common/ruoyi-common-datasource/pom.xml | 76 +++++++++---------- .../env/ApplicationSeataInitializer.java | 26 ------- .../main/resources/META-INF/spring.factories | 3 +- ruoyi-common/ruoyi-common-seata/pom.xml | 39 ++++++++++ .../main/resources/META-INF/spring.factories | 1 + ruoyi-modules/ruoyi-file/pom.xml | 5 ++ .../file/controller/SysFileController.java | 11 ++- .../file/dubbo/RemoteFileServiceImpl.java | 3 + .../ruoyi/file/service/ISysFileService.java | 38 +++++----- ruoyi-modules/ruoyi-system/pom.xml | 5 ++ .../controller/SysProfileController.java | 4 + sql/ry_config.sql | 5 +- sql/ry_seata.sql | 20 ++++- 21 files changed, 245 insertions(+), 112 deletions(-) create mode 100644 config/dev/seata-server.properties create mode 100644 docker/seata/registry.conf delete mode 100644 ruoyi-common/ruoyi-common-datasource/src/main/java/com/ruoyi/common/datasource/env/ApplicationSeataInitializer.java create mode 100644 ruoyi-common/ruoyi-common-seata/pom.xml create mode 100644 ruoyi-common/ruoyi-common-seata/src/main/resources/META-INF/spring.factories diff --git a/config/dev/application.yml b/config/dev/application.yml index 760fa7e4..1aa2ef7b 100644 --- a/config/dev/application.yml +++ b/config/dev/application.yml @@ -210,20 +210,17 @@ seata: application-id: ${spring.application.name} # Seata 事务组编号,用于 TC 集群名 tx-service-group: ${spring.application.name}-group - # 服务配置项 - service: - # 虚拟组和分组的映射 - vgroup-mapping: - ${spring.application.name}: default config: type: nacos nacos: - serverAddr: ${spring.cloud.nacos.server-addr} - group: SEATA_GROUP - namespace: + server-addr: ${spring.cloud.nacos.server-addr} + group: ${spring.cloud.nacos.config.group} + namespace: ${spring.profiles.active} + data-id: seata-server.properties registry: type: nacos nacos: application: seata-server server-addr: ${spring.cloud.nacos.server-addr} - namespace: + group: ${spring.cloud.nacos.discovery.group} + namespace: ${spring.profiles.active} diff --git a/config/dev/ruoyi-system.yml b/config/dev/ruoyi-system.yml index fabe6022..19e4c03c 100644 --- a/config/dev/ruoyi-system.yml +++ b/config/dev/ruoyi-system.yml @@ -17,12 +17,11 @@ spring: username: ${datasource.system-master.username} password: ${datasource.system-master.password} # 从库数据源 - slave: - lazy: true - driver-class-name: - url: - username: - password: + # slave: + # driver-class-name: + # url: + # username: + # password: xxl: job: diff --git a/config/dev/seata-server.properties b/config/dev/seata-server.properties new file mode 100644 index 00000000..dbb3f72e --- /dev/null +++ b/config/dev/seata-server.properties @@ -0,0 +1,47 @@ +service.vgroupMapping.ruoyi-auth-group=default +service.vgroupMapping.ruoyi-system-group=default +service.vgroupMapping.ruoyi-file-group=default +service.enableDegrade=false +service.disableGlobalTransaction=false +store.mode=db +store.publicKey= +store.db.datasource=druid +store.db.dbType=mysql +store.db.driverClassName=com.mysql.cj.jdbc.Driver +store.db.url=jdbc:mysql://172.30.0.36:3306/ry-seata?useUnicode=true&rewriteBatchedStatements=true +store.db.user=root +store.db.password=root +store.db.minConn=5 +store.db.maxConn=30 +store.db.globalTable=global_table +store.db.branchTable=branch_table +store.db.distributedLockTable=distributed_lock +store.db.queryLimit=100 +store.db.lockTable=lock_table +store.db.maxWait=5000 +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=kryo +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 +tcc.fence.logTableName=tcc_fence_log +tcc.fence.cleanPeriod=1h diff --git a/docker/seata/registry.conf b/docker/seata/registry.conf new file mode 100644 index 00000000..2912ddb7 --- /dev/null +++ b/docker/seata/registry.conf @@ -0,0 +1,28 @@ +registry { + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + type = "nacos" + + nacos { + application = "seata-server" + serverAddr = "172.30.0.40:8848" + group = "DEFAULT_GROUP" + namespace = "dev" + cluster = "default" + username = "" + password = "" + } +} + +config { + # file、nacos 、apollo、zk、consul、etcd3 + type = "nacos" + + nacos { + serverAddr = "172.30.0.40:8848" + group = "DEFAULT_GROUP" + namespace = "dev" + username = "" + password = "" + dataId = "seata-server.properties" + } +} diff --git a/pom.xml b/pom.xml index 3cf9c570..6c9ddb39 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ 3.16.7 2.2.1 2.7.15 + 1.4.2 1.0.11 2.3.0 2.0.9 @@ -120,6 +121,12 @@ ${dubbo.version} + + io.seata + seata-spring-boot-starter + ${seata.version} + + com.alibaba.spring spring-context-support diff --git a/ruoyi-auth/pom.xml b/ruoyi-auth/pom.xml index e1e9efa6..4fe94665 100644 --- a/ruoyi-auth/pom.xml +++ b/ruoyi-auth/pom.xml @@ -56,6 +56,11 @@ ruoyi-common-dubbo + + com.ruoyi + ruoyi-common-seata + + diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index b12a900d..fdf304bf 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -21,6 +21,7 @@ ruoyi-common-web ruoyi-common-job ruoyi-common-dubbo + ruoyi-common-seata ruoyi-common-loadbalancer diff --git a/ruoyi-common/ruoyi-common-bom/pom.xml b/ruoyi-common/ruoyi-common-bom/pom.xml index 086b1989..6f6625b8 100644 --- a/ruoyi-common/ruoyi-common-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-bom/pom.xml @@ -89,6 +89,13 @@ ruoyi-common-dubbo ${project.version} + + + com.ruoyi + ruoyi-common-seata + ${project.version} + + com.ruoyi ruoyi-common-loadbalancer diff --git a/ruoyi-common/ruoyi-common-datasource/pom.xml b/ruoyi-common/ruoyi-common-datasource/pom.xml index f7a1d98d..7b6256ca 100644 --- a/ruoyi-common/ruoyi-common-datasource/pom.xml +++ b/ruoyi-common/ruoyi-common-datasource/pom.xml @@ -1,41 +1,35 @@ - - - - com.ruoyi - ruoyi-common - 0.3.0 - - 4.0.0 - - ruoyi-common-datasource - - - ruoyi-common-datasource多数据源 - - - - - - - com.alibaba - druid-spring-boot-starter - ${druid.version} - - - - - com.baomidou - dynamic-datasource-spring-boot-starter - ${dynamic-ds.version} - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-seata - - - - \ No newline at end of file + + + + com.ruoyi + ruoyi-common + 0.3.0 + + 4.0.0 + + ruoyi-common-datasource + + + ruoyi-common-datasource多数据源 + + + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-ds.version} + + + + diff --git a/ruoyi-common/ruoyi-common-datasource/src/main/java/com/ruoyi/common/datasource/env/ApplicationSeataInitializer.java b/ruoyi-common/ruoyi-common-datasource/src/main/java/com/ruoyi/common/datasource/env/ApplicationSeataInitializer.java deleted file mode 100644 index 28394ead..00000000 --- a/ruoyi-common/ruoyi-common-datasource/src/main/java/com/ruoyi/common/datasource/env/ApplicationSeataInitializer.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ruoyi.common.datasource.env; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.Ordered; -import org.springframework.core.env.ConfigurableEnvironment; - -/** - * seata 在 springboot 2.6.x 存在循环引用问题的处理 - * - * @author ruoyi - */ -public class ApplicationSeataInitializer implements EnvironmentPostProcessor, Ordered -{ - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) - { - System.setProperty("spring.main.allow-circular-references", "true"); - } - - @Override - public int getOrder() - { - return Ordered.LOWEST_PRECEDENCE; - } -} diff --git a/ruoyi-common/ruoyi-common-datasource/src/main/resources/META-INF/spring.factories b/ruoyi-common/ruoyi-common-datasource/src/main/resources/META-INF/spring.factories index bdfc1f69..e58c6559 100644 --- a/ruoyi-common/ruoyi-common-datasource/src/main/resources/META-INF/spring.factories +++ b/ruoyi-common/ruoyi-common-datasource/src/main/resources/META-INF/spring.factories @@ -1,2 +1 @@ -org.springframework.boot.env.EnvironmentPostProcessor=\ - com.ruoyi.common.datasource.env.ApplicationSeataInitializer +org.springframework.boot.env.EnvironmentPostProcessor= diff --git a/ruoyi-common/ruoyi-common-seata/pom.xml b/ruoyi-common/ruoyi-common-seata/pom.xml new file mode 100644 index 00000000..7e86426b --- /dev/null +++ b/ruoyi-common/ruoyi-common-seata/pom.xml @@ -0,0 +1,39 @@ + + + + com.ruoyi + ruoyi-common + 0.3.0 + + 4.0.0 + + ruoyi-common-seata + + + ruoyi-common-seata 分布式事务 + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + + + com.esotericsoftware + kryo + 4.0.2 + + + de.javakaffee + kryo-serializers + 0.45 + + + + diff --git a/ruoyi-common/ruoyi-common-seata/src/main/resources/META-INF/spring.factories b/ruoyi-common/ruoyi-common-seata/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..485802b1 --- /dev/null +++ b/ruoyi-common/ruoyi-common-seata/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration= \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-file/pom.xml b/ruoyi-modules/ruoyi-file/pom.xml index 1277cc1d..2c761066 100644 --- a/ruoyi-modules/ruoyi-file/pom.xml +++ b/ruoyi-modules/ruoyi-file/pom.xml @@ -70,6 +70,11 @@ ruoyi-common-dubbo + + com.ruoyi + ruoyi-common-seata + + com.ruoyi ruoyi-common-web diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/controller/SysFileController.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/controller/SysFileController.java index a6700241..12bdbe21 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/controller/SysFileController.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/controller/SysFileController.java @@ -5,9 +5,8 @@ import com.ruoyi.common.core.utils.file.FileUtils; import com.ruoyi.file.api.domain.SysFile; import com.ruoyi.file.service.ISysFileService; import io.swagger.annotations.Api; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -18,12 +17,12 @@ import org.springframework.web.multipart.MultipartFile; * @author ruoyi */ @Api(tags = "文件处理") +@Slf4j +@RequiredArgsConstructor @RestController public class SysFileController { - private static final Logger log = LoggerFactory.getLogger(SysFileController.class); - @Autowired - private ISysFileService sysFileService; + private final ISysFileService sysFileService; /** * 文件上传请求 diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java index be4c940b..818599a4 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java @@ -31,6 +31,9 @@ public class RemoteFileServiceImpl implements RemoteFileService { */ @Override public SysFile upload(String name, String originalFilename, String contentType, byte[] file) { + // todo 临时用于测试 seata + // throw new ServiceException("上传文件失败"); + MultipartFile multipartFile = getMultipartFile(name, originalFilename, contentType, file); try { // 上传并返回访问地址 diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/ISysFileService.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/ISysFileService.java index 674622be..98b354a0 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/ISysFileService.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/ISysFileService.java @@ -1,19 +1,19 @@ -package com.ruoyi.file.service; - -import org.springframework.web.multipart.MultipartFile; - -/** - * 文件上传接口 - * - * @author ruoyi - */ -public interface ISysFileService { - /** - * 文件上传接口 - * - * @param file 上传的文件 - * @return 访问地址 - * @throws Exception - */ - public String uploadFile(MultipartFile file) throws Exception; -} +package com.ruoyi.file.service; + +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件上传接口 + * + * @author ruoyi + */ +public interface ISysFileService { + /** + * 文件上传接口 + * + * @param file 上传的文件 + * @return 访问地址 + * @throws Exception + */ + String uploadFile(MultipartFile file) throws Exception; +} diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml index e549652e..e4573560 100644 --- a/ruoyi-modules/ruoyi-system/pom.xml +++ b/ruoyi-modules/ruoyi-system/pom.xml @@ -86,6 +86,11 @@ ruoyi-common-dubbo + + com.ruoyi + ruoyi-common-seata + + com.ruoyi ruoyi-common-job diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java index 6179a6aa..f96201f3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java @@ -108,9 +108,13 @@ public class SysProfileController extends BaseController { /** * 头像上传 */ + // @GlobalTransactional(rollbackFor = Exception.class) @Log(title = "用户头像", businessType = BusinessType.UPDATE) @PostMapping("/avatar") public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException { + // todo 临时用于测试 seata + // userService.insertUser(new SysUser().setUserName("test").setNickName("test")); + if (!file.isEmpty()) { LoginUser loginUser = SecurityUtils.getLoginUser(); SysFile sysFile = remoteFileService.upload(file.getName(), file.getOriginalFilename(), file.getContentType(), file.getBytes()); diff --git a/sql/ry_config.sql b/sql/ry_config.sql index a6c9b7fe..49e3d802 100644 --- a/sql/ry_config.sql +++ b/sql/ry_config.sql @@ -43,6 +43,8 @@ insert into config_info(id, data_id, group_id, content, md5, gmt_create, gmt_mod (9, 'ruoyi-file.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:20:35', '2022-01-09 15:21:21', NULL, '0:0:0:0:0:0:0:1', '', 'dev', '文件服务', NULL, NULL, 'yaml', NULL), (10, 'sentinel-ruoyi-gateway.json', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'dev', '限流策略', NULL, NULL, 'json', NULL), (11, 'ruoyi-xxl-job-admin.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'dev', '定时任务控制台', NULL, NULL, 'yaml', NULL), +(12, 'seata-server.properties', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'dev', 'seata配置文件', NULL, NULL, 'properties', NULL), + (101, 'application.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '通用配置基础配置', NULL, NULL, 'yaml', NULL), (102, 'datasource.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '数据源配置', NULL, NULL, 'yaml', NULL), (103, 'ruoyi-gateway.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '网关模块', NULL, NULL, 'yaml', NULL), @@ -53,7 +55,8 @@ insert into config_info(id, data_id, group_id, content, md5, gmt_create, gmt_mod (108, 'ruoyi-job.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '定时任务', NULL, NULL, 'yaml', NULL), (109, 'ruoyi-file.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '文件服务', NULL, NULL, 'yaml', NULL), (110, 'sentinel-ruoyi-gateway.json', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:23:00', '2022-01-09 15:23:00', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '限流策略', NULL, NULL, 'json', NULL), -(111, 'ruoyi-xxl-job-admin.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '定时任务控制台', NULL, NULL, 'yaml', NULL); +(111, 'ruoyi-xxl-job-admin.yml', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'prod', '定时任务控制台', NULL, NULL, 'yaml', NULL), +(112, 'seata-server.properties', 'DEFAULT_GROUP', '# 将项目路径:config/下对应文件中内容复制到此处', '2944a25cb97926efcaa43b3ad7a64cf0', '2022-01-09 15:21:02', '2022-01-09 15:21:02', NULL, '0:0:0:0:0:0:0:1', '', 'prod', 'seata配置文件', NULL, NULL, 'properties', NULL); /******************************************/ /* 表名称 = config_info_aggr */ diff --git a/sql/ry_seata.sql b/sql/ry_seata.sql index c860d409..2e7e7e42 100644 --- a/sql/ry_seata.sql +++ b/sql/ry_seata.sql @@ -51,15 +51,31 @@ CREATE TABLE IF NOT EXISTS `branch_table` CREATE TABLE IF NOT EXISTS `lock_table` ( `row_key` VARCHAR(128) NOT NULL, - `xid` VARCHAR(96), + `xid` VARCHAR(128), `transaction_id` BIGINT, `branch_id` BIGINT NOT NULL, `resource_id` VARCHAR(256), `table_name` VARCHAR(32), `pk` VARCHAR(36), + `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', `gmt_create` DATETIME, `gmt_modified` DATETIME, PRIMARY KEY (`row_key`), + KEY `idx_status` (`status`), KEY `idx_branch_id` (`branch_id`) ) ENGINE = InnoDB - DEFAULT CHARSET = utf8mb4; \ No newline at end of file + DEFAULT CHARSET = utf8; + +CREATE TABLE IF NOT EXISTS `distributed_lock` +( + `lock_key` CHAR(20) NOT NULL, + `lock_value` VARCHAR(20) NOT NULL, + `expire` BIGINT, + primary key (`lock_key`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);