-
Notifications
You must be signed in to change notification settings - Fork 8.9k
[WIP]optimize : change transaction state thread-safe in db mode #4383
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
Conversation
server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/coordinator/DefaultCore.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/redis/session/RedisSessionManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/GlobalSession.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/redis/store/RedisTransactionStoreManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/redis/store/RedisTransactionStoreManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/AbstractSessionManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/AbstractSessionManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/AbstractSessionManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/GlobalSession.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/redis/store/RedisTransactionStoreManager.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/session/GlobalSession.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
Outdated
Show resolved
Hide resolved
…pache#5413) Signed-off-by: slievrly <[email protected]>
Signed-off-by: slievrly <[email protected]>
…ailureHandler (apache#5415) Signed-off-by: slievrly <[email protected]>
| if (globalSession.getStatus() == GlobalStatus.Begin) { | ||
| // Highlight: Firstly, close the session, then no more branch can be registered. | ||
| globalSession.closeAndClean(); | ||
| globalSession.close(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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顺序而不要依赖代码的顺序。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是为了遵循本来的风格,所以趁这次把这个方法改掉吗?
funky-eyes
left a comment
There was a problem hiding this 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
Ⅰ. 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