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

optimize: @GlobalTransactional and @GlobalLock can now customize lock retry config #2962

Merged
merged 32 commits into from
Oct 12, 2020

Conversation

selfishlover
Copy link
Contributor

Ⅰ. Describe what this PR did

allow @GlobalTransactional and @GlobalLock to customize lock retry interval and times, which would override the global config.

Ⅱ. Does this pull request fix one issue?

fixes #2943

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2020

Codecov Report

Merging #2962 into develop will increase coverage by 0.09%.
The diff coverage is 77.38%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #2962      +/-   ##
=============================================
+ Coverage      50.45%   50.54%   +0.09%     
- Complexity      3108     3122      +14     
=============================================
  Files            593      595       +2     
  Lines          19571    19637      +66     
  Branches        2427     2434       +7     
=============================================
+ Hits            9874     9925      +51     
- Misses          8702     8717      +15     
  Partials         995      995              
Impacted Files Coverage Δ Complexity Δ
...ain/java/io/seata/core/model/GlobalLockConfig.java 14.28% <14.28%> (ø) 1.00 <1.00> (?)
...ing/annotation/GlobalTransactionalInterceptor.java 29.45% <33.33%> (+0.97%) 9.00 <0.00> (ø)
...a/io/seata/tm/api/transaction/TransactionInfo.java 68.75% <33.33%> (-19.72%) 14.00 <2.00> (ø)
.../io/seata/core/context/GlobalLockConfigHolder.java 87.50% <87.50%> (ø) 4.00 <4.00> (?)
.../seata/rm/datasource/exec/LockRetryController.java 92.85% <94.11%> (+0.54%) 8.00 <5.00> (+4.00)
.../src/main/java/io/seata/rm/GlobalLockTemplate.java 100.00% <100.00%> (+25.00%) 5.00 <5.00> (+3.00)
...in/java/io/seata/tm/api/TransactionalTemplate.java 67.20% <100.00%> (+2.85%) 28.00 <3.00> (+3.00)
...java/io/seata/tm/api/transaction/RollbackRule.java 89.28% <0.00%> (-3.58%) 13.00% <0.00%> (-1.00%)
... and 1 more

@funky-eyes funky-eyes added first-time contributor first-time contributor RM Relate to seata rm labels Aug 3, 2020
int configInternal = config.getLockRetryInternal();
if (configInternal > 0) {
retryInternal = configInternal;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得加上else retryInternal=ConfigurationFactory.getInstance().getInt(ConfigurationKeys.CLIENT_LOCK_RETRY_INTERVAL, DEFAULT_CLIENT_LOCK_RETRY_INTERVAL);
可以在有本地的锁重试时,无序再去加载配置中心中的配置

Copy link
Contributor Author

Choose a reason for hiding this comment

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

有道理,我优化一下

int configTimes = config.getLockRetryTimes();
if (configTimes >= 0) {
retryTimes = configTimes;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

同上,改动后LOCK_RETRY_TIMES和LOCK_RETRY_TIMES 似乎就可以删除

@funky-eyes funky-eyes added this to the 1.4.0 milestone Aug 3, 2020
@funky-eyes funky-eyes added module/rm rm module and removed RM Relate to seata rm labels Aug 4, 2020
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

@wangliang181230
Copy link
Contributor

Please add the test.

final GlobalLock globalLockAnno) throws Throwable {
return globalLockTemplate.execute(new GlobalLockExecutor() {
@Override
public Object execute() throws Throwable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the try catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the old try-catch in fact do nothing, just to wrap a throwable as a RuntimeException, so that it can match the outer method signature(throws Exception~). Here i simplify the method signature(throws Throwable), thus it can save the catch and wrap process. Just like its "brother" method(handleGlobalTransaction).

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

private static int LOCK_RETRY_INTERNAL =
ConfigurationFactory.getInstance().getInt(ConfigurationKeys.CLIENT_LOCK_RETRY_INTERVAL, DEFAULT_CLIENT_LOCK_RETRY_INTERVAL);
private static int LOCK_RETRY_TIMES =
ConfigurationFactory.getInstance().getInt(ConfigurationKeys.CLIENT_LOCK_RETRY_TIMES, DEFAULT_CLIENT_LOCK_RETRY_TIMES);
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep this constants. Returns it in the get methods, if there is no customized config.

}
// if there is no customized config, use global config instead
Configuration configuration = ConfigurationFactory.getInstance();
return configuration.getInt(ConfigurationKeys.CLIENT_LOCK_RETRY_INTERVAL, DEFAULT_CLIENT_LOCK_RETRY_INTERVAL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Recovery LOCK_RETRY_INTERNAL, and returns LOCK_RETRY_INTERNAL.

}
// if there is no customized config, use global config instead
Configuration configuration = ConfigurationFactory.getInstance();
return configuration.getInt(ConfigurationKeys.CLIENT_LOCK_RETRY_TIMES, DEFAULT_CLIENT_LOCK_RETRY_TIMES);
Copy link
Contributor

Choose a reason for hiding this comment

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

Recovery LOCK_RETRY_TIMES, and returns LOCK_RETRY_TIMES.


private int globalLockRetryInternal;

private int globalLockRetryTimes;
Copy link
Contributor

Choose a reason for hiding this comment

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

volatile

}
}

private int parseInt(String value, int fallback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use the static method NumberUtils.toInt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i see it.

@@ -28,7 +32,7 @@
*/
public class LockRetryController {

private static final GlobalConfig globalConfig = new GlobalConfig();
private static GlobalConfig globalConfig = new GlobalConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

常量的变量名用大写就好,不要把final拿掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

问题不大,反正别的地方也改不了它

funky-eyes and others added 3 commits September 28, 2020 17:58
# Conflicts:
#	spring/src/main/java/io/seata/spring/annotation/GlobalTransactionalInterceptor.java
#	tm/src/main/java/io/seata/tm/api/TransactionalTemplate.java
@codecov-io
Copy link

codecov-io commented Oct 12, 2020

Codecov Report

Merging #2962 into develop will increase coverage by 0.09%.
The diff coverage is 78.16%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #2962      +/-   ##
=============================================
+ Coverage      50.40%   50.50%   +0.09%     
- Complexity      3123     3139      +16     
=============================================
  Files            594      596       +2     
  Lines          19698    19764      +66     
  Branches        2459     2466       +7     
=============================================
+ Hits            9929     9982      +53     
- Misses          8765     8780      +15     
+ Partials        1004     1002       -2     
Impacted Files Coverage Δ Complexity Δ
...ain/java/io/seata/core/model/GlobalLockConfig.java 14.28% <14.28%> (ø) 1.00 <1.00> (?)
...ing/annotation/GlobalTransactionalInterceptor.java 29.45% <33.33%> (+0.97%) 9.00 <0.00> (ø)
...a/io/seata/tm/api/transaction/TransactionInfo.java 68.75% <33.33%> (-19.72%) 14.00 <2.00> (ø)
.../io/seata/core/context/GlobalLockConfigHolder.java 87.50% <87.50%> (ø) 4.00 <4.00> (?)
.../seata/rm/datasource/exec/LockRetryController.java 92.85% <94.11%> (+0.54%) 8.00 <5.00> (+4.00)
.../src/main/java/io/seata/rm/GlobalLockTemplate.java 100.00% <100.00%> (+25.00%) 5.00 <5.00> (+3.00)
...ta/rm/datasource/exec/SelectForUpdateExecutor.java 82.00% <100.00%> (ø) 10.00 <0.00> (ø)
...in/java/io/seata/tm/api/TransactionalTemplate.java 63.84% <100.00%> (+3.01%) 28.00 <3.00> (+3.00)
...java/io/seata/tm/api/transaction/RollbackRule.java 89.28% <0.00%> (-3.58%) 13.00% <0.00%> (-1.00%)
... and 4 more

Copy link
Contributor

@wangliang181230 wangliang181230 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jsbxyyx jsbxyyx left a comment

Choose a reason for hiding this comment

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

LGTM for @wangliang181230

@funky-eyes funky-eyes changed the title optimize: @GlobalTransactional and @GlobalLock can now customize lock retry config (#2943) optimize: @GlobalTransactional and @GlobalLock can now customize lock retry config Oct 12, 2020
@funky-eyes funky-eyes merged commit 6c0c759 into apache:develop Oct 12, 2020
l81893521 pushed a commit to l81893521/seata that referenced this pull request Oct 22, 2020
Copy link
Contributor

@ls9527 ls9527 left a comment

Choose a reason for hiding this comment

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

随便问问, 啥也不影响

* note: 0 or negative number will take no effect(which mean fall back to global config)
* @return
*/
int lockRetryInternal() default 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

lockRetryInternal 是不是应该叫做 lockRetryInterval 。 是拼错了, 还是本来就是这个意思?

hicf pushed a commit to hicf/seata that referenced this pull request Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-time contributor first-time contributor module/rm rm module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimization of global lock contention cycle
8 participants