seata 1.5.2分布式事务之at -凯发k8国际

`

seata 1.5.2分布式事务之at

1.seata-server1.5.2下载
https://seata.io/zh-cn/blog/download.html
在你的mysql数据库中创建名为seata的库
/script/server/db/mysql.sql

2.在你的参与全局事务的数据库中加入undo_log这张表
create table if not exists `undo_log`
(
    `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(6)  not null comment 'create datetime',
    `log_modified`  datetime(6)  not null comment 'modify datetime',
    unique key `ux_undo_log` (`xid`, `branch_id`)
) engine = innodb
  auto_increment = 1
  default charset = utf8 comment ='at transaction mode undo table';

3.在你的项目中引入seata依赖


            io.seata
            seata-spring-boot-starter
           
               
                    com.alibaba
                    druid
               

           

       

       
            com.alibaba.cloud
            spring-cloud-starter-alibaba-seata
           
               
                    io.seata
                    seata-spring-boot-starter
               

           

       


4.application.yml
seata:
   enabled: true
   application-id: orders-service
   tx-service-group: default-tx-group
   config:
      type: nacos
      nacos:
         namespace: 0ef84c31-0570-4591-a708-1945a253048d
         serveraddr: 127.0.0.1:8848
         group: seata_group
         username: "nacos"
         password: "nacos"
         data-id: seataserver.properties
   registry:
      type: nacos
      nacos:
         application: seata-server
         serveraddr: 127.0.0.1:8848
         group: seata_group
         namespace: 0ef84c31-0570-4591-a708-1945a253048d
         username: "nacos"
         password: "nacos"
   data-source-proxy-mode: at

5.运行你下载的nacos,并参考https://github.com/seata/seata/tree/develop/script/config-center 的config.txt并修改

命名空间:seata_group
dataid: service.vgroupmapping.default-tx-group
dataid: seataserver.properties

service.vgroupmapping.default-tx-groupneirong内容:
default

seataserver.propertiesneirong内容如下:
transport.type=tcp
transport.server=nio
transport.heartbeat=true
transport.enabletmclientbatchsendrequest=false
transport.enablermclientbatchsendrequest=true
transport.enabletcserverbatchsendresponse=false
transport.rpcrmrequesttimeout=30000
transport.rpctmrequesttimeout=30000
transport.rpctcrequesttimeout=30000
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
transport.serialization=seata
transport.compressor=none

#transaction routing rules configuration, only for the client
service.vgroupmapping.default-tx-group=default
#if you use a registry, you can ignore it
service.default.grouplist=127.0.0.1:8091
service.enabledegrade=false
service.disableglobaltransaction=false

#transaction rule configuration, only for the client
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=true
client.rm.tablemetacheckerinterval=60000
client.rm.sqlparsertype=druid
client.rm.reportsuccessenable=false
client.rm.sagabranchregisterenable=false
client.rm.sagajsonparser=fastjson
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
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
#for tcc transaction mode
tcc.fence.logtablename=tcc_fence_log
tcc.fence.cleanperiod=1h

#log rule configuration, for client and server
log.exceptionrate=100

#transaction storage configuration, only for the server. the file, db, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#used for password encryption
store.publickey=

#if `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.
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

#these configurations are required if the `store mode` is `db`. if `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.

#连接数据库要修改
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=abc
store.db.password=1000
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

#these configurations are required if the `store mode` is `redis`. if `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.
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

#transaction rule configuration, only for the server
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
server.xaernotaretrytimeout=60000
server.session.branchasyncqueuesize=5000
server.session.enablebranchasyncremove=false
server.enableparallelrequesthandle=false

#metrics configuration, only for the server
metrics.enabled=false
metrics.registrytype=compact
metrics.exporterlist=prometheus
metrics.exporterprometheusport=9898

6.在全局事务调用者(发起全局事务的服务)的接口上加入@globaltransactional
    @requestmapping("/save")
    @globaltransactional(lockretryinternal = 10,lockretrytimes = 30)
    public boolean save(@requestbody orders orders) {
        return ordersservice.save(orders);
    }


7.其它知识:
执行阶段:
- 可回滚:根据 sql 解析结果,记录回滚日志
- 持久化:回滚日志和业务 sql 在同一个本地事务中提交到数据库
完成阶段:
- 分支提交:异步删除回滚日志记录
- 分支回滚:依据回滚日志进行反向补偿更新
其实xa流程相对at模式,是简单许多
at: 解析sql生成undolog 竞争全局锁(rpc)
0
0
分享到:
评论

相关推荐

    基于seata的分布式事务方案at模式demo

    seata 1.5.2

    分布式事务与seata总结精华

    seata 是一款开源的分布式事务凯发k8国际娱乐官网入口的解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务

    项目中集成seata(分布式事务凯发k8国际娱乐官网入口的解决方案)

    1. 在seata 1.4.2 分布式事务at模式示例的基础上增加tcc模式; 2. 目前采用的是at模式和tcc模式混合使用的方式; 3. account模块采用了tcc模式,整合业务代码; 4. product模块采用了tcc模式,未整合业务代码; 5. ...

    资源包含nacos seata 相应的软件和配置 ,包含了demo 工程,以及demo 使用的方式,操作手册 遇到的问题 是学习 研究seata 作为分布式组件好的工具

    计算机课程大作业基于springboot seata实现分布式事务管理系统

    1. 项目idea maven spring-boot spring-cloud spring-cloud-alibaba,依赖nacos 2.0.1, mysql,seata server 1.4.2; 2. 示例包括三个服务,订单服务,商品服务,账户服务; 3. 创建订单的同时,需要扣减商品库存,并...

    此代码为我的seata专栏的配套代码,主要是seata的at模式和tcc模式的基本使用代码。 1. 包含seata-order-8001和seata-stock-8002两个服务 2. 包含两个数据库seata-order和seata-stock对应的表的sql结构和数据 3. ...

    github下载太慢,上传到这里提供下载,方便大家,同时也赚点积分: seata 是一款开源的分布式事务凯发k8国际娱乐官网入口的解决方案,致力于提供高...seata 将为用户提供了 at、tcc、saga 和 xa 事务模式,为用户打造一站式的分布式凯发k8国际娱乐官网入口的解决方案。

    使用阿里seata实现的一个简单的分布式事务的小demo,基于订单,库存,余额的小测试demo,喜欢的可以下载自己测一测!亲测可用

    seata 将为用户提供了 at、tcc、saga 和 xa 事务模式,为用户打造一站式的分布式凯发k8国际娱乐官网入口的解决方案。在 seata 开源之前,seata 对应的内部版本在阿里经济体内部一直扮演着分布式一致性中间件的角色,帮助经济体平稳的度过历年...

    seata分布式事务0.9.0

    1、详细介绍了seata阿里分布式事务中间件; 2、对整个分布式事务凯发k8国际娱乐官网入口的解决方案原理进行了详细的分析,包括tcc、xa、saga等凯发k8国际娱乐官网入口的解决方案 3、it老齐老师视频资料配套pdf;

    分布式事务seata介绍

    shardingsphere-jdbc-nocas-seata用seata分布式事务处理方案分布式事务处理方案,seata分布式事务:项目spring cloud shardingspherejdbc nacos seata分组事务 fegin

    seata分布式事务

    seata分布式事务资料

    seata是一种易于使用,高性能,基于java的开源分布式事务凯发k8国际娱乐官网入口的解决方案

global site tag (gtag.js) - google analytics
网站地图