《分布式事务系列教程-第五章-Seata分布式事务解决方案》

落日映苍穹つ 2022-09-04 13:49 293阅读 0赞

《分布式事务系列教程-第五章-Seata分布式事务解决方案》

一、seata解决方案

Seata是一个开源的分布式事务解决方案,是由阿里中间件团队研发的,原名Fescar,后更名为seata,seata致力于提供高性能和易于使用的分布式事务服务。Seata将为用户提供AT,TCC,SAGA和XA交易模型,以为用户创建一站式分布式解决方案。

  • seata官网:http://seata.io
  • github地址:https://github.com/seata/seata

seata也是基于2PC的一种分布式解决方案,对传统的2PC基础上进行了一些优化,通过引入事务协调器(TC)来监控各个分支事务的执行状态来判断全局事务是否提交或回滚,引入日志表来替代锁表问题。

  • 阶段1:在同一本地事务中提交业务数据并且记录日志到undo表,然后释放本地锁和连接资源。
  • 阶段2:

    • 对于提交情况,异步快速地完成工作。
    • 对于回滚情况,请根据阶段1中创建的日志数据进行补偿。

1.1 seata执行流程:

1)当RM启动时,首先注册到TC中。

2)TM向TC申请开启全局事务,全局事务开启后生成用于标识此次全局事务的id(XID)。每个全局事务ID各不相同。

4)首先第一个RM向TC开启分支事务,当进行微服务调用时,XID也会随之传递下来,此时的RM事务已经真正提交

5)最终TM根据各分支事务执行情况,来请求TC提交或者回滚全局事务

6)TC根据XID对应的全局事务下的分支事务来提交或回滚。

在这里插入图片描述

TM和全局事务的发起方在一起;

1.2 搭建seata工程

1.2.1 启动seata协调器

启动事务协调器TC

  1. seata-server.bat -p 10101 -m file
  • -p:指定启动的端口
  • -m:指定启动的模式,file代表以文件方式存储信息

在这里插入图片描述

1.2.2 搭建父工程

  • pom.xml:

    <?xml version=”1.0” encoding=”UTF-8”?>


    4.0.0

    com.lscl
    seata_transaction
    pom
    1.0-SNAPSHOT

    eureka_server
    store
    orders



    2.1.0.RELEASE






    commons-lang
    commons-lang
    2.6



    com.alibaba
    druid-spring-boot-starter
    1.1.16



    com.alibaba.cloud
    spring-cloud-alibaba-dependencies
    2.1.0.RELEASE
    pom
    import


    org.springframework.boot
    spring-boot-dependencies
    2.1.3.RELEASE
    pom
    import



    org.springframework.cloud
    spring-cloud-dependencies
    Greenwich.RELEASE
    pom
    import




1.2.3 搭建EurekaServer

  • 1)pom.xml:

    <?xml version=”1.0” encoding=”UTF-8”?>



    seata_transaction
    com.lscl
    1.0-SNAPSHOT

    4.0.0

    eureka_server



    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-server



    org.springframework.boot
    spring-boot-starter



  • 2)Application.yml

    server:
    port: 10102
    eureka:
    client:

    1. register-with-eureka: false # 是否将该服务注册到eureka服务端
    2. fetch-registry: false # 是否从eureka服务端获取其他服务实例
    3. service-url: # eureka的注册地址
    4. defaultZone: http://127.0.0.1:${ server.port}/eureka
  • 3)启动类

    package com.lscl.eureka;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

    @SpringBootApplication
    @EnableEurekaServer // 开启eureka服务器
    public class EurekaApplication {

    1. public static void main(String[] args) {
    2. SpringApplication.run(EurekaApplication.class);
    3. }

    }

1.2.4 搭建库存微服

1)pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <parent>
  4. <artifactId>seata_transaction</artifactId>
  5. <groupId>com.lscl</groupId>
  6. <version>1.0-SNAPSHOT</version>
  7. </parent>
  8. <modelVersion>4.0.0</modelVersion>
  9. <artifactId>store</artifactId>
  10. <dependencies>
  11. <dependency>
  12. <groupId>com.alibaba.cloud</groupId>
  13. <artifactId>spring-cloud-alibaba-seata</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-data-jpa</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework.cloud</groupId>
  21. <artifactId>spring-cloud-starter-openfeign</artifactId>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.cloud</groupId>
  25. <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.cloud</groupId>
  29. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.springframework.boot</groupId>
  33. <artifactId>spring-boot-starter-web</artifactId>
  34. </dependency>
  35. <dependency>
  36. <groupId>mysql</groupId>
  37. <artifactId>mysql-connector-java</artifactId>
  38. <version>5.1.47</version>
  39. </dependency>
  40. </dependencies>
  41. </project>

