Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于SpringColud那个例子 #1

Open
CrazyShaQuiShi opened this issue Jun 16, 2017 · 16 comments
Open

关于SpringColud那个例子 #1

CrazyShaQuiShi opened this issue Jun 16, 2017 · 16 comments

Comments

@CrazyShaQuiShi
Copy link

里面的业务逻辑是怎样的,能描述下吗。好像提供这个例子的任何说明啊,这是个纯代码的例子。数据库的执行文件好像也没有。大佬能提供下吗,frozen是啥含义?冻结吗?amount是总金额吗?为啥在increaseAmount增加的时候frozen要增加,那个提供者里面
update tb_account_one set frozen = frozen + ? where acct_id = ?

@liuyangming
Copy link
Owner

数据库表建表sql在dubbo那个样例中。

@yangshijin1995
Copy link

springCloud用gradle构建时,报错:
2017-07-27 09:56:00.837 ERROR 15616 --- [pool-1-thread-3] druid.sql.Statement : {conn-10005, pstmt-20004} execute error. delete from bytejta where xid = ?
java.sql.BatchUpdateException: Table 'wzd.bytejta' doesn't exist
能帮忙解决下吗?

@liuyangming
Copy link
Owner

看一下用户指南。需要建bytejta表。

@carvendy
Copy link

carvendy commented Sep 5, 2017

frozen 这个每张表都要加的字段,用作标识?

@liuyangming
Copy link
Owner

frozen只是是ByteTCC-sample样例工程的业务数据字段。业务表字段由各业务系统自行设计,ByteTCC不做任何约束。

@watonyweng
Copy link

@liuyangming bytejta表在inst01和inst02数据库中都要创建吗?

@liuyangming
Copy link
Owner

是的,都需要创建。

@watonyweng
Copy link

@liuyangming 谢谢您的解惑

@laziobird
Copy link

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
你项目包有冲突?起不来eureka

@txp-reps
Copy link

txp-reps commented Dec 5, 2018

@liuyangming 你好! 我在consumer中加了下面的逻辑, 模拟confirm阶段报错. 按我的理解confirm阶段报错会执行cancel的逻辑.结果没有执行. 期待解惑!

    @CompensableConfirm
@Transactional
public void commitTransfer(String sourceAcctId, String targetAcctId, double amount) {
	if (amount == 3) {
		throw new IllegalStateException("ERROR!");
	}
	System.out.println("consumer commit ================");
}

调用参数:
localhost:7080/simplified/transfer?sourceAcctId=1001&targetAcctId=2001&amount=3
错误信息:
[2018-12-05 14:23:03.532] [http-nio-7080-exec-2] [ERROR] org.bytesoft.bytetcc.CompensableTransactionImpl - 7c67a2561d464c2b970d411fd73e87c3| error occurred while confirming service: [compensable-archive| identifier= 7c67a2561d464c2b970d411fd73e87c3, transactionKey= dataSource, transactionXid= 1207-7c67a2561d464c2b970d411fd73e87c3-7c67a2561d464c2b970d672299a4ce36, compensableKey= null, compensableXid= 1207-7c67a2561d464c2b970d411fd73e87c3-7c67a2561d464c2b970d6823b25d08d2, confirmed= false, cancelled= false]
java.lang.RuntimeException: org.springframework.transaction.TransactionSystemException: Unexpected internal transaction state; nested exception is java.lang.IllegalStateException

@liuyangming
Copy link
Owner

confirm属于commit阶段的回调业务逻辑;cancel属于rollback阶段的回调业务逻辑。
TCC全局事务一旦进入commit阶段,就不会在进入rollback阶段了(因为此时可能已经有资源/分支已经commit成功,如果再走rollback,则会造成一部分分支commit而另一部分分支rollback的mixed状态)。

因此,当confirm出错时,后续故障恢复模块会重新尝试回调该confirm,而不是执行cancel。

@txp-reps
Copy link

txp-reps commented Dec 6, 2018

明白了, 多谢

@txp-reps
Copy link

txp-reps commented Dec 9, 2018

故障恢复的重试时间能调整吗? 怎么调整?

@liuyangming
Copy link
Owner

可以调整,找到CompensableWork的bean实例,改变其默认间隔时间的属性即可。

@SampsonJava
Copy link

SpringCloud-sample中为什么frozen这个字段没有使用了

@liuyangming
Copy link
Owner

liuyangming commented May 11, 2020

为了覆盖更多的使用场景,所以样例故意设置成不一样的:
1、使用frozen的样例,存在中间状态,所以业务中必须存在confirm逻辑;
2、不使用frozen的样例,不存在中间状态,所以confirm逻辑是可以省略的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants