-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] Check the datacache usability before calling its function in case that the uninitialized members are called in some cases. #51158
[BugFix] Check the datacache usability before calling its function in case that the uninitialized members are called in some cases. #51158
Conversation
be/src/block_cache/block_cache.cpp
Outdated
if (_kv_cache) { | ||
return _kv_cache->engine_type(); | ||
} | ||
return DataCacheEngineType::STARCACHE; | ||
} | ||
|
||
void BlockCache::_refresh_quota() { |
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.
The most risky bug in this code is:
Accessing _kv_cache
without checking for its initialization state.
You can modify the code like this:
void BlockCache::record_read_remote(size_t size, int64_t latency_us) {
if (_kv_cache) {
_kv_cache->record_read_remote(size, latency_us);
}
}
const DataCacheMetrics BlockCache::cache_metrics(int level) const {
if (_kv_cache) {
return _kv_cache->cache_metrics(level);
}
DataCacheMetrics dummy_metrics;
return dummy_metrics;
}
void BlockCache::record_read_cache(size_t size, int64_t latency_us) {
if (_kv_cache) {
_kv_cache->record_read_cache(size, latency_us);
}
}
DataCacheEngineType BlockCache::engine_type() {
if (_kv_cache) {
return _kv_cache->engine_type();
}
return DataCacheEngineType::STARCACHE;
}
Make sure additional functions also properly check _kv_cache
before use to avoid potential issues.
be/src/block_cache/block_cache.cpp
Outdated
@@ -66,6 +66,9 @@ Status BlockCache::init(const CacheOptions& options) { | |||
|
|||
Status BlockCache::write_buffer(const CacheKey& cache_key, off_t offset, const IOBuffer& buffer, | |||
WriteCacheOptions* options) { | |||
if (!_kv_cache) { |
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.
Too many If
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.
Too many If
Changed it to check before calling datacache functions.
… case that the uninitialized members are called in some cases. Signed-off-by: GavinMar <[email protected]>
23712b9
to
5d1eba2
Compare
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]❌ fail : 0 / 1 (00.00%) file detail
|
… case that the uninitialized members are called in some cases. (backport #51158) (#51231) Signed-off-by: GavinMar <[email protected]>
… case that the uninitialized members are called in some cases. (StarRocks#51158) Signed-off-by: GavinMar <[email protected]> Signed-off-by: zhiminr.ren <[email protected]>
Why I'm doing:
Now we call datacache
update_mem_quota
functions to release the memory resource before coredump. However, in some cases, especially for unittests, the datacache instance may not be initialized, which cause an unintialized datacache instance is used and result in unexpected error.What I'm doing:
Check the datacache usability before calling its function.
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: