From 9d31610c4283a4b4afa79716e16028d6ab894e73 Mon Sep 17 00:00:00 2001 From: Lchangliang <915311741@qq.com> Date: Mon, 8 Jul 2024 19:37:33 +0800 Subject: [PATCH 1/2] (cloud-merge) Fix index data cannot be writed into ttl dir --- be/src/io/cache/block_file_cache.cpp | 7 ++++++- be/src/io/cache/block_file_cache.h | 2 +- be/src/io/cache/cached_remote_file_reader.cpp | 2 +- be/test/io/cache/block_file_cache_test.cpp | 17 +++++++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/be/src/io/cache/block_file_cache.cpp b/be/src/io/cache/block_file_cache.cpp index 05bbaa69adc2c8..73c247b6f3aebb 100644 --- a/be/src/io/cache/block_file_cache.cpp +++ b/be/src/io/cache/block_file_cache.cpp @@ -619,10 +619,15 @@ void BlockFileCache::fill_holes_with_empty_file_blocks(FileBlocks& file_blocks, } FileBlocksHolder BlockFileCache::get_or_set(const UInt128Wrapper& hash, size_t offset, size_t size, - const CacheContext& context) { + CacheContext& context) { FileBlock::Range range(offset, offset + size - 1); std::lock_guard cache_lock(_mutex); + if (auto iter = _key_to_time.find(hash); + context.cache_type == FileCacheType::INDEX && iter != _key_to_time.end()) { + context.cache_type = FileCacheType::TTL; + context.expiration_time = iter->second; + } /// Get all blocks which intersect with the given range. auto file_blocks = get_impl(hash, context, range, cache_lock); diff --git a/be/src/io/cache/block_file_cache.h b/be/src/io/cache/block_file_cache.h index 86ce1dc1196c39..00ca40ec74ae7b 100644 --- a/be/src/io/cache/block_file_cache.h +++ b/be/src/io/cache/block_file_cache.h @@ -86,7 +86,7 @@ class BlockFileCache { * it is guaranteed that these file blocks are not removed from cache. */ FileBlocksHolder get_or_set(const UInt128Wrapper& hash, size_t offset, size_t size, - const CacheContext& context); + CacheContext& context); /** * Clear all cached data for this cache instance async diff --git a/be/src/io/cache/cached_remote_file_reader.cpp b/be/src/io/cache/cached_remote_file_reader.cpp index 9572180c8926ba..493e56411c5062 100644 --- a/be/src/io/cache/cached_remote_file_reader.cpp +++ b/be/src/io/cache/cached_remote_file_reader.cpp @@ -222,7 +222,7 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t* st = block->finalize(); } if (!st.ok()) { - LOG_WARNING("Write data to file cache failed").error(st); + LOG_EVERY_N(WARNING, 100) << "Write data to file cache failed. err=" << st.msg(); } else { _insert_file_reader(block); } diff --git a/be/test/io/cache/block_file_cache_test.cpp b/be/test/io/cache/block_file_cache_test.cpp index 919680f1c16b95..d0675f77945de3 100644 --- a/be/test/io/cache/block_file_cache_test.cpp +++ b/be/test/io/cache/block_file_cache_test.cpp @@ -1554,9 +1554,9 @@ TEST_F(BlockFileCacheTest, ttl_normal) { query_id.hi = 1; query_id.lo = 1; io::FileCacheSettings settings; - settings.query_queue_size = 30; + settings.query_queue_size = 50; settings.query_queue_elements = 5; - settings.capacity = 30; + settings.capacity = 50; settings.max_file_block_size = 30; settings.max_query_cache_size = 30; io::CacheContext context; @@ -1595,6 +1595,19 @@ TEST_F(BlockFileCacheTest, ttl_normal) { assert_range(1, blocks[0], io::FileBlock::Range(50, 59), io::FileBlock::State::DOWNLOADED); EXPECT_EQ(blocks[0]->cache_type(), io::FileCacheType::TTL); } + { + context.cache_type = io::FileCacheType::INDEX; + context.expiration_time = 0; + auto holder = cache.get_or_set(key2, 60, 10, context); /// Add range [60, 69] + auto blocks = fromHolder(holder); + ASSERT_EQ(blocks.size(), 1); + assert_range(1, blocks[0], io::FileBlock::Range(60, 69), io::FileBlock::State::EMPTY); + ASSERT_TRUE(blocks[0]->get_or_set_downloader() == io::FileBlock::get_caller_id()); + download(blocks[0]); + assert_range(1, blocks[0], io::FileBlock::Range(60, 69), + io::FileBlock::State::DOWNLOADED); + EXPECT_EQ(blocks[0]->cache_type(), io::FileCacheType::TTL); + } { cache.modify_expiration_time(key2, modify_time); context.expiration_time = modify_time; From e32ca88238c0105f65f896f5edfbeb259539fc4a Mon Sep 17 00:00:00 2001 From: Lchangliang <915311741@qq.com> Date: Mon, 8 Jul 2024 19:51:04 +0800 Subject: [PATCH 2/2] tmp --- be/test/io/cache/block_file_cache_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/be/test/io/cache/block_file_cache_test.cpp b/be/test/io/cache/block_file_cache_test.cpp index d0675f77945de3..a81aa22d433688 100644 --- a/be/test/io/cache/block_file_cache_test.cpp +++ b/be/test/io/cache/block_file_cache_test.cpp @@ -1604,8 +1604,7 @@ TEST_F(BlockFileCacheTest, ttl_normal) { assert_range(1, blocks[0], io::FileBlock::Range(60, 69), io::FileBlock::State::EMPTY); ASSERT_TRUE(blocks[0]->get_or_set_downloader() == io::FileBlock::get_caller_id()); download(blocks[0]); - assert_range(1, blocks[0], io::FileBlock::Range(60, 69), - io::FileBlock::State::DOWNLOADED); + assert_range(1, blocks[0], io::FileBlock::Range(60, 69), io::FileBlock::State::DOWNLOADED); EXPECT_EQ(blocks[0]->cache_type(), io::FileCacheType::TTL); } {