微服务痛点-基于Dubbo + Seata的分布式事务(TCC模式) (6)

微服务痛点-基于Dubbo + Seata的分布式事务(TCC模式)

正常流程-模拟用户下单,看下各应用的二阶段提交日志

执行business模块test/java目录下的business.http文件,对接口发起请求

POST localhost:8084/business/buy Content-Type: application/json { "userId" : "user123", "commodityCode" : "cola", "count" : 2, "amount" : 5.0 }

各数据库数据变化

mysql> use storage; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from storage; +----+----------------+------+-------+ | id | commodity_code | name | count | +----+----------------+------+-------+ | 1 | cola | ???? | 1998 | +----+----------------+------+-------+ 1 row in set (0.00 sec) mysql> use account; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from account; +----+---------+---------+ | id | user_id | amount | +----+---------+---------+ | 1 | user123 | 1245.00 | +----+---------+---------+ 1 row in set (0.00 sec) mysql> use order; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from order; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order' at line 1 mysql> select * from `order`; +----+----------------------------------+---------+------+-------+--------+ | id | order_no | user_id | code | count | amount | +----+----------------------------------+---------+------+-------+--------+ | 5 | dbde6ebfd72b4ad5aeba67d67ade6894 | user123 | cola | 2 | 5.00 | +----+----------------------------------+---------+------+-------+--------+ 1 row in set (0.00 sec)

各应用下二阶段提交情况,下面日志以Storage应用为例

2020-12-28 17:59:40.778 INFO 28287 --- [ctor_RMROLE_1_1] io.seata.rm.AbstractRMHandler : the rm client received response msg [version=1.5.0-SNAPSHOT,extraData=null,identified=true,resultCode=null,msg=null] from tc server. 2020-12-28 17:59:40.783 DEBUG 28287 --- [:20881-thread-2] c.m.s.d.S.tccDecreaseStoragePrepare : ==> Preparing: update tcc_storage set count = count - ?, frozen_count = frozen_count + ? where commodity_code = ? 2020-12-28 17:59:40.822 DEBUG 28287 --- [:20881-thread-2] c.m.s.d.S.tccDecreaseStoragePrepare : ==> Parameters: 2(Integer), 2(Integer), cola(String) 2020-12-28 17:59:40.830 DEBUG 28287 --- [:20881-thread-2] c.m.s.d.S.tccDecreaseStoragePrepare : <== Updates: 1 2020-12-28 17:59:41.662 INFO 28287 --- [h_RMROLE_1_1_16] i.s.c.r.p.c.RmBranchCommitProcessor : rm client handle branch commit process:xid=172.20.0.2:8091:86882407747166208,branchId=86882409689128960,branchType=TCC,resourceId=decreaseStorageTcc,applicationData={"actionContext":{"action-start-time":1609149580502,"sys::prepare":"decreaseStoragePrepare","sys::rollback":"decreaseStorageCancel","sys::commit":"decreaseStorageCommit","commdityDTO":{"commodityCode":"cola","count":2},"host-name":"172.17.54.171","actionName":"decreaseStorageTcc"}} 2020-12-28 17:59:41.664 INFO 28287 --- [h_RMROLE_1_1_16] io.seata.rm.AbstractRMHandler : Branch committing: 172.20.0.2:8091:86882407747166208 86882409689128960 decreaseStorageTcc {"actionContext":{"action-start-time":1609149580502,"sys::prepare":"decreaseStoragePrepare","sys::rollback":"decreaseStorageCancel","sys::commit":"decreaseStorageCommit","commdityDTO":{"commodityCode":"cola","count":2},"host-name":"172.17.54.171","actionName":"decreaseStorageTcc"}} 2020-12-28 17:59:41.675 DEBUG 28287 --- [h_RMROLE_1_1_16] c.m.s.d.S.tccDecreaseStorageCommit : ==> Preparing: update tcc_storage set frozen_count = frozen_count - ? where commodity_code = ? 2020-12-28 17:59:41.676 DEBUG 28287 --- [h_RMROLE_1_1_16] c.m.s.d.S.tccDecreaseStorageCommit : ==> Parameters: 2(Integer), cola(String) 2020-12-28 17:59:41.681 DEBUG 28287 --- [h_RMROLE_1_1_16] c.m.s.d.S.tccDecreaseStorageCommit : <== Updates: 1 2020-12-28 17:59:41.704 INFO 28287 --- [h_RMROLE_1_1_16] io.seata.rm.AbstractResourceManager : TCC resource commit result : true, xid: 172.20.0.2:8091:86882407747166208, branchId: 86882409689128960, resourceId: decreaseStorageTcc 2020-12-28 17:59:41.705 INFO 28287 --- [h_RMROLE_1_1_16] io.seata.rm.AbstractRMHandler : Branch commit result: PhaseTwo_Committed 异常流程-模拟用户下单,看下各应用的二阶段提交日志

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpyzyx.html