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
2 changes: 1 addition & 1 deletion be/src/io/cache/block_file_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ FileBlocks BlockFileCache::split_range_into_cells(const UInt128Wrapper& hash,
cell->update_atime();
}
}
if (_ttl_mgr && context.tablet_id != 0) {
if (_ttl_mgr && context.tablet_id > 0) {
_ttl_mgr->register_tablet_id(context.tablet_id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/io/cache/cached_remote_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ CachedRemoteFileReader::CachedRemoteFileReader(FileReaderSPtr remote_file_reader
: _is_doris_table(opts.is_doris_table),
_cache_align_mode(opts.align_mode),
_cache_write_mode(opts.cache_write_mode),
_tablet_id(opts.tablet_id),
_tablet_id(opts.is_doris_table ? opts.tablet_id : 0),
Comment thread
liaoxin01 marked this conversation as resolved.
_storage_resource_id(opts.storage_resource_id),
_remote_file_reader(std::move(remote_file_reader)) {
DCHECK(!_is_doris_table || _tablet_id > 0);
Expand Down Expand Up @@ -1078,6 +1078,7 @@ Status CachedRemoteFileReader::_read_from_indirect_cache(size_t offset, Slice re
s_align_size(offset + already_read, bytes_req - already_read, size());
CacheContext cache_context(io_ctx);
cache_context.stats = &stats;
cache_context.tablet_id = _tablet_id;
Comment thread
liaoxin01 marked this conversation as resolved.
Comment thread
liaoxin01 marked this conversation as resolved.
MonotonicStopWatch sw;
sw.start();
ConcurrencyStatsManager::instance().cached_remote_reader_get_or_set->increment();
Expand Down
50 changes: 50 additions & 0 deletions be/test/io/cache/cached_remote_file_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,56 @@ class AsyncCachedRemoteFileReaderTest : public BlockFileCacheTest {

} // namespace

TEST_F(AsyncCachedRemoteFileReaderTest, sync_write_path_preserves_tablet_id) {
create_cache("cached_remote_reader_sync_write_tablet_id");
auto reader = create_reader(open_remote_file());

std::string result(64_kb, '\0');
FileCacheStatistics stats;
IOContext context;
context.file_cache_stats = &stats;
context.is_warmup = true;
size_t bytes_read = 0;
ASSERT_TRUE(
reader->read_at(0, Slice(result.data(), result.size()), &bytes_read, &context).ok());
EXPECT_EQ(bytes_read, result.size());
EXPECT_EQ(result, std::string(result.size(), '0'));

const auto blocks = cache()->get_blocks_by_key(reader->_cache_hash);
ASSERT_EQ(blocks.size(), 1);
EXPECT_EQ(blocks.begin()->second->tablet_id(), 10086);
Comment thread
liaoxin01 marked this conversation as resolved.
}

TEST_F(AsyncCachedRemoteFileReaderTest, external_reader_normalizes_tablet_id_for_cache_writes) {
create_cache("cached_external_reader_tablet_id");
FileReaderOptions options;
options.cache_type = FileCachePolicy::FILE_BLOCK_CACHE;
auto reader = std::make_shared<CachedRemoteFileReader>(open_remote_file(), options);

std::string result(64_kb, '\0');
FileCacheStatistics stats;
IOContext context;
context.file_cache_stats = &stats;
context.is_warmup = true;
size_t bytes_read = 0;
ASSERT_TRUE(
reader->read_at(0, Slice(result.data(), result.size()), &bytes_read, &context).ok());
EXPECT_EQ(bytes_read, result.size());

context.is_warmup = false;
bytes_read = 0;
ASSERT_TRUE(
reader->read_at(1_mb, Slice(result.data(), result.size()), &bytes_read, &context).ok());
EXPECT_EQ(bytes_read, result.size());
wait_for_async_writes();

const auto blocks = cache()->get_blocks_by_key(reader->_cache_hash);
ASSERT_EQ(blocks.size(), 2);
for (const auto& [offset, block] : blocks) {
EXPECT_EQ(block->tablet_id(), 0) << "offset=" << offset;
}
}

TEST_F(AsyncCachedRemoteFileReaderTest, preallocated_cache_block_can_cover_the_short_file_tail) {
create_cache("cached_remote_reader_async_preallocated_file_tail");
auto counting_reader = std::make_shared<CountingFileReader>(open_remote_file());
Expand Down
Loading