-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
feature: add db realization for distribute lock #3487
feature: add db realization for distribute lock #3487
Conversation
server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
Outdated
Show resolved
Hide resolved
# Conflicts: # core/src/main/java/io/seata/core/constants/ConfigurationKeys.java # core/src/main/java/io/seata/core/store/DistributedLockDO.java # script/server/config/file.conf # script/server/config/file.properties # script/server/config/file.yml # server/src/main/java/io/seata/server/Server.java # server/src/main/resources/file.conf
Codecov Report
@@ Coverage Diff @@
## develop #3487 +/- ##
=============================================
- Coverage 40.56% 40.38% -0.19%
- Complexity 3070 3071 +1
=============================================
Files 682 685 +3
Lines 23082 23194 +112
Branches 2854 2869 +15
=============================================
+ Hits 9364 9367 +3
- Misses 12848 12958 +110
+ Partials 870 869 -1
|
… feature-distribute-lock-db
server/src/main/java/io/seata/server/session/SessionHolder.java
Outdated
Show resolved
Hide resolved
config/seata-config-core/src/main/java/io/seata/config/ConfigurationCache.java
Show resolved
Hide resolved
server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
Show resolved
Hide resolved
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
rm-datasource/src/main/java/io/seata/rm/datasource/undo/AbstractUndoLogManager.java
Show resolved
Hide resolved
server/src/main/java/io/seata/server/storage/db/lock/DataBaseDistributedLocker.java
Outdated
Show resolved
Hide resolved
I think '分布式锁' use 'Distributed lock' is better than 'Distribute lock'. |
lock_value VARCHAR2(20) NOT NULL, | ||
expire DECIMAL(18) NOT NULL, | ||
PRIMARY KEY (lock_key) |
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.
是否需要创建时间这个字段?如果出现什么问题,能知道这个记录什么时候insert进去的。
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.
这个我觉得应该不需要。
- expire + 配置的distributedLockExpireTime是可以反推出来插入时间的
- 不同公司的对于插入时间的字段名一般也不太一样,如果他们有需要可以随时自行加一个default current_timestamp的插入时间
connection.commit(); | ||
return true; | ||
} | ||
|
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.
释放锁的做法不是delete,而是update,是为了可重入吗?
那分布式锁表岂不是数据越来越多?
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.
delete其实更符合分布式锁的正常实现方式,但是在db的时候,我这边测试的话,数据量少的时候,MySQL插入是拿了表锁,因此就很容易造成死锁;然后考虑到我们目前的使用方式中,传入的key都是一样的,也就无需清理,因此就采用了update的形式
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.
哦,是的,我们这个场景目前确实是这样的。
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
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
Ⅰ. Describe what this PR did
添加db模式下的分布式锁实现
Ⅱ. Does this pull request fix one issue?
fixes #3428
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews