# byteTcc-demo **Repository Path**: wydongs/byte-tcc-demo ## Basic Information - **Project Name**: byteTcc-demo - **Description**: 分布式事务框架 byteTcc 小案例 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-10-19 - **Last Updated**: 2021-10-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 1. 在每个参与tcc事务的数据库中创建bytejta表 ```sql DROP TABLE IF EXISTS `bytejta`; CREATE TABLE `bytejta` ( `xid` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `gxid` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `bxid` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ctime` bigint(20) NULL DEFAULT NULL, PRIMARY KEY (`xid`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; ``` ## 2. 业务场景: A向B转账1元 ### Try: ``` //A的变化 A: { amount = amount -1; frozen = frozen + 1; } //B的变化 B: { frozen = frozen + 1; } ``` ### Confirm: ``` //A的变化 A: { frozen = frozen - 1; } //B的变化 B: { frozen = frozen - 1; amount = amount + 1; } ``` ### Cancel: ``` //A的变化 A: { amount = amount +1; frozen = frozen - 1; } //B的变化 B: { frozen = frozen - 1; } ``` ## 3. 准备工作: sql脚本: ```sql -- 数据库实例inst01 CREATE TABLE tb_account_one ( acct_id varchar(16), amount double(10, 2), frozen double(10, 2), PRIMARY KEY (acct_id) ) ENGINE=InnoDB; insert into tb_account_one (acct_id, amount, frozen) values('1001', 100, 0.00); -- 数据库实例inst02 CREATE TABLE tb_account_two ( acct_id varchar(16), amount double(10, 2), frozen double(10, 2), PRIMARY KEY (acct_id) ) ENGINE=InnoDB; insert into tb_account_two (acct_id, amount, frozen) values('2001', 10000.00, 0.00); ``` ## 4. 运行 POST http://localhost:7080/transfer?sourceAcctId=2001&targetAcctId=1001&amount=1000 ### consumer 日志 ``` 2020-09-28 09:32:46.844 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableManagerImpl : 69e260bbcb9cb6d0b8705701670a2924| compensable transaction begin! 2020-09-28 09:32:46.844 INFO 1336 --- [nio-7080-exec-1] o.b.bytejta.TransactionCoordinator : 69e260bbcb9cb6d0b8705701670a2924> begin-participant 2020-09-28 09:32:46.844 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| register compensable service: 69e260bbcb9cb6d0b8705701670a2924. 2020-09-28 09:32:47.029 INFO 1336 --- [nio-7080-exec-1] c.n.u.concurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-SPRINGCLOUD-SAMPLE-PROVIDER 2020-09-28 09:32:47.030 INFO 1336 --- [nio-7080-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: SPRINGCLOUD-SAMPLE-PROVIDER instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=SPRINGCLOUD-SAMPLE-PROVIDER,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null 2020-09-28 09:32:47.038 INFO 1336 --- [nio-7080-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater 2020-09-28 09:32:47.063 INFO 1336 --- [nio-7080-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client SPRINGCLOUD-SAMPLE-PROVIDER initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=SPRINGCLOUD-SAMPLE-PROVIDER,current list of Servers=[inst1:7070],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;] },Server stats: [[Server:inst1:7070; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0] ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@1e63943f 2020-09-28 09:32:47.110 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| enlist remote resource: 192.168.1.163:SPRINGCLOUD-SAMPLE-PROVIDER:7070. 2020-09-28 09:32:47.378 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bbcb9cb6d0b8705701670a2924> enlist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bdfa9cb6d0b870570442746e8d, flags: 0 int02 decrease: acct= 2001, amount= 1000.00 2020-09-28 09:32:47.387 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bbcb9cb6d0b8705701670a2924> delist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bdfa9cb6d0b870570442746e8d, flags= 67108864 2020-09-28 09:32:47.387 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bbcb9cb6d0b8705701670a2924> commit-participant start 2020-09-28 09:32:47.390 INFO 1336 --- [nio-7080-exec-1] o.b.bytejta.resource.XATerminatorOptd : 69e260bbcb9cb6d0b8705701670a2924> commit: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bdfa9cb6d0b870570442746e8d, opc= false 2020-09-28 09:32:47.390 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| try: identifier= 69e260bbcb9cb6d0b8705701670a2924, resourceKey= dataSource, resourceXid= 1207-69e260bbcb9cb6d0b8705701670a2924-69e260bdfa9cb6d0b870570442746e8d. 2020-09-28 09:32:47.390 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| try completed. 2020-09-28 09:32:47.390 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bbcb9cb6d0b8705701670a2924> commit-participant complete successfully 2020-09-28 09:32:47.391 INFO 1336 --- [nio-7080-exec-1] o.b.bytejta.TransactionCoordinator : 69e260bdfb9cb6d0b8705705839696c3> begin-participant confirm : acct= 2001, amount= 1000.00 2020-09-28 09:32:47.392 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bdfb9cb6d0b8705705839696c3> enlist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bbcb9cb6d0b8705701670a2924, flags: 0 2020-09-28 09:32:47.393 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bdfb9cb6d0b8705705839696c3> delist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bbcb9cb6d0b8705701670a2924, flags= 67108864 2020-09-28 09:32:47.393 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bdfb9cb6d0b8705705839696c3> commit-participant start 2020-09-28 09:32:47.398 INFO 1336 --- [nio-7080-exec-1] o.b.bytejta.resource.XATerminatorOptd : 69e260bdfb9cb6d0b8705705839696c3> commit: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bbcb9cb6d0b8705701670a2924, opc= false 2020-09-28 09:32:47.399 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| confirm: identifier= 69e260bbcb9cb6d0b8705701670a2924, resourceKey= dataSource, resourceXid= 1207-69e260bdfb9cb6d0b8705705839696c3-69e260bbcb9cb6d0b8705701670a2924. 2020-09-28 09:32:47.399 INFO 1336 --- [nio-7080-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bdfb9cb6d0b8705705839696c3> commit-participant complete successfully 2020-09-28 09:32:47.445 WARN 1336 --- [nio-7080-exec-1] x.MappingJackson2XmlHttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class void]]: com.fasterxml.jackson.databind.JsonMappingException: Internal error: can't find deserializer for void 2020-09-28 09:32:47.445 WARN 1336 --- [nio-7080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class void]]: com.fasterxml.jackson.databind.JsonMappingException: Internal error: can't find deserializer for void 2020-09-28 09:32:48.186 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| confirm remote branch: 192.168.1.163:SPRINGCLOUD-SAMPLE-PROVIDER:7070 2020-09-28 09:32:48.186 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| compensable transaction committed! 2020-09-28 09:32:48.186 INFO 1336 --- [nio-7080-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| forget transaction. 2020-09-28 09:37:09.452 INFO 1336 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration 2020-09-28 09:42:09.453 INFO 1336 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration ``` ### provider 日志 ``` 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application is null : false 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application version is -1: false 2020-09-28 09:32:03.122 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2020-09-28 09:32:03.149 INFO 17396 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The response status is 200 2020-09-28 09:32:47.246 INFO 17396 --- [nio-7070-exec-1] o.b.bytetcc.CompensableCoordinator : 69e260bbcb9cb6d0b8705701670a2924| compensable transaction begin! 2020-09-28 09:32:47.286 INFO 17396 --- [nio-7070-exec-1] o.b.bytejta.TransactionCoordinator : 69e260bd989cb6d0b87057017c20f8d1> begin-participant 2020-09-28 09:32:47.287 INFO 17396 --- [nio-7070-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| register compensable service: 69e260bbcb9cb6d0b8705701670a2924. 2020-09-28 09:32:47.293 INFO 17396 --- [nio-7070-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bd989cb6d0b87057017c20f8d1> enlist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bda59cb6d0b87057035bc4f94f, flags: 0 exec increase: acct= 1001, amount= 1000.00 2020-09-28 09:32:47.319 INFO 17396 --- [nio-7070-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bd989cb6d0b87057017c20f8d1> delist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bda59cb6d0b87057035bc4f94f, flags= 67108864 2020-09-28 09:32:47.321 INFO 17396 --- [nio-7070-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bd989cb6d0b87057017c20f8d1> commit-participant start 2020-09-28 09:32:47.326 INFO 17396 --- [nio-7070-exec-1] o.b.bytejta.resource.XATerminatorOptd : 69e260bd989cb6d0b87057017c20f8d1> commit: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bda59cb6d0b87057035bc4f94f, opc= false 2020-09-28 09:32:47.326 INFO 17396 --- [nio-7070-exec-1] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| try: identifier= 69e260bbcb9cb6d0b8705701670a2924, resourceKey= dataSource, resourceXid= 1207-69e260bd989cb6d0b87057017c20f8d1-69e260bda59cb6d0b87057035bc4f94f. 2020-09-28 09:32:47.326 INFO 17396 --- [nio-7070-exec-1] org.bytesoft.bytejta.TransactionImpl : 69e260bd989cb6d0b87057017c20f8d1> commit-participant complete successfully 2020-09-28 09:32:48.155 INFO 17396 --- [nio-7070-exec-2] o.b.bytejta.TransactionCoordinator : 69e260bda69cb6d0b87057041c8aabef> begin-participant 2020-09-28 09:32:48.157 INFO 17396 --- [nio-7070-exec-2] org.bytesoft.bytejta.TransactionImpl : 69e260bda69cb6d0b87057041c8aabef> enlist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bd989cb6d0b87057017c20f8d1, flags: 0 confirm increase: acct= 1001, amount= 1000.00 2020-09-28 09:32:48.159 INFO 17396 --- [nio-7070-exec-2] org.bytesoft.bytejta.TransactionImpl : 69e260bda69cb6d0b87057041c8aabef> delist: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bd989cb6d0b87057017c20f8d1, flags= 67108864 2020-09-28 09:32:48.159 INFO 17396 --- [nio-7070-exec-2] org.bytesoft.bytejta.TransactionImpl : 69e260bda69cb6d0b87057041c8aabef> commit-participant start 2020-09-28 09:32:48.172 INFO 17396 --- [nio-7070-exec-2] o.b.bytejta.resource.XATerminatorOptd : 69e260bda69cb6d0b87057041c8aabef> commit: xares= xa-res-archive[descriptor: local-xa-resource[dataSource]], branch= 69e260bd989cb6d0b87057017c20f8d1, opc= false 2020-09-28 09:32:48.172 INFO 17396 --- [nio-7070-exec-2] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| confirm: identifier= 69e260bbcb9cb6d0b8705701670a2924, resourceKey= dataSource, resourceXid= 1207-69e260bda69cb6d0b87057041c8aabef-69e260bd989cb6d0b87057017c20f8d1. 2020-09-28 09:32:48.173 INFO 17396 --- [nio-7070-exec-2] org.bytesoft.bytejta.TransactionImpl : 69e260bda69cb6d0b87057041c8aabef> commit-participant complete successfully 2020-09-28 09:32:48.173 INFO 17396 --- [nio-7070-exec-2] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| compensable transaction committed! 2020-09-28 09:32:48.174 INFO 17396 --- [nio-7070-exec-2] o.b.bytetcc.CompensableTransactionImpl : 69e260bbcb9cb6d0b8705701670a2924| forget transaction. ```