You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "poorbarcode (via GitHub)" <gi...@apache.org> on 2023/12/26 12:03:28 UTC
[PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
poorbarcode opened a new pull request, #21804:
URL: https://github.com/apache/pulsar/pull/21804
### Motivation
**Context**
The previous PR is https://github.com/apache/pulsar/pull/21790
**Background of MemoryLimitController**
- When there is not enough memory to use, the method `MemoryLimitController.reserveMemory` will stuck until some memory is released<sup>[1]</sup>.
- After calling `MemoryLimitController.releaseMemory`, it would wake up all stuck threads.
**Issue**
- the method `tryReserveMemory`, `reserveMemory`, `forceReserveMemory` will also release the memory if it accepted a negative value, but it will not wake up the stuck threads. This would cause the stuck threads to remain stuck forever.
- https://github.com/apache/pulsar/pull/17936 used this method incorrectly and caused a Producer stuck bug that fixed by https://github.com/apache/pulsar/pull/21790.
We should add a check to prevent new PRs incorrectly used `tryReserveMemory`, `reserveMemory`, `forceReserveMemory`
#### Footnotes
**[1]**:
https://github.com/apache/pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java#L88
```java
if (!tryReserveMemory(size)) {
while (!tryReserveMemory(size)) {
condition.await();
}
}
```
### Modifications
Just like @lhotari's [suggestion](https://github.com/apache/pulsar/pull/21790#issuecomment-1869402727), add validation to prevent calling `tryReserveMemory`, `reserveMemory`, `forceReserveMemory` with a negative argument.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-coplete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository: x
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- commented on code in PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#discussion_r1436465094
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java:
##########
@@ -81,6 +100,10 @@ private void checkTrigger(long prevUsage, long newUsage) {
}
public void reserveMemory(long size) throws InterruptedException {
+ ensureReservedMemoryIsPositive(size);
Review Comment:
checkPositive
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode closed pull request #21804: [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck
URL: https://github.com/apache/pulsar/pull/21804
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "AnonHxy (via GitHub)" <gi...@apache.org>.
AnonHxy commented on code in PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#discussion_r1436452355
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java:
##########
@@ -68,6 +72,15 @@ public boolean tryReserveMemory(long size) {
}
}
+ private static void ensureReservedMemoryIsPositive(long reservedMemorySize) {
+ if (reservedMemorySize < 0) {
Review Comment:
Nit: Zero is not positive but can pass this method. So change to `reservedMemorySize <= 0` here or change the method name:)
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#issuecomment-1869636051
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/21804?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: `2 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`4bfc786`)](https://app.codecov.io/gh/apache/pulsar/commit/4bfc786ff1fc5a10e71844f11a101baeee93e40b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 73.07% compared to head [(`8544705`)](https://app.codecov.io/gh/apache/pulsar/pull/21804?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 73.54%.
> Report is 18 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/pulsar/pull/21804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #21804 +/- ##
============================================
+ Coverage 73.07% 73.54% +0.47%
+ Complexity 32573 32251 -322
============================================
Files 1897 1858 -39
Lines 140622 138040 -2582
Branches 15487 15116 -371
============================================
- Hits 102754 101528 -1226
+ Misses 29783 28645 -1138
+ Partials 8085 7867 -218
```
| [Flag](https://app.codecov.io/gh/apache/pulsar/pull/21804/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [inttests](https://app.codecov.io/gh/apache/pulsar/pull/21804/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `24.17% <47.36%> (-0.10%)` | :arrow_down: |
| [systests](https://app.codecov.io/gh/apache/pulsar/pull/21804/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `23.71% <63.15%> (-1.01%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pulsar/pull/21804/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `72.84% <89.47%> (+0.51%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files](https://app.codecov.io/gh/apache/pulsar/pull/21804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...ache/pulsar/client/impl/MemoryLimitController.java](https://app.codecov.io/gh/apache/pulsar/pull/21804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL01lbW9yeUxpbWl0Q29udHJvbGxlci5qYXZh) | `93.75% <89.47%> (-1.81%)` | :arrow_down: |
... and [181 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/21804/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari merged PR #21804:
URL: https://github.com/apache/pulsar/pull/21804
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#discussion_r1436457658
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java:
##########
@@ -68,6 +72,15 @@ public boolean tryReserveMemory(long size) {
}
}
+ private static void ensureReservedMemoryIsPositive(long reservedMemorySize) {
+ if (reservedMemorySize < 0) {
Review Comment:
Good suggestion, skipped all logic if the argument is `0`
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#discussion_r1436473235
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java:
##########
@@ -81,6 +100,10 @@ private void checkTrigger(long prevUsage, long newUsage) {
}
public void reserveMemory(long size) throws InterruptedException {
+ ensureReservedMemoryIsPositive(size);
Review Comment:
Done
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve] [client] Prevent reserve memory with a negative memory size to avoid send task stuck [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on PR #21804:
URL: https://github.com/apache/pulsar/pull/21804#issuecomment-1869522607
@lhotari
> I think that it would make sense to guard the release memory methods with a similar check that ensures that the value is positive.
Good suggestion. Added
--
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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org