GeezerVison is showing github.com — [fix][ml] Fix race conditions in RangeCache by lhotari · Pull Request #22789 · apache/pulsar
Conversation
lhotari
commented
May 28, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Motivation
The RangeCache class contains several race conditions which cause instability.
When one thread removes the entry and another one uses it, that will become a problem.
The cacheEvictionIntervalMs setting is 10 ms by default. This results in the
RangeCache.evictLEntriesBeforeTimestamp method getting called about 100 times per second.
The default expiration is managedLedgerCacheEvictionTimeThresholdMillis which is 1000 ms by default.
It's also possible that 2 threads remove the entry at the same time. ManagedLedgerImpl.invalidateEntriesUpToSlowestReaderPosition will result in calls to RangeCache.removeRange method. These calls happen independently of the RangeCache.evictLEntriesBeforeTimestamp calls so there's a chance for race conditions.
Modifications
- Add checks to validate that the value hasn't already been released before it is removed.
- add extra
.retain() and .release() calls
- add a way to validate that the value matches the key
- this is to prevent a possible race condition where the entry has already been recycled and contains another valid entry which is for a different key
- Make all removals using the
remove(key, value) method so that removals remove the correct value exactly once
- Add a wrapper object for the value to ensure this so that exact identity match is used for the removal.
- The wrapper instance is recycled to reduce the overhead.
Documentation
-
doc
-
doc-required
-
doc-not-needed
-
doc-complete
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 86.45833% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.27%. Comparing base (bbc6224) to head (2a6c2b1).
⚠️ Report is 1281 commits behind head on master.
Additional details and impacted files

@@ Coverage Diff @@
## master #22789 +/- ##
============================================
- Coverage 73.57% 73.27% -0.31%
- Complexity 32624 32648 +24
============================================
Files 1877 1889 +12
Lines 139502 141659 +2157
Branches 15299 15543 +244
============================================
+ Hits 102638 103800 +1162
- Misses 28908 29844 +936
- Partials 7956 8015 +59
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 367 files with indirect coverage changes
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Previous work in RangeCache to prevent race conditions: #15707 and #21302.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced May 31, 2024
|
This PR contained a few issues. I have a follow up PR #22814 to address the issues. Please review
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|