[seata]配置了db存储模式,服务正常启动,日志能看到全局事务等信息,并且事务回滚成功,但是branch_table、distributed_lock、global_table、lock_table表在事务执行过程中没有数据

2024-05-09 122 views
6

回答

9

2023-11-02 16:33:50.036 INFO --- [ NettyServerNIOWorker_1_10_32] iscrprocessor.server.RegTmProcessor : TM 注册成功,消息:RegisterTMRequest{applicationId='product-chain-service', transactionServiceGroup='default_tx_group'},channel: [id: 0x854458ba,L:/172.18.169.101:8091 - R:/172.18.169.101:57272],客户端版本:1.6.1 2023-11-02 16:33:50.145 INFO --- [ NettyServerNIOWorker_1_11_32] iscrprocessor.server .RegTmProcessor : TM 注册成功,消息:RegisterTMRequest{applicationId='F10-query-service', transactionServiceGroup='default_tx_group'},channel:[id: 0xc3dbf8a4, L:/172.18.169.101:8091 - R:/172.18.169.101 :57275],客户端版本:1.6.1 2023-11-02 16:33:50.920 INFO --- [ ServerHandlerThread_1_13_500] iscrprocessor.server.RegRmProcessor : RM 注册成功,消息:RegisterRMRequest{resourceIds='jdbc:mysql:// localhost:3306/financial_graph_query', applicationId='product-chain-service', transactionServiceGroup='default_tx_group'},channel:[id: 0x95d9062d, L:/172.18.169.101:8091 - R:/172.18.169.101:57279],客户端版本:1.6.1 2023-11-02 16:33:51.313 INFO --- [ ServerHandlerThread_1_14_500] iscrprocessor.server.RegRmProcessor : RM 注册成功,消息:RegisterRMRequest{resourceIds='jdbc:mysql://localhost:3306/ Financial_graph_query', applicationId='F10-query-service', transactionServiceGroup='default_tx_group'},channel:[id: 0x8d668dd2, L:/172.18.169.101:8091 - R:/172.18.169.101:57282],客户端版本:1.6 .1 2023-11-02 16:34:15.360 信息 --- [batchLoggerPrint_1_1] iscrpserver.BatchLogHandler : timeout=60000,transactionName=addComopany(edu.neu.domain.Company),clientIp:172.18.169.101,vgroup:default_tx_group 2023 -11-02 16:34:15.360 INFO --- [ ServerHandlerThread_1_15_500] isscoordinator.DefaultCoordinator :开始新的全局事务 applicationId:F10-query-service,transactionServiceGroup:default_tx_group,transactionName:addComopany(edu.neu.domain.Company),超时:60000,xid:172.18.169.101:8091:5242642458978557957 2023-11-02 16:34:15.550信息---[batchLoggerPrint_1_1] iscrpserver.BatchLogHandler:SeataMergeMes​​sage xid = 172.18.169.101:8 091:5242642458978557957,branchType=AT,resourceId= jdbc:mysql://localhost:3306/financial_graph_query,lockKey=company:1 ,clientIp:172.18.169.101,vgroup:default_tx_group 2023-11-02 16:34:15.550 信息 --- [ ServerHandlerThread_1_16_500] i.seata.server。 coordinator.AbstractCore :注册分支成功,xid = 172.18.169.101:8091:5242642458978557957,branchId = 5242642458978557958,resourceId = jdbc:mysql://localhost:3306/financial_graph_query ,lockKeys = company:1 2023-11 -02 16:34: 15.906信息---[batchLoggerPrint_1_1] iscrpserver.BatchLogHandler:SeataMergeMes​​sage xid = 172.18.169.101:8091:5242642458978557957,branchType = AT,resourceId = jdbc:mysql://localhost:3306/financial_graph_query,lockKey =产品:1,clientIp: 172.18 .169.101,vgroup:default_tx_group 2023-11-02 16:34:15.906 INFO --- [ ServerHandlerThread_1_17_500] i.seata.server.coordinator.AbstractCore :注册分支成功,xid = 172.18.169.101:8091:5242642458978557957,branchId = 52 42642458978557959, 资源 ID = jdbc:mysql://localhost:3306/financial_graph_query ,lockKeys = 产品:1 2023-11-02 16:34:15.980 INFO --- [batchLoggerPrint_1_1] iscrpserver.BatchLogHandler : xid=172.18.169.101:8091:5242642458978557957,额外数据= null,clientIp:172.18.169.101,vgroup:default_tx_group 2023-11-02 16:34:16.023 INFO --- [ ServerHandlerThread_1_18_500] io.seata.server.coordinator.DefaultCore :成功回滚分支事务,xid = 172.18.169.101:8091 :5242642458978557957branchId = 5242642458978557959 2023-11-02 16:34:16.055 INFO --- [ServerHandlerThread_1_18_500] io.seata.server.coordinator.DefaultCore : 成功回滚分支事务,xid = 172.18.16 9.101:8091:5242642458978557957 分支 ID = 5242642458978557958 2023 -11-02 16:34:16.055 INFO --- [ ServerHandlerThread_1_18_500] io.seata.server.coordinator.DefaultCore :成功回滚全局事务,xid = 172.18.169.101:8091:5242642458978557957。

