This is an automated email from the ASF dual-hosted git repository.

hellostephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 9dff1c7759c [ut](filecache) fix bvar::Window metrics use-after free 
(#59958)
9dff1c7759c is described below

commit 9dff1c7759c8e4cdea90c3fb8c0406a8326c85a3
Author: zhengyu <[email protected]>
AuthorDate: Mon Jan 19 14:39:45 2026 +0800

    [ut](filecache) fix bvar::Window metrics use-after free (#59958)
    
    Disable creation of these Window metrics for UT (keep only Adder/Status)
    to prevent sampling threads from being involved. Otherwise,
    BlockFileCache class can be destroyed before sampling threads join make
    it Use-After-Free.
---
 be/src/io/cache/block_file_cache.cpp | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/be/src/io/cache/block_file_cache.cpp 
b/be/src/io/cache/block_file_cache.cpp
index 135e87baa7b..97454a364ca 100644
--- a/be/src/io/cache/block_file_cache.cpp
+++ b/be/src/io/cache/block_file_cache.cpp
@@ -280,6 +280,12 @@ BlockFileCache::BlockFileCache(const std::string& 
cache_base_path,
     _num_removed_blocks = 
std::make_shared<bvar::Adder<size_t>>(_cache_base_path.c_str(),
                                                                 
"file_cache_num_removed_blocks");
 
+    _no_warmup_num_read_blocks = std::make_shared<bvar::Adder<size_t>>(
+            _cache_base_path.c_str(), "file_cache_no_warmup_num_read_blocks");
+    _no_warmup_num_hit_blocks = std::make_shared<bvar::Adder<size_t>>(
+            _cache_base_path.c_str(), "file_cache_no_warmup_num_hit_blocks");
+
+#ifndef BE_TEST
     _num_hit_blocks_5m = std::make_shared<bvar::Window<bvar::Adder<size_t>>>(
             _cache_base_path.c_str(), "file_cache_num_hit_blocks_5m", 
_num_hit_blocks.get(), 300);
     _num_read_blocks_5m = std::make_shared<bvar::Window<bvar::Adder<size_t>>>(
@@ -289,12 +295,6 @@ BlockFileCache::BlockFileCache(const std::string& 
cache_base_path,
     _num_read_blocks_1h = std::make_shared<bvar::Window<bvar::Adder<size_t>>>(
             _cache_base_path.c_str(), "file_cache_num_read_blocks_1h", 
_num_read_blocks.get(),
             3600);
-
-    _no_warmup_num_read_blocks = std::make_shared<bvar::Adder<size_t>>(
-            _cache_base_path.c_str(), "file_cache_no_warmup_num_read_blocks");
-    _no_warmup_num_hit_blocks = std::make_shared<bvar::Adder<size_t>>(
-            _cache_base_path.c_str(), "file_cache_no_warmup_num_hit_blocks");
-
     _no_warmup_num_hit_blocks_5m = 
std::make_shared<bvar::Window<bvar::Adder<size_t>>>(
             _cache_base_path.c_str(), "file_cache_no_warmup_num_hit_blocks_5m",
             _no_warmup_num_hit_blocks.get(), 300);
@@ -307,6 +307,7 @@ BlockFileCache::BlockFileCache(const std::string& 
cache_base_path,
     _no_warmup_num_read_blocks_1h = 
std::make_shared<bvar::Window<bvar::Adder<size_t>>>(
             _cache_base_path.c_str(), 
"file_cache_no_warmup_num_read_blocks_1h",
             _no_warmup_num_read_blocks.get(), 3600);
+#endif
 
     _hit_ratio = 
std::make_shared<bvar::Status<double>>(_cache_base_path.c_str(),
                                                         
"file_cache_hit_ratio", 0.0);
@@ -1967,11 +1968,11 @@ void BlockFileCache::run_background_monitor() {
                 _hit_ratio->set_value((double)_num_hit_blocks->get_value() /
                                       (double)_num_read_blocks->get_value());
             }
-            if (_num_read_blocks_5m->get_value() > 0) {
+            if (_num_read_blocks_5m && _num_read_blocks_5m->get_value() > 0) {
                 
_hit_ratio_5m->set_value((double)_num_hit_blocks_5m->get_value() /
                                          
(double)_num_read_blocks_5m->get_value());
             }
-            if (_num_read_blocks_1h->get_value() > 0) {
+            if (_num_read_blocks_1h && _num_read_blocks_1h->get_value() > 0) {
                 
_hit_ratio_1h->set_value((double)_num_hit_blocks_1h->get_value() /
                                          
(double)_num_read_blocks_1h->get_value());
             }
@@ -1980,12 +1981,12 @@ void BlockFileCache::run_background_monitor() {
                 
_no_warmup_hit_ratio->set_value((double)_no_warmup_num_hit_blocks->get_value() /
                                                 
(double)_no_warmup_num_read_blocks->get_value());
             }
-            if (_no_warmup_num_hit_blocks_5m->get_value() > 0) {
+            if (_no_warmup_num_hit_blocks_5m && 
_no_warmup_num_hit_blocks_5m->get_value() > 0) {
                 _no_warmup_hit_ratio_5m->set_value(
                         (double)_no_warmup_num_hit_blocks_5m->get_value() /
                         (double)_no_warmup_num_read_blocks_5m->get_value());
             }
-            if (_no_warmup_num_hit_blocks_1h->get_value() > 0) {
+            if (_no_warmup_num_hit_blocks_1h && 
_no_warmup_num_hit_blocks_1h->get_value() > 0) {
                 _no_warmup_hit_ratio_1h->set_value(
                         (double)_no_warmup_num_hit_blocks_1h->get_value() /
                         (double)_no_warmup_num_read_blocks_1h->get_value());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to