Skip to content

Commit

Permalink
[fix](FileCache) the logic of selecting the cache path is reversed (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
AshinGau authored Sep 13, 2023
1 parent f985b28 commit 9916324
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions be/src/io/cache/block/cached_remote_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9916324

Please sign in to comment.