2)registry.conf:

  1. registry {
  2. # file 、redis、zookeeper、eureka、nacos 、consul、etcd3、sofa
  3. type = "file"
  4. file {
  5. name = "file.conf"
  6. }
  7. }
  8. config {
  9. # file、nacos 、apollo、zk
  10. type = "file"
  11. file {
  12. name = "file.conf"
  13. }
  14. }

3)file.conf:

  1. transport {
  2. # tcp udt unix-domain-socket
  3. type = "TCP"
  4. #NIO NATIVE
  5. server = "NIO"
  6. #enable heartbeat
  7. heartbeat = true
  8. #thread factory for netty
  9. thread-factory {
  10. boss-thread-prefix = "NettyBoss"
  11. worker-thread-prefix = "NettyServerNIOWorker"
  12. server-executor-thread-prefix = "NettyServerBizHandler"
  13. share-boss-worker = false
  14. client-selector-thread-prefix = "NettyClientSelector"
  15. client-selector-thread-size = 1
  16. client-worker-thread-prefix = "NettyClientWorkerThread"
  17. # netty boss thread size,will not be used for UDT
  18. boss-thread-size = 1
  19. #auto default pin or 8
  20. worker-thread-size = 8
  21. }
  22. }
  23. ## transaction log store
  24. store {
  25. ## store mode: file、db
  26. mode = "file"
  27. ## file store
  28. file {
  29. dir = "sessionStore"
  30. # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
  31. max-branch-session-size = 16384
  32. # globe session size , if exceeded throws exceptions
  33. max-global-session-size = 512
  34. # file buffer size , if exceeded allocate new buffer
  35. file-write-buffer-cache-size = 16384
  36. # when recover batch read size
  37. session.reload.read_size = 100
  38. # async, sync
  39. flush-disk-mode = async
  40. }
  41. }
  42. service {
  43. #vgroup->rgroup
  44. vgroup_mapping.orders-fescar-service-group = "default" # 微服名称
  45. #only support single node
  46. default.grouplist = "127.0.0.1:10101" # seata
  47. #degrade current not support
  48. enableDegrade = false
  49. #disable
  50. disable = false
  51. }
  52. client {
  53. async.commit.buffer.limit = 10000
  54. lock {
  55. retry.internal = 10
  56. retry.times = 30
  57. }
  58. }

4)application.xml:

  1. server:
  2. port: 10104
  3. servlet:
  4. context-path: /store
  5. spring:
  6. application:
  7. name: store #指定服务名
  8. datasource:
  9. driverClassName: com.mysql.jdbc.Driver
  10. url: jdbc:mysql://localhost:3306/store?serverTimezone=GMT%2b8
  11. username: root
  12. password: admin
  13. jpa:
  14. properties:
  15. hibernate:
  16. format_sql: true # 格式化sql
  17. show_sql: true # 显示sql
  18. eureka:
  19. client:
  20. service-url:
  21. defaultZone: http://127.0.0.1:10102/eureka

5)启动类:

  1. package com.lscl.store;
  2. import com.alibaba.druid.pool.DruidDataSource;
  3. import io.seata.rm.datasource.DataSourceProxy;
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6. import org.springframework.boot.context.properties.ConfigurationProperties;
  7. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  8. import org.springframework.context.ApplicationContext;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Primary;
  11. import javax.sql.DataSource;
  12. @EnableEurekaClient
  13. @SpringBootApplication
  14. public class StoreApplication {
  15. public static void main(String[] args) {
  16. SpringApplication.run(StoreApplication.class);
  17. }
  18. private final ApplicationContext applicationContext;
  19. public StoreApplication(ApplicationContext applicationContext) {
  20. this.applicationContext = applicationContext;
  21. }
  22. @Bean
  23. @ConfigurationProperties(prefix = "spring.datasource")
  24. public DruidDataSource druidDataSource() {
  25. DruidDataSource druidDataSource = new DruidDataSource();
  26. return druidDataSource;
  27. }
  28. @Primary
  29. @Bean // 代理数据源
  30. public DataSource dataSource(DruidDataSource dataSource) {
  31. DataSourceProxy proxyDS = new DataSourceProxy(dataSource);
  32. return proxyDS;
  33. }
  34. }

