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

morningman 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 9916324e9c [fix](FileCache) the logic of selecting the cache path is 
reversed (#24277)
9916324e9c is described below

commit 9916324e9ca7f801759bcdaf3e5f44bc9ae8c7b9
Author: Ashin Gau <ashin...@users.noreply.github.com>
AuthorDate: Wed Sep 13 13:25:07 2023 +0800

    [fix](FileCache) the logic of selecting the cache path is reversed (#24277)
    
    Bug was introduced by https://github.com/apache/doris/pull/23881/files
    The logic of selecting the cache path is reversed, and BE will be crashed 
when enable file cache.
---
 be/src/io/cache/block/cached_remote_file_reader.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/be/src/io/cache/block/cached_remote_file_reader.cpp 
b/be/src/io/cache/block/cached_remote_file_reader.cpp
index 86ecb14a75..4a23433086 100644
--- a/be/src/io/cache/block/cached_remote_file_reader.cpp
+++ b/be/src/io/cache/block/cached_remote_file_reader.cpp
@@ -52,7 +52,10 @@ 
CachedRemoteFileReader::CachedRemoteFileReader(FileReaderSPtr remote_file_reader
         // Use path and modification time to build cache key
         std::string unique_path = fmt::format("{}:{}", path().native(), 
opts.mtime);
         _cache_key = IFileCache::hash(unique_path);
-        if (!opts.cache_base_path.empty()) {
+        if (opts.cache_base_path.empty()) {
+            // if cache path is not specified by session variable, chose 
randomly.
+            _cache = FileCacheFactory::instance()->get_by_path(_cache_key);
+        } else {
             // from query session variable: file_cache_base_path
             _cache = 
FileCacheFactory::instance()->get_by_path(opts.cache_base_path);
             if (_cache == nullptr) {
@@ -61,7 +64,6 @@ CachedRemoteFileReader::CachedRemoteFileReader(FileReaderSPtr 
remote_file_reader
                 _cache = FileCacheFactory::instance()->get_by_path(_cache_key);
             }
         }
-        _cache = FileCacheFactory::instance()->get_by_path(path().native());
     }
 }
 
@@ -91,6 +93,7 @@ std::pair<size_t, size_t> 
CachedRemoteFileReader::_align_size(size_t offset,
 Status CachedRemoteFileReader::_read_from_cache(size_t offset, Slice result, 
size_t* bytes_read,
                                                 const IOContext* io_ctx) {
     size_t bytes_req = result.size;
+    bytes_req = std::min(bytes_req, size() - offset);
     ReadStatistics stats;
     auto [align_left, align_size] = _align_size(offset, bytes_req);
     CacheContext cache_context(io_ctx);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to