5
#  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: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      namespace:
      group: SEATA_GROUP
      username: nacos
      password: nacos
      context-path:
      ##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, sofa
    type: nacos
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      namespace:
      cluster: default
      username: nacos
      password: nacos
  store:
    # support: file 、 db 、 redis
    mode: db
    lock:
      mode: db
    session:
      mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/seata?characterEncoding=utf-8&serverTimezone=UTC&rewriteBatchedStatements=true
      user: root
      password: 123456
      min-conn: 10
      max-conn: 100
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 1000
      max-wait: 5000
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
7

`#配置项详情参见https://seata.io/zh-cn/docs/user/configurations.html

客户端和服务器的传输配置

Transport.type=TCP Transport.server=NIO Transport.heartbeat=truetransport.enableTmClientBatchSendRequest=falsetransport.enableRmClientBatchSendRequest=truetransport.enableTcServerBatchSendResponse=falsetransport.rpcRmRequestTimeout=30000transport.rpcTmRequestTimeout=30000transport.rpcTcRequestTimeout=30000transport.threadFactory.bossThreadPrefix =NettyBosstransport.threadFactory.workerThreadPrefix=NettyServerNIOWorkertransport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandlertransport.threadFactory.shareBossWorker=falsetransport.threadFactory.clientSelectorThreadPrefix=NettyClientSelectortransport.threadFactory.clientSelectorThreadSize=1transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThreadtransport.threadFactory.boss线程大小= 1transport.threadFactory.workerThreadSize=默认transport.shutdown.wait=3transport.serialization=seatatransport.compressor=none

交易路由规则配置,仅针对客户端

service.vgroupMapping.default_tx_group=默认

如果您使用注册表,则可以忽略它

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=true 客户端。 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 个客户端。 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 客户端。 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

对于TCC交易模式

tcc.fence.logTableName=tcc_fence_log tcc.fence.cleanPeriod=1h

日志规则配置,适用于客户端和服务器

日志异常率=100

交易存储配置,仅适用于服务器。 file、db 和 redis 配置值是可选的。

store.mode=db store.lock.mode=文件 store.session.mode=文件

用于密码加密

商店.publicKey=

如果store.mode,store.lock.mode,store.session.mode不等于file,则可以删除配置块。

store.file.dir=file_store/数据 store.file.maxBranchSessionSize=16384 store.file.maxGlobalSessionSize=512 store.file.fileWriteBufferCacheSize=16384 store.file.flushDiskMode=异步 store.file.sessionReloadReadSize=100

store mode如果是,则需要这些配置db。如果store.mode,store.lock.mode,store.session.mode不等于db,则可以删除配置块。

store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=mysql://127.0.0.1:3306/seata?characterEncoding=utf -8&serverTimezone=UTC&rewriteBatchedStatements=true store.db.user=root store.db.password=123456 store.db.minConn=5 store.db.maxConn=30 store.db.globalTable=global_table store.db.branchTable=branch_table 存储。 db.distributedLockTable=分布式锁 store.db.queryLimit=100 store.db.lockTable=lock_table store.db.maxWait=5000

store mode如果是,则需要这些配置redis。如果store.mode,store.lock.mode,store.session.mode不等于redis,则可以删除配置块。

store.redis.mode=单 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.distributedLockExp时间=10000 server.xaerNotaRetryTimeout=60000 server.session.branchAsyncQueueSize=5000 server.session.enableBranchAsyncRemove=false server.enableParallelRequestHandle=false

Metrics配置,仅适用于服务器

metrics.enabled=falsemetrics.registryType=compactmetrics.exporterList=prometheusmetrics.exporterPrometheusPort=9898 `