6)entity.java:

  1. package com.lscl.store.entity;
  2. import javax.persistence.Entity;
  3. import javax.persistence.Id;
  4. import javax.persistence.Table;
  5. import java.io.Serializable;
  6. @Entity
  7. @Table(name = "t_store")
  8. public class Store implements Serializable {
  9. @Id
  10. private String id;
  11. private Integer count;
  12. public String getId() {
  13. return id;
  14. }
  15. public void setId(String id) {
  16. this.id = id;
  17. }
  18. public Integer getCount() {
  19. return count;
  20. }
  21. public void setCount(Integer count) {
  22. this.count = count;
  23. }
  24. }

7)dao.java:

  1. package com.lscl.store.dao;
  2. import com.lscl.store.entity.Store;
  3. import org.springframework.data.jpa.repository.JpaRepository;
  4. import org.springframework.data.jpa.repository.Modifying;
  5. import org.springframework.data.jpa.repository.Query;
  6. import org.springframework.stereotype.Repository;
  7. @Repository
  8. public interface StoreDao extends JpaRepository<Store,String> {
  9. @Query("update Store s set s.count=s.count-1")
  10. @Modifying
  11. void updateCount();
  12. }

8)service.java:

  1. package com.lscl.store.service;
  2. import com.lscl.store.dao.StoreDao;
  3. import io.seata.core.context.RootContext;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. @Service
  8. public class StoreService {
  9. @Autowired
  10. private StoreDao storeDao;
  11. @Transactional
  12. public void updateCount(Integer flag) {
  13. System.out.println("orders_xid: "+ RootContext.getXID());
  14. // 库存-1
  15. storeDao.updateCount();
  16. if(flag==200){ // 模拟异常
  17. throw new RuntimeException("store...error");
  18. }
  19. }
  20. }

9)controller.java:

  1. package com.lscl.store.controller;
  2. import com.lscl.store.service.StoreService;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.web.bind.annotation.PathVariable;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. @RestController
  8. public class StoreController {
  9. @Autowired
  10. private StoreService storeService;
  11. @RequestMapping("/updateCount/{flag}")
  12. public String updateCount(@PathVariable Integer flag){
  13. storeService.updateCount(flag);
  14. return "store...success";
  15. }
  16. }

1.2.5 搭建订单微服

1)pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <parent>
  4. <artifactId>seata_transaction</artifactId>
  5. <groupId>com.lscl</groupId>
  6. <version>1.0-SNAPSHOT</version>
  7. </parent>
  8. <modelVersion>4.0.0</modelVersion>
  9. <artifactId>orders</artifactId>
  10. <dependencies>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-web</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>com.alibaba.cloud</groupId>
  17. <artifactId>spring-cloud-alibaba-seata</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-data-jpa</artifactId>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.cloud</groupId>
  25. <artifactId>spring-cloud-starter-openfeign</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.cloud</groupId>
  29. <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.springframework.cloud</groupId>
  33. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  34. </dependency>
  35. <dependency>
  36. <groupId>mysql</groupId>
  37. <artifactId>mysql-connector-java</artifactId>
  38. <version>5.1.47</version>
  39. </dependency>
  40. </dependencies>
  41. </project>

2)registry.conf:

  1. registry {
  2. # file 、redis、zookeeper、eureka、nacos 、consul、etcd3、sofa
  3. type = "file"
  4. file {
  5. name = "file.conf"
  6. }
  7. }
  8. config {
  9. # file、nacos 、apollo、zk
  10. type = "file"
  11. file {
  12. name = "file.conf"
  13. }
  14. }

