[BugFix] fix MetdataCache concurrency issue #52968
Open
+53
−11
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.
Why I'm doing:
In previous PR, we introduced
MetadataCache
to achieve LRU strategy for rowset metadata memory manage, and when rowset been evict, then we will call this function:to close rowset and release metadata memory.
But in some case, this rowset which pointer point to could has been destroy, but
_cache_value_deleter
doesn't know that and will still keep callingclose()
, and it will lead to concurrency issue.What I'm doing:
This pull request includes several changes to the
MetadataCache
class and related functionality in therowset
module. The main goals are to improve memory management by usingstd::weak_ptr
for cached rowsets and to rename thewarmup_rowset
method torefresh_rowset
for clarity. Additionally, a new concurrency test is added to ensure thread safety.Memory management improvements:
be/src/storage/rowset/metadata_cache.cpp
: ChangedMetadataCache::cache_rowset
to usestd::weak_ptr<Rowset>
for better memory management and updated the_insert
method accordingly. [1] [2]be/src/storage/rowset/metadata_cache.cpp
: Modified_cache_value_deleter
to handlestd::weak_ptr<Rowset>
and ensure proper cleanup of cached rowsets.Method renaming for clarity:
be/src/storage/rowset/metadata_cache.cpp
andbe/src/storage/rowset/metadata_cache.h
: Renamedwarmup_rowset
torefresh_rowset
to better reflect its purpose. [1] [2] [3]be/src/storage/rowset/rowset.cpp
: Updated calls towarmup_rowset
to use the newrefresh_rowset
method.be/test/storage/rowset/metadata_cache_test.cpp
: Updated test cases to userefresh_rowset
instead ofwarmup_rowset
. [1] [2]New test for concurrency:
be/test/storage/rowset/metadata_cache_test.cpp
: Added a new testtest_concurrency_issue
to verify the thread safety of theMetadataCache
when caching rowsets concurrently.What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: