github-actions[bot] commented on code in PR #61083:
URL: https://github.com/apache/doris/pull/61083#discussion_r3316096792
##########
be/test/io/cache/block_file_cache_test_lru_dump.cpp:
##########
@@ -597,4 +597,111 @@ TEST_F(BlockFileCacheTest,
cached_remote_file_reader_direct_read_order_check) {
FileCacheFactory::instance()->_capacity = 0;
}
+TEST_F(BlockFileCacheTest, get_or_set_hit_order_check) {
+ std::string cache_base_path = caches_dir /
"cache_get_or_set_hit_order_check" / "";
+
+ const auto old_async_touch =
config::enable_file_cache_async_touch_on_get_or_set;
+ const auto old_update_interval_ms =
config::file_cache_background_block_lru_update_interval_ms;
+ const auto old_update_qps_limit =
config::file_cache_background_block_lru_update_qps_limit;
+ Defer defer {[old_async_touch, old_update_interval_ms,
old_update_qps_limit] {
+ config::enable_file_cache_async_touch_on_get_or_set = old_async_touch;
+ config::file_cache_background_block_lru_update_interval_ms =
old_update_interval_ms;
+ config::file_cache_background_block_lru_update_qps_limit =
old_update_qps_limit;
+ }};
+
+ config::enable_file_cache_async_touch_on_get_or_set = true;
+ config::file_cache_background_block_lru_update_interval_ms = 200;
+ config::file_cache_background_block_lru_update_qps_limit = 100000;
+
+ 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 = 6291456;
+ settings.query_queue_elements = 6;
+ settings.index_queue_size = 1048576;
+ settings.index_queue_elements = 1;
+ settings.disposable_queue_size = 1048576;
+ settings.disposable_queue_elements = 1;
+ settings.capacity = 8388608;
+ settings.max_file_block_size = 1048576;
+
+ io::BlockFileCache cache(cache_base_path, settings);
+ ASSERT_TRUE(cache.initialize());
+ for (int i = 0; i < 100; i++) {
+ if (cache.get_async_open_success()) {
+ break;
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ }
+ ASSERT_TRUE(cache.get_async_open_success());
+
+ io::CacheContext context;
+ ReadStatistics stats;
+ context.stats = &stats;
+ context.cache_type = io::FileCacheType::NORMAL;
+ context.query_id = query_id;
+
+ auto key = io::BlockFileCache::hash("get_or_set_hit_order_check_key");
+ constexpr size_t kBlockSize = 1024 * 1024;
+ std::vector<size_t> offsets {0, kBlockSize, 2 * kBlockSize};
+
+ for (size_t offset : offsets) {
+ auto holder = cache.get_or_set(key, offset, kBlockSize, context);
+ auto blocks = fromHolder(holder);
+ ASSERT_EQ(blocks.size(), 1);
+ ASSERT_TRUE(blocks[0]->get_or_set_downloader() ==
io::FileBlock::get_caller_id());
+ download_into_memory(blocks[0]);
+ ASSERT_EQ(blocks[0]->state(), io::FileBlock::State::DOWNLOADED);
+ }
+
+ std::vector<size_t> initial_offsets;
+ for (auto it = cache._normal_queue.begin(); it !=
cache._normal_queue.end(); ++it) {
+ initial_offsets.push_back(it->offset);
+ }
+ ASSERT_EQ(initial_offsets.size(), 3);
+ ASSERT_EQ(initial_offsets[0], 0);
+ ASSERT_EQ(initial_offsets[1], kBlockSize);
+ ASSERT_EQ(initial_offsets[2], 2 * kBlockSize);
+
+ auto holder = cache.get_or_set(key, 0, kBlockSize, context);
+ auto blocks = fromHolder(holder);
+ ASSERT_EQ(blocks.size(), 1);
+ ASSERT_EQ(blocks[0]->state(), io::FileBlock::State::DOWNLOADED);
+
+ std::vector<size_t> before_updated_offsets;
+ for (auto it = cache._normal_queue.begin(); it !=
cache._normal_queue.end(); ++it) {
+ before_updated_offsets.push_back(it->offset);
+ }
+ ASSERT_EQ(before_updated_offsets.size(), 3);
+ ASSERT_EQ(before_updated_offsets[0], 0);
+ ASSERT_EQ(before_updated_offsets[1], kBlockSize);
+ ASSERT_EQ(before_updated_offsets[2], 2 * kBlockSize);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(
Review Comment:
This assertion still depends on the background LRU thread waking and
draining within a fixed wall-clock sleep. On a busy CI host the thread can be
delayed past `2 * interval_ms`, leaving the queue unchanged and making
`updated_offsets.back()` fail even though the implementation is correct. This
is distinct from the existing lock-wait timing thread: here the flake is the
fixed sleep used to observe the async LRU worker. Please make this
deterministic, for example by polling until
`need_update_lru_blocks_size_unsafe() == 0`/the expected order with a timeout,
or by invoking/draining the LRU update path synchronously in the test.
##########
be/test/io/cache/cached_remote_file_reader_test.cpp:
##########
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "block_file_cache_test_common.h"
+
+namespace doris::io {
+
+TEST_F(BlockFileCacheTest,
+
direct_partial_hit_with_downloaded_remainder_should_not_read_remote_again) {
+ std::string local_cache_base_path =
+ caches_dir / "cache_direct_partial_downloaded_no_remote_read" / "";
+ config::enable_read_cache_file_directly = true;
+ if (fs::exists(local_cache_base_path)) {
+ fs::remove_all(local_cache_base_path);
+ }
+ fs::create_directories(local_cache_base_path);
+
+ TUniqueId query_id;
+ query_id.hi = 1;
+ query_id.lo = 1;
+
+ io::FileCacheSettings settings;
+ settings.query_queue_size = 6291456;
+ settings.query_queue_elements = 6;
+ settings.index_queue_size = 1048576;
+ settings.index_queue_elements = 1;
+ settings.disposable_queue_size = 1048576;
+ settings.disposable_queue_elements = 1;
+ settings.capacity = 8388608;
+ settings.max_file_block_size = 1048576;
+ settings.max_query_cache_size = 0;
+
+ io::CacheContext context;
+ ReadStatistics rstats;
+ context.stats = &rstats;
+ context.query_id = query_id;
+ ASSERT_TRUE(
+
FileCacheFactory::instance()->create_file_cache(local_cache_base_path,
settings).ok());
+
+ io::FileReaderOptions opts;
+ opts.cache_type = io::cache_type_from_string("file_block_cache");
+ opts.is_doris_table = true;
+ opts.tablet_id = 10086;
+
+ {
+ FileReaderSPtr local_reader;
+ ASSERT_TRUE(global_local_filesystem()->open_file(tmp_file,
&local_reader));
+ auto seed_reader =
std::make_shared<CachedRemoteFileReader>(local_reader, opts);
+ std::string buffer(64_kb, '\0');
+ IOContext io_ctx;
+ FileCacheStatistics stats;
+ io_ctx.file_cache_stats = &stats;
+ size_t bytes_read {0};
+ ASSERT_TRUE(
+ seed_reader->read_at(100, Slice(buffer.data(), buffer.size()),
&bytes_read, &io_ctx)
+ .ok());
+ EXPECT_EQ(bytes_read, 64_kb);
+ EXPECT_EQ(std::string(64_kb, '0'), buffer);
+ }
+
+ FileReaderSPtr stale_local_reader;
+ ASSERT_TRUE(global_local_filesystem()->open_file(tmp_file,
&stale_local_reader));
+ auto stale_reader =
std::make_shared<CachedRemoteFileReader>(stale_local_reader, opts);
+ EXPECT_EQ(stale_reader->_cache_file_readers.size(), 1);
+
+ {
+ FileReaderSPtr local_reader;
+ ASSERT_TRUE(global_local_filesystem()->open_file(tmp_file,
&local_reader));
+ auto updater_reader =
std::make_shared<CachedRemoteFileReader>(local_reader, opts);
+ std::string buffer(64_kb, '\0');
+ IOContext io_ctx;
+ FileCacheStatistics stats;
+ io_ctx.file_cache_stats = &stats;
+ size_t bytes_read {0};
+ ASSERT_TRUE(updater_reader
+ ->read_at(1_mb + 100, Slice(buffer.data(),
buffer.size()), &bytes_read,
+ &io_ctx)
+ .ok());
+ EXPECT_EQ(bytes_read, 64_kb);
+ EXPECT_EQ(std::string(64_kb, '1'), buffer);
+ }
+
+ EXPECT_EQ(stale_reader->_cache_file_readers.size(), 1);
+
+ std::string cross_block_buffer(64_kb, '\0');
+ IOContext io_ctx;
+ FileCacheStatistics stats;
+ io_ctx.file_cache_stats = &stats;
+ size_t bytes_read {0};
+ ASSERT_TRUE(stale_reader
+ ->read_at(1_mb - 100,
+ Slice(cross_block_buffer.data(),
cross_block_buffer.size()),
+ &bytes_read, &io_ctx)
+ .ok());
+ EXPECT_EQ(bytes_read, 64_kb);
+ EXPECT_EQ(std::string(100, '0') + std::string(64_kb - 100, '1'),
cross_block_buffer);
+ EXPECT_EQ(stats.bytes_read_from_remote, 0);
+
+ EXPECT_TRUE(stale_reader->close().ok());
+ EXPECT_TRUE(stale_reader->closed());
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ if (fs::exists(local_cache_base_path)) {
+ fs::remove_all(local_cache_base_path);
+ }
+ FileCacheFactory::instance()->_caches.clear();
+ FileCacheFactory::instance()->_path_to_cache.clear();
+ FileCacheFactory::instance()->_capacity = 0;
+ config::enable_read_cache_file_directly = false;
Review Comment:
This test changes the global `enable_read_cache_file_directly` flag but
restores it to `false` unconditionally. This PR changes the default to `true`,
so after this test runs, later BE cache tests in the same process execute with
a different direct-read mode than the PR default, and any early ASSERT before
this line also leaks the override. Please save the original value and restore
it with `Defer` at the point where the flag is changed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]