3)file.conf:

  1. transport {
  2. # tcp udt unix-domain-socket
  3. type = "TCP"
  4. #NIO NATIVE
  5. server = "NIO"
  6. #enable heartbeat
  7. heartbeat = true
  8. #thread factory for netty
  9. thread-factory {
  10. boss-thread-prefix = "NettyBoss"
  11. worker-thread-prefix = "NettyServerNIOWorker"
  12. server-executor-thread-prefix = "NettyServerBizHandler"
  13. share-boss-worker = false
  14. client-selector-thread-prefix = "NettyClientSelector"
  15. client-selector-thread-size = 1
  16. client-worker-thread-prefix = "NettyClientWorkerThread"
  17. # netty boss thread size,will not be used for UDT
  18. boss-thread-size = 1
  19. #auto default pin or 8
  20. worker-thread-size = 8
  21. }
  22. }
  23. ## transaction log store
  24. store {
  25. ## store mode: file、db
  26. mode = "file"
  27. ## file store
  28. file {
  29. dir = "sessionStore"
  30. # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
  31. max-branch-session-size = 16384
  32. # globe session size , if exceeded throws exceptions
  33. max-global-session-size = 512
  34. # file buffer size , if exceeded allocate new buffer
  35. file-write-buffer-cache-size = 16384
  36. # when recover batch read size
  37. session.reload.read_size = 100
  38. # async, sync
  39. flush-disk-mode = async
  40. }
  41. }
  42. service {
  43. #vgroup->rgroup
  44. vgroup_mapping.store-fescar-service-group = "default"
  45. #only support single node
  46. default.grouplist = "127.0.0.1:10101"
  47. #degrade current not support
  48. enableDegrade = false
  49. #disable
  50. disable = false
  51. }
  52. client {
  53. async.commit.buffer.limit = 10000
  54. lock {
  55. retry.internal = 10
  56. retry.times = 30
  57. }
  58. }

4)application.yml:

  1. server:
  2. port: 10103
  3. servlet:
  4. context-path: /orders
  5. spring:
  6. application:
  7. name: orders #指定服务名
  8. datasource:
  9. driverClassName: com.mysql.jdbc.Driver
  10. url: jdbc:mysql://localhost:3306/orders?serverTimezone=GMT%2b8
  11. username: root
  12. password: admin
  13. jpa:
  14. properties:
  15. hibernate:
  16. format_sql: true # 格式化sql
  17. show_sql: true # 显示sql
  18. eureka:
  19. client:
  20. service-url:
  21. defaultZone: http://127.0.0.1:10102/eureka
  22. feign: # 开启熔断器
  23. hystrix:
  24. enabled: true

5)启动类:

  1. package com.lscl.orders;
  2. import com.alibaba.druid.pool.DruidDataSource;
  3. import io.seata.rm.datasource.DataSourceProxy;
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6. import org.springframework.boot.context.properties.ConfigurationProperties;
  7. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  8. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  9. import org.springframework.cloud.openfeign.EnableFeignClients;
  10. import org.springframework.context.ApplicationContext;
  11. import org.springframework.context.annotation.Bean;
  12. import org.springframework.context.annotation.Primary;
  13. @EnableEurekaClient
  14. @EnableDiscoveryClient
  15. @EnableFeignClients
  16. @SpringBootApplication
  17. public class OrdersApplication {
  18. public static void main(String[] args) {
  19. SpringApplication.run(OrdersApplication.class);
  20. }
  21. private final ApplicationContext applicationContext;
  22. public OrdersApplication(ApplicationContext applicationContext) {
  23. this.applicationContext = applicationContext;
  24. }
  25. @Bean
  26. @ConfigurationProperties(prefix = "spring.datasource")
  27. public DruidDataSource druidDataSource() {
  28. DruidDataSource druidDataSource = new DruidDataSource();
  29. return druidDataSource;
  30. }
  31. @Primary
  32. @Bean // 代理数据源
  33. public DataSourceProxy dataSource(DruidDataSource dataSource) {
  34. DataSourceProxy proxyDS = new DataSourceProxy(dataSource);
  35. return proxyDS;
  36. }
  37. }

6)Client:

  1. package com.lscl.orders.client;
  2. import com.lscl.orders.client.impl.StoreClientImpl;
  3. import org.springframework.cloud.openfeign.FeignClient;
  4. import org.springframework.web.bind.annotation.PathVariable;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. @FeignClient(value = "store",fallback = StoreClientImpl.class)
  7. public interface StoreClient {
  8. @RequestMapping("/store/updateCount/{flag}")
  9. public String updateCount(@PathVariable("flag") Integer flag);
  10. }

7)ClientImpl:

  1. package com.lscl.orders.client.impl;
  2. import com.lscl.orders.client.StoreClient;
  3. import org.springframework.stereotype.Component;
  4. @Component
  5. public class StoreClientImpl implements StoreClient {
  6. @Override
  7. public String updateCount(Integer flag) {
  8. return "no";
  9. }
  10. }

