github-actions[bot] commented on code in PR #37484: URL: https://github.com/apache/doris/pull/37484#discussion_r1668479631
########## be/src/io/cache/file_cache_common.cpp: ########## @@ -30,6 +30,7 @@ FileCacheSettings get_file_cache_settings(size_t capacity, size_t max_query_cach size_t normal_percent, size_t disposable_percent, size_t index_percent) { io::FileCacheSettings settings; + if (capacity == 0) return settings; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (capacity == 0) { return settings; } ``` ########## be/test/io/cache/block_file_cache_test.cpp: ########## @@ -4096,4 +4101,79 @@ TEST_F(BlockFileCacheTest, recyle_unvalid_ttl_async) { } } +TEST_F(BlockFileCacheTest, reset_capacity) { + if (fs::exists(cache_base_path)) { + fs::remove_all(cache_base_path); + } + fs::create_directories(cache_base_path); + TUniqueId query_id; + query_id.hi = 1; + query_id.lo = 1; + io::FileCacheSettings settings; + settings.query_queue_size = 30; + settings.query_queue_elements = 5; + settings.index_queue_size = 30; + settings.index_queue_elements = 5; + settings.disposable_queue_size = 30; + settings.disposable_queue_elements = 5; + settings.capacity = 90; + settings.max_file_block_size = 30; + settings.max_query_cache_size = 30; + io::CacheContext context; + context.query_id = query_id; + auto key = io::BlockFileCache::hash("key1"); + auto key2 = io::BlockFileCache::hash("key2"); + io::BlockFileCache cache(cache_base_path, settings); + auto sp = SyncPoint::get_instance(); Review Comment: warning: 'auto sp' can be declared as 'auto *sp' [readability-qualified-auto] ```suggestion s);auto * ``` ########## be/test/io/cache/block_file_cache_test.cpp: ########## @@ -4096,4 +4101,79 @@ } } +TEST_F(BlockFileCacheTest, reset_capacity) { + if (fs::exists(cache_base_path)) { + fs::remove_all(cache_base_path); + } + fs::create_directories(cache_base_path); + TUniqueId query_id; + query_id.hi = 1; + query_id.lo = 1; + io::FileCacheSettings settings; + settings.query_queue_size = 30; + settings.query_queue_elements = 5; + settings.index_queue_size = 30; + settings.index_queue_elements = 5; + settings.disposable_queue_size = 30; + settings.disposable_queue_elements = 5; + settings.capacity = 90; + settings.max_file_block_size = 30; + settings.max_query_cache_size = 30; + io::CacheContext context; + context.query_id = query_id; + auto key = io::BlockFileCache::hash("key1"); + auto key2 = io::BlockFileCache::hash("key2"); + io::BlockFileCache cache(cache_base_path, settings); + auto sp = SyncPoint::get_instance(); + Defer defer {[sp] { + sp->clear_call_back("BlockFileCache::set_remove_batch"); + sp->clear_call_back("BlockFileCache::set_sleep_time"); + }}; + sp->set_call_back("BlockFileCache::set_sleep_time", + [](auto&& args) { *try_any_cast<int64_t*>(args[0]) = 1; }); + sp->set_call_back("BlockFileCache::set_remove_batch", + [](auto&& args) { *try_any_cast<int*>(args[0]) = 2; }); + sp->enable_processing(); + ASSERT_TRUE(cache.initialize()); + for (int i = 0; i < 100; i++) { + if (cache.get_lazy_open_success()) { + break; + }; + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + for (int64_t offset = 0; offset < 45; offset += 5) { + context.cache_type = static_cast<io::FileCacheType>((offset / 5) % 3); + auto holder = cache.get_or_set(key, offset, 5, context); + auto segments = fromHolder(holder); + ASSERT_EQ(segments.size(), 1); + assert_range(1, segments[0], io::FileBlock::Range(offset, offset + 4), + io::FileBlock::State::EMPTY); + ASSERT_TRUE(segments[0]->get_or_set_downloader() == io::FileBlock::get_caller_id()); + download(segments[0]); + assert_range(1, segments[0], io::FileBlock::Range(offset, offset + 4), + io::FileBlock::State::DOWNLOADED); + } + context.cache_type = io::FileCacheType::TTL; + int64_t cur_time = UnixSeconds(); + context.expiration_time = cur_time + 120; + for (int64_t offset = 45; offset < 90; offset += 5) { + auto holder = cache.get_or_set(key2, offset, 5, context); + auto segments = fromHolder(holder); + ASSERT_EQ(segments.size(), 1); + assert_range(1, segments[0], io::FileBlock::Range(offset, offset + 4), + io::FileBlock::State::EMPTY); + ASSERT_TRUE(segments[0]->get_or_set_downloader() == io::FileBlock::get_caller_id()); + download(segments[0]); + assert_range(1, segments[0], io::FileBlock::Range(offset, offset + 4), + io::FileBlock::State::DOWNLOADED); + } + std::cout << cache.reset_capacity(30) << std::endl; + while (cache._async_clear_file_cache) + ; + EXPECT_EQ(cache._cur_cache_size, 30); Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion he) { ; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org