解决分布式事务,Seata真香!

年IT寒冬,大厂都裁员或者准备裁员,作为开猿节流主要目标之一,我们更应该时刻保持竞争力。为了抱团取暖,林老师开通了知识星球,并邀请我阿里、快手、腾讯等的朋友加入,分享八股文、项目经验、管理经验等,帮助大家提升技能,安稳度过这个寒冬,快加入我们吧!

星球地址

一、分布式事务基本概念

在开始介绍Seata分布式框架之前,我们先来了解一下,什么是分布式事务?

在传统的单体应用中,事务是由单个数据库管理的,一个事务中的所有操作要么全部成功,要么全部失败。但是,在分布式系统中,一个事务可能涉及多个数据库,这些数据库可能位于不同的服务器上。因此,需要一种机制来协调这些数据库之间的事务。

分布式事务是指一个事务中的操作分布在多个节点上,需要保证这些操作要么全部成功,要么全部失败。在分布式事务中,有几个基本概念:

  1. 事务管理器(Transaction Manager):负责管理事务的整个生命周期,包括事务的开始、提交和回滚。
  2. 资源管理器(Resource Manager):负责管理本地资源(如数据库),并与事务管理器进行交互。
  3. 参与者(Participant):参与到分布式事务中的节点。
  4. 事务(Transaction):一个事务是由一个或多个操作组成的逻辑单元。
  5. 分支(Branch):一个事务中的每个操作都被称为一个分支。
  6. 全局事务(Global Transaction):一个包含多个分支的事务被称为全局事务。

二、Seata 是什么

Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案。

  1. AT 模式(Auto Commit Transaction):是一种基于两阶段提交协议的自动事务提交模式。在这种模式下,Seata 框架会自动管理事务的提交和回滚过程,以确保数据的一致性。
  2. TCC 模式(Try-Confirm-Cancel):是一种基于补偿机制的事务处理模式。在这种模式下,事务中的每个操作都被拆分成了 try、confirm 和 cancel 三个阶段。如果所有的 try 操作都成功了,那么事务就会被提交;否则,事务就会被回滚。
  3. SAGA 模式(Long Running Transaction):是一种基于事件驱动的事务处理模式。在这种模式下,事务中的每个操作都是一个独立的事务,它们之间通过事件进行协调。如果一个操作失败了,那么它会发送一个补偿事件来撤销之前的操作。
  4. XA 模式(eXtended Architecture):是一种基于 XA 协议的分布式事务处理模式。在这种模式下,事务中的每个操作都需要与事务管理器进行交互,以确保数据的一致性。

官方4大模式解释:https://seata.apache.org/zh-cn/docs/user/mode/at

从Seata的使用角度来说,AT模式和XA模式,在用法上面是一样的,只是说数据库配置不一样而已。

三、Seata服务器

Seata分布式事务的实现,可以分为client和serve两大部分。client就是每个业务服务本身,只需要引入Seata相关的依赖即可,serve是一个独立运行的服务,需要我们独立部署,独立于业务之外。下面给大家介绍如何基于Nacos作为配置中心和注册中心,来使用Seata框架。

3.1 Nacos安装和配置

首先下载安装Nacos安装包,教程可以参照:Window环境下Nacos安装教程

在Configuration Management模块中配置Seata所需要用到的配置,如下所示:

#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
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=falseclient.metadataMaxAgeMs=30000
#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.rm.sqlParserType=druid
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
# You can choose from the following options: fastjson, jackson, gson
tcc.contextJsonParserType=fastjson#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?rewriteBatchedStatements=true&useSSL=false
store.db.user=seata
store.db.password=seata
store.db.minConn=5
store.db.maxConn=10
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.type=pipeline
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.sentinel.sentinelPassword=
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.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=true
server.enableParallelHandleBranch=falseserver.raft.cluster=127.0.0.1:7091,127.0.0.1:7092,127.0.0.1:7093
server.raft.snapshotInterval=600
server.raft.applyBatch=32
server.raft.maxAppendBufferSize=262144
server.raft.maxReplicatorInflightMsgs=256
server.raft.disruptorBufferSize=16384
server.raft.electionTimeoutMs=2000
server.raft.reporterEnabled=false
server.raft.reporterInitialDelay=60
server.raft.serialization=jackson
server.raft.compressor=none
server.raft.sync=true#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

上述文件来自seata\seata-server-2.0.0\seata\script\config-center\config.txt,我们也可以通过Linux脚本或者Python脚本,将配置自动同步Nacos中,也可以我们自己手动复制上去。

主要事项:其中store.db.url部分需要修改为自己的数据库地址,否则Seata启动过程中会造成连接数据库失败。

3.2 初始化store.db脚本

如果想要Seata进行存储共享,需要将store.mode=db,默认是file,也就是本地文件存储,这种模式是无法进行数据共享的,脚本如下所示:

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(`xid`                       VARCHAR(128) NOT NULL,`transaction_id`            BIGINT,`status`                    TINYINT      NOT NULL,`application_id`            VARCHAR(32),`transaction_service_group` VARCHAR(32),`transaction_name`          VARCHAR(128),`timeout`                   INT,`begin_time`                BIGINT,`application_data`          VARCHAR(2000),`gmt_create`                DATETIME,`gmt_modified`              DATETIME,PRIMARY KEY (`xid`),KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDBDEFAULT CHARSET = utf8mb4;-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(`branch_id`         BIGINT       NOT NULL,`xid`               VARCHAR(128) NOT NULL,`transaction_id`    BIGINT,`resource_group_id` VARCHAR(32),`resource_id`       VARCHAR(256),`branch_type`       VARCHAR(8),`status`            TINYINT,`client_id`         VARCHAR(64),`application_data`  VARCHAR(2000),`gmt_create`        DATETIME(6),`gmt_modified`      DATETIME(6),PRIMARY KEY (`branch_id`),KEY `idx_xid` (`xid`)
) ENGINE = InnoDBDEFAULT CHARSET = utf8mb4;-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(`row_key`        VARCHAR(128) NOT NULL,`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`),KEY `idx_xid` (`xid`)
) ENGINE = InnoDBDEFAULT CHARSET = utf8mb4;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 = InnoDBDEFAULT 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);

3.3 修改application.yml配置

修改\seata\seata-server-2.0.0\seata\confapplication.yml配置,将注册中心和配置中心修改为Nacos地址。

#  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.server:port: 7091spring:application:name: seata-serverlogging:config: classpath:logback-spring.xmlfile:path: ${log.home:${user.home}/logs/seata}extend:logstash-appender:destination: 127.0.0.1:4560kafka-appender:bootstrap-servers: 127.0.0.1:9092topic: logback_to_logstashconsole:user:username: seatapassword: seata
seata:config:# support: nacos, consul, apollo, zk, etcd3type: "nacos"nacos:server-addr: "127.0.0.1:8848"namespace: ""group: "SEATA_GROUP"username: "nacos"password: "nacos"# context-path: /nacos##if use MSE Nacos with auth, mutex with username/password attribute# access-key:# secret-key:data-id: "seataServer.properties"registry:# support: nacos, eureka, redis, zk, consul, etcd3, sofatype: "nacos"nacos:application: "seata-server"server-addr: "127.0.0.1:8848"namespace: ""group: "SEATA_GROUP"cluster: "default"username: "nacos"password: "nacos"# context-path: /nacossecurity:secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017tokenValidityInMilliseconds: 1800000ignore:urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**

上述Nacos地址需要修改为自己的地址,否则会拉取不到配置,导致启动失败。

3.4 启动Seata服务

如果是window环境,只需要双击seata-server.bat文件,即可启动Seata服务。

地址:http://127.0.0.1:7091/#/transaction/list

账号:seata

密码:seata

Seata服务启动成功之后,可以进入Seata控制台,查看当前正在执行的事务和全局锁信息,如果当前没有服务在运行,那列表就是空的。

最后我们可以进入Nacos控制台,查看在线服务列表,如果可以看到如上所示的服务信息,就说明Seata服务已经成功注册到Nacos上面了。

四、基于nacos实现分布式事务步骤