8)entity:

  1. package com.lscl.orders.entity;
  2. import javax.persistence.Entity;
  3. import javax.persistence.Id;
  4. import javax.persistence.Table;
  5. import java.io.Serializable;
  6. @Entity
  7. @Table(name = "t_orders")
  8. public class Orders implements Serializable {
  9. @Id
  10. private String id;
  11. private Integer count;
  12. public String getId() {
  13. return id;
  14. }
  15. public void setId(String id) {
  16. this.id = id;
  17. }
  18. public Integer getCount() {
  19. return count;
  20. }
  21. public void setCount(Integer count) {
  22. this.count = count;
  23. }
  24. }

9)dao:

  1. package com.lscl.orders.dao;
  2. import com.lscl.orders.entity.Orders;
  3. import org.springframework.data.jpa.repository.JpaRepository;
  4. import org.springframework.data.jpa.repository.Modifying;
  5. import org.springframework.data.jpa.repository.Query;
  6. import org.springframework.stereotype.Repository;
  7. @Repository
  8. public interface OrdersDao extends JpaRepository<Orders,String> {
  9. @Query("update Orders o set o.count=o.count+1")
  10. @Modifying
  11. void updateCount();
  12. }

10)service:

  1. package com.lscl.orders.service;
  2. import com.lscl.orders.client.StoreClient;
  3. import com.lscl.orders.dao.OrdersDao;
  4. import io.seata.core.context.RootContext;
  5. import io.seata.spring.annotation.GlobalTransactional;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. @Service
  10. public class OrdersService {
  11. @Autowired
  12. private OrdersDao ordersDao;
  13. @Autowired
  14. private StoreClient storeClient;
  15. @Transactional
  16. @GlobalTransactional // 开启全局事务
  17. public void updateCount(Integer flag) {
  18. System.out.println("orders_xid: "+RootContext.getXID());
  19. // 订单+1
  20. ordersDao.updateCount();
  21. // 库存-1
  22. String msg = storeClient.updateCount(flag);
  23. if("no".equals(msg)){
  24. throw new RuntimeException("store...error");
  25. }
  26. System.out.println(msg);
  27. if (flag == 100) {
  28. throw new RuntimeException("orders...error");
  29. }
  30. }
  31. }

11)controller:

  1. package com.lscl.orders.controller;
  2. import com.lscl.orders.service.OrdersService;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.web.bind.annotation.PathVariable;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. @RestController
  8. public class OrdersController {
  9. @Autowired
  10. private OrdersService ordersService;
  11. @RequestMapping("/updateCount/{flag}")
  12. public String updateCount(@PathVariable Integer flag){
  13. ordersService.updateCount(flag);
  14. return "orders...success";
  15. }
  16. }

1.2.5 创建undo_log表

根据2PC协议,我们知道在第一阶段时,执行完业务sql之后,会把前后镜像数据以及业务 SQL 相关的信息组成一条回滚日志记录,插入到 UNDO_LOG 表中

在第二阶段时如果是回滚则根据 UNDO LOG 中的前镜像和业务 SQL 的相关信息生成并执行回滚的语句

如果是提交则分支提交请求将异步和批量地删除相应 UNDO LOG 记录。

在订单、库存两个数据库中分别创建对应的undo_log日志表。

  1. CREATE TABLE `undo_log` (
  2. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  3. `branch_id` bigint(20) NOT NULL,
  4. `xid` varchar(100) NOT NULL,
  5. `context` varchar(128) NOT NULL,
  6. `rollback_info` longblob NOT NULL,
  7. `log_status` int(11) NOT NULL,
  8. `log_created` datetime NOT NULL,
  9. `log_modified` datetime NOT NULL,
  10. PRIMARY KEY (`id`),
  11. UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
  12. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

全部RM执行成功流程:

在这里插入图片描述

某个RM执行失败流程:

在这里插入图片描述

1.3 总结

seata也是基于2PC的一种分布式解决方案。seata方案解决了XA方案在准备阶段时,RM锁的问题。在高并发情况下,应当避免XA方案。

xa方案依赖于数据库对XA协议的支持,seata则是通过业务逻辑的处理(记录undo_log表),来达到数据的回滚,底层不依赖于数据库。

发表评论

表情:
评论列表 (有 0 条评论,293人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Seata--分布式事务

    1、Seata 分布式事务基础 1.1事务 事务指的就是一个操作单元,在这个操作单元中的所有操作最终要保持一致的行为,要么所有操作都成功,要么所有的操作都被撤销。简