fix: Allocate TaggedCache::getKeys() memory outside of lock#7567
Open
ximinez wants to merge 3 commits into
Open
fix: Allocate TaggedCache::getKeys() memory outside of lock#7567ximinez wants to merge 3 commits into
ximinez wants to merge 3 commits into
Conversation
- Uses a loop in case the size grows while the lock is free. Guarantees the result vector will not need to allocate under lock.
Co-authored-by: xrplf-ai-reviewer[bot] <266832837+xrplf-ai-reviewer[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7567 +/- ##
=======================================
Coverage 82.0% 82.0%
=======================================
Files 1007 1007
Lines 76876 76880 +4
Branches 8981 8981
=======================================
+ Hits 63001 63005 +4
Misses 13866 13866
Partials 9 9
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
High Level Overview of Change
Moves the allocation of storage for the keys vector in
TaggedCache::getKeys()outside of lock. Because the size of the cache may change while allocating, uses a loop to check (under lock) that the capacity is sufficient before filling.Context of Change
Aside from the fact that allocating memory under a lock is almost always Wrong, there is the specific potential for excess lock contention if a given cache is very large at the time that
getKeys()is called. Such an allocation could take a significant amount of time, causing other threads to stall waiting for it.The primary consumer of
getKeys()is online_delete database rotation, which is supposed to be a lower priority than most other functions, deferring if they fall behind. (See also #5531.)