6

你错过了启动日志,应该有一些像这样的日志

16:42:28.772  INFO --- [                     main] [rver.lock.LockerManagerFactory] [                init]  [] : use lock store mode: file
16:42:28.776  INFO --- [                     main] [a.server.session.SessionHolder] [                init]  [] : use session store mode: file

看来你使用文件模式,你可以检查 store.file.dir=file_store/data

交易存储配置,仅适用于服务器。 file、db 和 redis 配置值是可选的。

store.mode=db store.lock.mode=文件 store.session.mode=文件

这些应该是数据库。

如果您正在编写一些演示,您可以提供整个项目

4

我修改一下config,把lock和session都改成db,然后重新导入到nacos。然后启动seata报连接不到数据源的错误,请问这是什么原因呢?

17:12:34.021  INFO --- [                     main] o.s.s.web.DefaultSecurityFilterChain     : Will not secure any request
17:12:34.056  INFO --- [                     main] o.a.coyote.http11.Http11NioProtocol      : Starting ProtocolHandler ["http-nio-7091"]
17:12:34.081  INFO --- [                     main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 7091 (http) with context path ''
17:12:34.093  INFO --- [                     main] io.seata.server.ServerApplication        : Started ServerApplication in 3.731 seconds (JVM running for 4.415)
17:12:34.590 ERROR --- [                     main] com.alibaba.druid.pool.DruidDataSource   : init datasource error, url: mysql://127.0.0.1:3306/seata?characterEncoding=utf-8&serverTimezone=UTC&rewriteBatchedStatements=true
==>
java.sql.SQLException: connect error, url mysql://127.0.0.1:3306/seata?characterEncoding=utf-8&serverTimezone=UTC&rewriteBatchedStatements=true, driverClass com.mysql.cj.jdbc.Driver
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1727)
        at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:919)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1393)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1389)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:100)
        at io.seata.server.storage.db.store.LogStoreDataBaseDAO.queryTableStructure(LogStoreDataBaseDAO.java:473)
        at io.seata.server.storage.db.store.LogStoreDataBaseDAO.initTransactionNameSize(LogStoreDataBaseDAO.java:457)
        at io.seata.server.storage.db.store.LogStoreDataBaseDAO.<init>(LogStoreDataBaseDAO.java:106)
        at io.seata.server.storage.db.store.DataBaseTransactionStoreManager.<init>(DataBaseTransactionStoreManager.java:95)
        at io.seata.server.storage.db.store.DataBaseTransactionStoreManager.getInstance(DataBaseTransactionStoreManager.java:80)
        at io.seata.server.storage.db.session.DataBaseSessionManager.init(DataBaseSessionManager.java:76)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.initInstance(EnhancedServiceLoader.java:634)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.createNewExtension(EnhancedServiceLoader.java:459)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.getExtensionInstance(EnhancedServiceLoader.java:452)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.loadExtension(EnhancedServiceLoader.java:420)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.load(EnhancedServiceLoader.java:311)
        at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.access$200(EnhancedServiceLoader.java:245)
        at io.seata.common.loader.EnhancedServiceLoader.load(EnhancedServiceLoader.java:87)
        at io.seata.server.session.SessionHolder.init(SessionHolder.java:106)
        at io.seata.server.session.SessionHolder.init(SessionHolder.java:93)
        at io.seata.server.Server.start(Server.java:78)
        at io.seata.server.ServerRunner.run(ServerRunner.java:50)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:812)
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:796)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:346)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
        at io.seata.server.ServerApplication.main(ServerApplication.java:30)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
<==
5
store.db.url=mysql://127.0.0.1:3306/seata?characterEncoding=utf-8&serverTimezone=UTC&rewriteBatchedStatements=true

缺少 jdbc 前缀。

store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
5

并确保您的数据库正常,可以通过 127.0.0.1 连接

4

啊解决了,已经找到jdbc了,谢谢!

0

全局表中的回滚和提交将在事务完成后2分10秒被删除。