Seata使用教程我们可以去官网中查看,例如: https://seata.apache.org/zh-cn/docs/user/quickstart
但是我推荐大家还是基于GitHub上面的demo项目来探索Seata的用法,因为官网的教程不是很详细,GitHub地址: https://github.com/apache/incubator-seata-samples

下面来给大家介绍以下使用Nacos作为注册中心和配置中心,来实现Seata分布式事务的详细步骤。

4.1 找到springcloud-nacos-seata项目

在incubator-seata-samples父项目中,找到springcloud-nacos-seata的子项目,如下图所示:

4.2 修改项目配置

在application.properties中,将spring.cloud.nacos.discovery.server-addr修改为我们自己的Nacos地址,将spring.datasource.url修改为我们自己的数据库地址。

spring.application.name=order-service
server.port=9091
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group
logging.level.io.seata=debug
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/seata_order?allowMultiQueries=true&useSSL=false
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.username=seata
spring.datasource.password=seataspring.application.name=stock-service
server.port=9092
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group
logging.level.io.seata=debug
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/seata_stock?allowMultiQueries=true&useSSL=false
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.username=seata
spring.datasource.password=seata

在registry.conf中,将配置中心和注册中心的Nacos地址更新为自己的地址。

registry {# file 、nacos 、eureka、redis、zk、consul、etcd3、sofatype = "nacos"nacos {# order和stock中application名称需要进行区分,不然注册过去的应用名称就重复了。application = "seata-server-order"serverAddr = "127.0.0.1:8848"group = "SEATA_GROUP"namespace = ""cluster = "default"username = "nacos"password = "nacos"}eureka {serviceUrl = "http://localhost:8761/eureka"application = "default"weight = "1"}redis {serverAddr = "localhost:6379"db = 0password = ""cluster = "default"timeout = 0}zk {cluster = "default"serverAddr = "127.0.0.1:2181"sessionTimeout = 6000connectTimeout = 2000username = ""password = ""}consul {cluster = "default"serverAddr = "127.0.0.1:8500"}etcd3 {cluster = "default"serverAddr = "http://localhost:2379"}sofa {serverAddr = "127.0.0.1:9603"application = "default"region = "DEFAULT_ZONE"datacenter = "DefaultDataCenter"cluster = "default"group = "SEATA_GROUP"addressWaitTime = "3000"}file {name = "file.conf"}
}config {# file、nacos 、apollo、zk、consul、etcd3type = "nacos"nacos {serverAddr = "127.0.0.1:8848"namespace = ""group = "SEATA_GROUP"username = "nacos"password = "nacos"dataId = "seataServer.properties"}consul {serverAddr = "127.0.0.1:8500"}apollo {appId = "seata-server"apolloMeta = "http://192.168.1.204:8801"namespace = "application"}zk {serverAddr = "127.0.0.1:2181"sessionTimeout = 6000connectTimeout = 2000username = ""password = ""}etcd3 {serverAddr = "http://localhost:2379"}file {name = "file.conf"}
}
注意springcloud-nacos-seata含有order和stock两个项目模块,两个模块的application.properties和registry.conf都需要修改。

4.3 初始化order和stock的db脚本

