You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "qianye1001 (via GitHub)" <gi...@apache.org> on 2024/11/13 12:45:50 UTC
[PR] [ISSUE #8877] Refactor lock in ReceiptHandleGroup to make the lock can be properly released when future can not be completed. [rocketmq]
qianye1001 opened a new pull request, #8916:
URL: https://github.com/apache/rocketmq/pull/8916
<!-- Please make sure the target branch is right. In most case, the target branch should be `develop`. -->
### Which Issue(s) This PR Fixes
<!-- Please ensure that the related issue has already been created, and [link this pull request to that issue using keywords](<https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>) to ensure automatic closure. -->
Fixes #8877
### Brief Description
<!-- Write a brief description for your pull request to help the maintainer understand the reasons behind your changes. -->
### How Did You Test This Change?
<!-- In order to ensure the code quality of Apache RocketMQ, we expect every pull request to have undergone thorough testing. -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #8877] Refactor lock in ReceiptHandleGroup to make the lock can be properly released when future can not be completed. [rocketmq]
Posted by "fuyou001 (via GitHub)" <gi...@apache.org>.
fuyou001 commented on code in PR #8916:
URL: https://github.com/apache/rocketmq/pull/8916#discussion_r1841684301
##########
proxy/src/main/java/org/apache/rocketmq/proxy/common/ReceiptHandleGroup.java:
##########
@@ -98,22 +99,44 @@ public long getOffset() {
public static class HandleData {
private final Semaphore semaphore = new Semaphore(1);
+ private final AtomicLong lastLockTimeMs = new AtomicLong(-1L);
private volatile boolean needRemove = false;
private volatile MessageReceiptHandle messageReceiptHandle;
public HandleData(MessageReceiptHandle messageReceiptHandle) {
this.messageReceiptHandle = messageReceiptHandle;
}
- public boolean lock(long timeoutMs) {
+ public Long lock(long timeoutMs) {
try {
- return this.semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS);
+ boolean result = this.semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS);
+ long currentTimeMs = System.currentTimeMillis();
+ if (result) {
+ this.lastLockTimeMs.set(currentTimeMs);
+ return currentTimeMs;
+ } else {
+ // if the lock is expired, can be acquired again
+ long expiredTimeMs = ConfigurationManager.getProxyConfig().getLockTimeoutMsInHandleGroup() * 3;
+ if (currentTimeMs - this.lastLockTimeMs.get() > expiredTimeMs) {
+ synchronized (this) {
+ if (currentTimeMs - this.lastLockTimeMs.get() > expiredTimeMs) {
+ this.lastLockTimeMs.set(currentTimeMs);
+ return currentTimeMs;
+ }
+ }
+ }
+ }
+ return null;
} catch (InterruptedException e) {
- return false;
+ return null;
}
}
- public void unlock() {
+ public void unlock(long lockTimeMs) {
+ // if the lock is expired, we don't need to unlock it
+ if (System.currentTimeMillis() - lockTimeMs > ConfigurationManager.getProxyConfig().getLockTimeoutMsInHandleGroup() * 2) {
Review Comment:
add log
##########
proxy/src/main/java/org/apache/rocketmq/proxy/common/ReceiptHandleGroup.java:
##########
@@ -98,22 +99,44 @@ public long getOffset() {
public static class HandleData {
private final Semaphore semaphore = new Semaphore(1);
+ private final AtomicLong lastLockTimeMs = new AtomicLong(-1L);
private volatile boolean needRemove = false;
private volatile MessageReceiptHandle messageReceiptHandle;
public HandleData(MessageReceiptHandle messageReceiptHandle) {
this.messageReceiptHandle = messageReceiptHandle;
}
- public boolean lock(long timeoutMs) {
+ public Long lock(long timeoutMs) {
try {
- return this.semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS);
+ boolean result = this.semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS);
+ long currentTimeMs = System.currentTimeMillis();
+ if (result) {
+ this.lastLockTimeMs.set(currentTimeMs);
+ return currentTimeMs;
+ } else {
+ // if the lock is expired, can be acquired again
+ long expiredTimeMs = ConfigurationManager.getProxyConfig().getLockTimeoutMsInHandleGroup() * 3;
+ if (currentTimeMs - this.lastLockTimeMs.get() > expiredTimeMs) {
+ synchronized (this) {
Review Comment:
add log
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #8877] Refactor lock in ReceiptHandleGroup to make the lock can be properly released when future can not be completed. [rocketmq]
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins merged PR #8916:
URL: https://github.com/apache/rocketmq/pull/8916
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #8877] Refactor lock in ReceiptHandleGroup to make the lock can be properly released when future can not be completed. [rocketmq]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #8916:
URL: https://github.com/apache/rocketmq/pull/8916#issuecomment-2473588106
## [Codecov](https://app.codecov.io/gh/apache/rocketmq/pull/8916?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `44.82759%` with `16 lines` in your changes missing coverage. Please review.
> Project coverage is 47.55%. Comparing base [(`5600684`)](https://app.codecov.io/gh/apache/rocketmq/commit/5600684eb437dd5a4aeb9c658e24200bcb74909b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`4292756`)](https://app.codecov.io/gh/apache/rocketmq/commit/4292756632843522b792a8c97ff7890c351d361c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 7 commits behind head on develop.
| [Files with missing lines](https://app.codecov.io/gh/apache/rocketmq/pull/8916?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ache/rocketmq/proxy/common/ReceiptHandleGroup.java](https://app.codecov.io/gh/apache/rocketmq/pull/8916?src=pr&el=tree&filepath=proxy%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Frocketmq%2Fproxy%2Fcommon%2FReceiptHandleGroup.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHJveHkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3Byb3h5L2NvbW1vbi9SZWNlaXB0SGFuZGxlR3JvdXAuamF2YQ==) | 44.82% | [10 Missing and 6 partials :warning: ](https://app.codecov.io/gh/apache/rocketmq/pull/8916?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## develop #8916 +/- ##
=============================================
- Coverage 47.71% 47.55% -0.17%
+ Complexity 11763 11729 -34
=============================================
Files 1304 1304
Lines 91051 91077 +26
Branches 11675 11684 +9
=============================================
- Hits 43448 43310 -138
- Misses 42274 42418 +144
- Partials 5329 5349 +20
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/rocketmq/pull/8916?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ISSUE #8877] Refactor lock in ReceiptHandleGroup to make the lock can be properly released when future can not be completed. [rocketmq]
Posted by "dingshuangxi888 (via GitHub)" <gi...@apache.org>.
dingshuangxi888 commented on PR #8916:
URL: https://github.com/apache/rocketmq/pull/8916#issuecomment-2475327832
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org