Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Bughue
Copy link
Contributor

@Bughue Bughue commented Feb 16, 2022

Ⅰ. Describe what this PR did

更新globalstatus的时候采用线程安全的方式,阻止预期状态不匹配的操作继续执行。
目前的思路是:rollback和commit都用乐观锁方式去更新globalsession的status,更新成功的会往下执行。没有更新成功的会遇到异常而中断。
传参expected status方式使用threadlocal

以下两个pr优化了之后,这个pr可以简化
#4858
#4881

pr已经重新提交
#5501

Ⅱ. Does this pull request fix one issue?

fixes #4372

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@slievrly slievrly added the first-time contributor first-time contributor label Feb 16, 2022
@Bughue Bughue changed the title change transaction state thread-safe in db/redis mode bugfix:change transaction state thread-safe in db/redis mode Feb 17, 2022
@Bughue Bughue changed the title bugfix:change transaction state thread-safe in db/redis mode optimize : change transaction state thread-safe in db/redis mode Feb 17, 2022
pengten
pengten previously approved these changes Feb 21, 2022
if (globalSession.getStatus() == GlobalStatus.Begin) {
// Highlight: Firstly, close the session, then no more branch can be registered.
globalSession.closeAndClean();
globalSession.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change to close,instead of closeAndClean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close session first, and clean it later (line172)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我想起来了,是防止一下解锁了后,事务状态不一致了?因为现在是先close后解锁,如果这个时候先解锁更新状态失败了,说明这个事务timeoutcheck线程改成回滚了,但是由于先解锁会可能数据被脏写@slievrly 看下这个情况,由于先改状态后解锁,性能肯定是会受到一定影响

throw new StoreException("updateGlobalSessionStatus failed.");
try {
// set expected status threadlocal
session.setExpectedStatusFromCurrent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using threadlocal on the server side is not a good design solution.It is tied to the current threading model. threadlocal's public set method does nothing to protect it from abuse.


在server侧使用threadlocal不是一个好的设计方案,这里与当前的线程处理模型有绑定关系。threadlocal 的public set方法没办法去规避被滥用的风险。

conn = logStoreDataSource.getConnection();
conn.setAutoCommit(true);
ps = conn.prepareStatement(sql);
ps.setInt(index++, globalTransactionDO.getStatus());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the index order of the columns rather than relying on the order of the code.


明确列的index顺序而不要依赖代码的顺序。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是为了遵循本来的风格,所以趁这次把这个方法改掉吗?

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

� Conflicts:
�	.github/workflows/build.yml
�	.github/workflows/publishes.yml
�	.github/workflows/test.yml
�	changes/en-us/develop.md
�	changes/zh-cn/develop.md
�	integration-tx-api/src/main/java/io/seata/integration/tx/api/interceptor/handler/GlobalTransactionalInterceptorHandler.java
�	rm-datasource/src/main/java/io/seata/rm/datasource/exec/UpdateExecutor.java
�	rm-datasource/src/main/java/io/seata/rm/datasource/undo/mysql/MySQLUndoUpdateExecutor.java
�	server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
@Bughue Bughue changed the title optimize : change transaction state thread-safe in db mode [WIP]optimize : change transaction state thread-safe in db mode Apr 10, 2023
@Bughue Bughue closed this Apr 10, 2023
@slievrly slievrly removed this from the 2.0.0 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db/redis mode must be thread-safe when changing the transaction state