-- 创建 order库、业务表、undo_log表
create database seata_order;
use seata_order;DROP TABLE IF EXISTS `order_tbl`;
CREATE TABLE `order_tbl` (`id` int(11) NOT NULL AUTO_INCREMENT,`user_id` varchar(255) DEFAULT NULL,`commodity_code` varchar(255) DEFAULT NULL,`count` int(11) DEFAULT 0,`money` int(11) DEFAULT 0,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE `undo_log`
(`id`            BIGINT(20)   NOT NULL AUTO_INCREMENT,`branch_id`     BIGINT(20)   NOT NULL,`xid`           VARCHAR(100) NOT NULL,`context`       VARCHAR(128) NOT NULL,`rollback_info` LONGBLOB     NOT NULL,`log_status`    INT(11)      NOT NULL,`log_created`   DATETIME     NOT NULL,`log_modified`  DATETIME     NOT NULL,`ext`           VARCHAR(100) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDBAUTO_INCREMENT = 1DEFAULT CHARSET = utf8;-- 创建 stock库、业务表、undo_log表
create database seata_stock;
use seata_stock;DROP TABLE IF EXISTS `stock_tbl`;
CREATE TABLE `stock_tbl` (`id` int(11) NOT NULL AUTO_INCREMENT,`commodity_code` varchar(255) DEFAULT NULL,`count` int(11) DEFAULT 0,PRIMARY KEY (`id`),UNIQUE KEY (`commodity_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE `undo_log`
(`id`            BIGINT(20)   NOT NULL AUTO_INCREMENT,`branch_id`     BIGINT(20)   NOT NULL,`xid`           VARCHAR(100) NOT NULL,`context`       VARCHAR(128) NOT NULL,`rollback_info` LONGBLOB     NOT NULL,`log_status`    INT(11)      NOT NULL,`log_created`   DATETIME     NOT NULL,`log_modified`  DATETIME     NOT NULL,`ext`           VARCHAR(100) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDBAUTO_INCREMENT = 1DEFAULT CHARSET = utf8;-- 初始化库存模拟数据
INSERT INTO seata_stock.stock_tbl (id, commodity_code, count) VALUES (1, 'product-1', 9999999);
INSERT INTO seata_stock.stock_tbl (id, commodity_code, count) VALUES (2, 'product-2', 0);
脚本的位置在README.md文件中,官网demo并没有将DDL单独独立一份文件出来,所以脚本的位置需要注意一下。

4.4 调用接口验证分布式事务

分别启动order和stock服务,如下所示就代表启动成功了。

确定Nacos服务列表中包含启动成功的order和stock两个服务,如下所示:

调用http://127.0.0.1:9091/order/placeOrder/commit接口,该接口会先扣减库存,然后再创建订单,但是创建订单后会抛出一个异常,如果分布式事务执行成功,应该是库存没扣减成功,订单也没有创建成功,所以现在我们来验证一下是不是这样子。

order服务代码:

@RequestMapping("/placeOrder/commit")
public Boolean placeOrderCommit() {orderService.placeOrder("1", "product-1", 1);return true;
}@GlobalTransactional
@Transactional(rollbackFor = Exception.class)
public void placeOrder(String userId, String commodityCode, Integer count) {stockFeignClient.deduct(commodityCode, count);BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));Order order = new Order().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney(orderMoney);orderDAO.insert(order);if (commodityCode.equals("product-1")) {throw new RuntimeException("异常:模拟业务异常:stock branch exception");}
}

stock服务代码:

@RequestMapping(path = "/deduct")
public Boolean deduct(String commodityCode, Integer count) {stockService.deduct(commodityCode, count);return true;
}/** * 减库存 * * @param commodityCode * @param count */
@Transactional(rollbackFor = Exception.class)
public void deduct(String commodityCode, int count) {QueryWrapper<Stock> wrapper = new QueryWrapper<>();wrapper.setEntity(new Stock().setCommodityCode(commodityCode));Stock stock = stockDAO.selectOne(wrapper);stock.setCount(stock.getCount() - count);stockDAO.updateById(stock);
}

在开始执行接口之前,我们来看一下stock_tbl和order_tbl的数据,如下所示我们可以得到product-1产品的库存为9999999,order_tbl表数据为空。

利用postman来执行order/placeOrder/commit接口,可以看到返回值是500,如下所示:

执行接口后,我们重新刷新一下stock_tbl和order_tbl表,发现库表数据没有发生任何变动,说明分布式事务生效了,stock_tbl和order_tbl的数据都成功回滚了。

如果要从0创建seata的客户端,可以将demo中的pom相关依赖引用进去即可,其它的步骤和上述差不多。

五、总结

Seata 是一种强大而简单的分布式事务解决方案,它提供了一种高性能、易于使用和可扩展的方式来管理分布式事务。通过使用 Seata,你可以轻松地实现分布式事务,确保数据的一致性和可靠性。

但是Seata也有它的局限性,如果非分布式事务中,MySQL事务默认隔离机制是REPEATABLE-READ,但是Seata的隔离级别是Read Uncommitted,如果对数据非常敏感的系统,要注意因为分布式事务造成的数据问题。
林老师带你学编程 知识星球,创始人由工作 10年以上的一线大厂人员组成,希望通过我们的分享,帮助大家少走弯路,可以在技术领域不断突破和发展。

具体的加入方式

  • 直接访问链接:https://t.zsxq.com/14F2uGap7

星球内容涵盖:Java技术栈、Python、大数据、项目实战、面试指导等主题。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2871402.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

Java八股文(MyBatis Plus)

Java八股文のMyBatis Plus MyBatis Plus MyBatis Plus MyBatis Plus 是什么&#xff1f;它与 MyBatis 有什么区别&#xff1f; MyBatis Plus 是基于 MyBatis 进行扩展的一款持久层框架&#xff0c;它提供了一系列增强功能&#xff0c;简化了 MyBatis 的使用。 与 MyBatis 相比…

zookeeper快速入门四:在java客户端中操作zookeeper

系列文章&#xff1a; zookeeper快速入门一&#xff1a;zookeeper安装与启动-CSDN博客 zookeeper快速入门二&#xff1a;zookeeper基本概念-CSDN博客 zookeeper快速入门三&#xff1a;zookeeper的基本操作 先启动zookeeper服务端。 在maven引入zookeeper依赖。 <depende…

Acwing-基础算法课笔记之动态规划(计数类DP)

Acwing-基础算法课笔记之动态规划&#xff08;计数类DP&#xff09; 一、整数划分1、定义2、完全背包的做法代码示例&#xff08;1&#xff09;过程模拟&#xff08;2&#xff09;代码示例 3、计数类DP的做法&#xff08;1&#xff09;过程模拟&#xff08;2&#xff09;闫氏DP…

疑难杂症!handleSubmit does not execute onSubmit function

背景 今天在写Nextjs代码的时候&#xff0c;发现一个问题&#xff0c;我使用react-use-form的表单&#xff0c;点击提交按钮的时候&#xff1a;onSubmit没有被触发&#xff01;&#xff01; 于是排查 源代码如下&#xff1a; "use client"import { AddLinkReques…

ros小问题之差速轮式机器人轮子不显示(rviz gazebo)

在rviz及gazebo练习差速轮式机器人时&#xff0c;很奇怪&#xff0c;只有个机器人的底板及底部的两个万向轮&#xff0c;如下图&#xff0c; 后来查看相关.xacro文件&#xff0c;里面是引用包含了轮子的xacro文件&#xff0c;只需传入不同的参数即可调用生成不同位置的轮子&…

数据结构——lesson8二叉树的实现

&#x1f49e;&#x1f49e; 前言 hello hello~ &#xff0c;这里是大耳朵土土垚~&#x1f496;&#x1f496; &#xff0c;欢迎大家点赞&#x1f973;&#x1f973;关注&#x1f4a5;&#x1f4a5;收藏&#x1f339;&#x1f339;&#x1f339; &#x1f4a5;个人主页&#x…

如何使用人工智能打造超用户预期的个性化购物体验

回看我的营销职业生涯&#xff0c;我见证了数字时代如何重塑客户期望。从一刀切的方法过渡到创造高度个性化的购物体验已成为企业的关键。在这个客户期望不断变化的新时代&#xff0c;创造个性化的购物体验不再是奢侈品&#xff0c;而是企业的必需品。人工智能 &#xff08;AI&…

UnityShader(十六)凹凸映射

前言&#xff1a; 纹理的一种常见应用就是凹凸映射&#xff08;bump mapping&#xff09;。凹凸映射目的就是用一张纹理图来修改模型表面的法线&#xff0c;让模型看起来更加细节&#xff0c;这种方法不会改变模型原本的顶点位置&#xff08;也就是不会修改模型的形状&#xf…

资深老鸟经验,性能测试-性能指标分析总结,一篇策底概全...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 性能测试指标 1、…

146 Linux 网络编程2 ,Socket编程,如何创建Linux 服务器 和linux 客户端

IPport 就是一个程序在网络上的身份证号码。 这意味着我们需要如果写一个服务器&#xff0c;至少需要将这台服务器的ip 和 端口号写到程序里面。 实际上更细化的说&#xff1a;应该是将这三都写进程序里面 &#xff1a; IP类型&#xff08;IPV4或者IPV6&#xff09;&#xff…

Anaconda安装proplot库

看了一下Anaconda中的环境&#xff0c;现在我有4个&#xff0c;其中gee是一个虚拟环境 因此一般在prompt中装库时要先进入其中一个虚拟环境 conda activate geepip install proplot --no-deps下完了之后&#xff0c;发现版本不对应 conda install matplotlib3.4.3

面试算法-39-删除链表的倒数第 N 个结点

题目 给你一个链表&#xff0c;删除链表的倒数第 n 个结点&#xff0c;并且返回链表的头结点。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4,5], n 2 输出&#xff1a;[1,2,3,5] 解 class Solution {public ListNode removeNthFromEnd(ListNode head, int n) {L…

【Linux】进程信号{初识信号/常见的信号/中断信号/信号的产生}

文章目录 0.浅谈中断信号1.初识信号2.中断信号3.信号的产生测试&#xff1a;SIGINT 4.core dump核心转储5.系统接口产生信号5.1kill给指定发5.2raise向自己发5.3abort自己给自己发6 6.由于软件条件不满足产生信号6.1SIGPIPE6.2SIGALRM 7. 硬件异常产生信号7.1除零错误7.2野指针…

云服务器容器常用操作系统介绍

常用操作系统介绍 开源软件国内镜像源Alpine操作系统介绍镜像源修改镜像源apk包管理器 Debian操作系统介绍镜像源修改镜像源apt包管理器 ubuntu操作系统介绍修改镜像源apt包管理器 CentOS操作系统介绍修改镜像源yum包管理器 开源软件国内镜像源 名称地址南京大学mirror.nju.ed…

奇酷网络董事长吴渔夫:AI时代的工作节奏

奇酷网络董事长吴渔夫今日分享&#xff1a; 1、从2024年春节后上班至今&#xff0c;我每天都是工作16小时的。除了睡觉时间段&#xff0c;其它时间都在工作&#xff1b;连吃个饭也是一边吃一边看手机&#xff0c;阅读AI新闻、学习Sora和AI知识的。 2、我的工作方式&#xff0…

22 OpenCV 直方图计算

文章目录 直方图概念split 通道分离函数calcHist 计算直方图normalize 归一化函数示例 直方图概念 上述直方图概念是基于图像像素值&#xff0c;其实对图像梯度、每个像素的角度、等一切图像的属性值&#xff0c;我们都可以建立直方图。这个才是直方图的概念真正意义&#xff0…

PHP魔术方法详解

php魔术方法是一些特殊的方法&#xff0c;由特定的环境来进行触发。 这些魔术方法让开发者能够更好地控制对象的行为&#xff0c;特别是在处理不常见的操作或者需要自动化处理某些任务时非常有用。 1、_construct()构造函数&#xff1a; <?php highlight_file(__FILE__);…

【静夜思】为什么我们会如此喜欢夜晚呢

作为一名大学生&#xff0c;熬夜对我来说已是常态。每天都是近乎一点钟才有困意&#xff0c;觉得应该上床睡觉了&#xff0c;即使明天早八&#xff0c;即使明天有很多课。我也观察过身边的朋友&#xff0c;他们中大多数也和我一样&#xff0c;基本都是在12点过后才入睡。当今的…

DDL - 建立数据库,建表代码版(Way 2)

一、DB操作 show databases; create database DBOFRYX; drop database DBOFRYX; use DBOFRYX; 二、表操作&#xff08;表和表结构、字段是A、B两姐妹&#xff09; (1) use DBOFRYX; show tables; (2) create table TABOFRYX( name varchar(50) comment "姓名"…

【SpringBoot3】整合Druid数据源和Mybatis 项目打包和运行

文章目录 一、整合Druid数据源二、整合Mybatis2.1 MyBatis整合步骤2.1 Mybatis整合实践2.1 声明式事务整合配置2.1 AOP整合配置 三、项目打包和运行命令启动和参数说明 总结web 与 springboot 打包区别JDK8的编译环境 执行17高版本jar 一、整合Druid数据源 创建模块 &#xff1…