This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 3669397d289 branch-4.1: [fix](be) Preserve tablet ID in synchronous
file cache writes #68310 (#68347)
3669397d289 is described below
commit 3669397d289eb7ec4c609d19a1f95a07893e7ff4
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 23 08:34:43 2026 +0800
branch-4.1: [fix](be) Preserve tablet ID in synchronous file cache writes
#68310 (#68347)
Cherry-picked from #68310
Co-authored-by: Xin Liao <[email protected]>
---
be/src/io/cache/block_file_cache.cpp | 2 +-
be/src/io/cache/cached_remote_file_reader.cpp | 3 +-
.../io/cache/cached_remote_file_reader_test.cpp | 50 ++++++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/be/src/io/cache/block_file_cache.cpp
b/be/src/io/cache/block_file_cache.cpp
index 5d8b7d230cd..f78fe10ef41 100644
--- a/be/src/io/cache/block_file_cache.cpp
+++ b/be/src/io/cache/block_file_cache.cpp
@@ -1107,7 +1107,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);
}
}
diff --git a/be/src/io/cache/cached_remote_file_reader.cpp
b/be/src/io/cache/cached_remote_file_reader.cpp
index 4b33f976bd3..0d0a0dbf3cb 100644
--- a/be/src/io/cache/cached_remote_file_reader.cpp
+++ b/be/src/io/cache/cached_remote_file_reader.cpp
@@ -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),
_storage_resource_id(opts.storage_resource_id),
_remote_file_reader(std::move(remote_file_reader)) {
DCHECK(!_is_doris_table || _tablet_id > 0);
@@ -1065,6 +1065,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;
MonotonicStopWatch sw;
sw.start();
ConcurrencyStatsManager::instance().cached_remote_reader_get_or_set->increment();
diff --git a/be/test/io/cache/cached_remote_file_reader_test.cpp
b/be/test/io/cache/cached_remote_file_reader_test.cpp
index a64fe685bfb..6fe9bac5d60 100644
--- a/be/test/io/cache/cached_remote_file_reader_test.cpp
+++ b/be/test/io/cache/cached_remote_file_reader_test.cpp
@@ -178,6 +178,56 @@ private:
} // 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);
+}
+
+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());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]