This is an automated email from the ASF dual-hosted git repository.

liaoxin01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 3750a819a2a [fix](be) Preserve tablet ID in synchronous file cache 
writes (#68310)
3750a819a2a is described below

commit 3750a819a2af157ad539d947bc301ff0f806b928
Author: Xin Liao <[email protected]>
AuthorDate: Tue Sep 22 00:07:41 2026 +0800

    [fix](be) Preserve tablet ID in synchronous file cache writes (#68310)
    
    The synchronous CachedRemoteFileReader path constructed CacheContext
    without copying the reader tablet ID. Cache misses were downloaded
    correctly, but newly created FileBlock and persisted block metadata used
    the no-tablet sentinel 0. Runtime per-tablet cache inspection and TTL
    registration therefore could not associate those new blocks with their
    Doris tablet.
    
    This change propagates the Doris tablet ID into the synchronous cache
    context. External readers are normalized to the existing no-tablet
    sentinel 0 for both synchronous and asynchronous writes, and TTL
    registration defensively accepts only positive tablet IDs.
    
    ### Release note
    
    Fix synchronous file cache blocks to retain their Doris tablet ID while
    preserving no-tablet metadata for external readers.
---
 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 a4c769ad9bb..33bb9cd1055 100644
--- a/be/src/io/cache/block_file_cache.cpp
+++ b/be/src/io/cache/block_file_cache.cpp
@@ -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);
             }
         }
diff --git a/be/src/io/cache/cached_remote_file_reader.cpp 
b/be/src/io/cache/cached_remote_file_reader.cpp
index da4d5c42a24..ef0c395b4c1 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);
@@ -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;
     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]

Reply via email to