Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion be/src/io/cache/block_file_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion be/src/io/cache/block_file_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion be/src/io/cache/cached_remote_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 14 additions & 2 deletions be/test/io/cache/block_file_cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1595,6 +1595,18 @@ 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;
Expand Down