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
6 changes: 5 additions & 1 deletion be/src/cloud/cloud_backend_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "load/stream_load/stream_load_context.h"
#include "load/stream_load/stream_load_recorder.h"
#include "util/brpc_client_cache.h" // BrpcClientCache
#include "util/stack_util.h"
#include "util/thrift_server.h"

namespace doris {
Expand Down Expand Up @@ -233,10 +234,13 @@ void CloudBackendService::_warm_up_cache(TWarmUpCacheAsyncResponse& response,
return;
}
PGetFileCacheMetaRequest brpc_request;
PGetFileCacheMetaResponse brpc_response;
std::stringstream ss;
for (int64_t tablet_id : request.tablet_ids) {
brpc_request.add_tablet_ids(tablet_id);
ss << tablet_id << ",";
}
VLOG_DEBUG << "tablets set: " << ss.str() << " stack: " << get_stack_trace();
PGetFileCacheMetaResponse brpc_response;

Status rpc_status = run_rpc_get_file_cache_meta(brpc_stub, brpc_addr, std::move(brpc_request),
brpc_response);
Expand Down
2 changes: 2 additions & 0 deletions be/src/cloud/cloud_tablet_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
TabletMap& tablet_map;
};

VLOG_DEBUG << "get_tablet tablet_id=" << tablet_id << " stack: " << get_stack_trace();

auto tablet_id_str = std::to_string(tablet_id);
CacheKey key(tablet_id_str);
auto* handle = _cache->lookup(key);
Expand Down
1 change: 1 addition & 0 deletions be/src/cloud/cloud_warm_up_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void CloudWarmUpManager::handle_jobs() {
std::make_shared<bthread::CountdownEvent>(0);

for (int64_t tablet_id : cur_job->tablet_ids) {
VLOG_DEBUG << "Warm up tablet " << tablet_id << " stack: " << get_stack_trace();
if (_cur_job_id == 0) { // The job is canceled
break;
}
Expand Down
36 changes: 29 additions & 7 deletions be/src/io/cache/block_file_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,9 @@ size_t BlockFileCache::try_release() {
std::lock_guard lc(cell->file_block->_mutex);
remove_size += file_block->range().size();
remove(file_block, cache_lock, lc);
VLOG_DEBUG << "try_release " << _cache_base_path
<< " hash=" << file_block->get_hash_value().to_string()
<< " offset=" << file_block->offset();
}
*_evict_by_try_release << remove_size;
LOG(INFO) << "Released " << trash.size() << " blocks in file cache " << _cache_base_path;
Expand Down Expand Up @@ -1076,12 +1079,16 @@ const LRUQueue& BlockFileCache::get_queue(FileCacheType type) const {
}

void BlockFileCache::remove_file_blocks(std::vector<FileBlockCell*>& to_evict,
std::lock_guard<std::mutex>& cache_lock, bool sync) {
std::lock_guard<std::mutex>& cache_lock, bool sync,
std::string& reason) {
auto remove_file_block_if = [&](FileBlockCell* cell) {
FileBlockSPtr file_block = cell->file_block;
if (file_block) {
std::lock_guard block_lock(file_block->_mutex);
remove(file_block, cache_lock, block_lock, sync);
VLOG_DEBUG << "remove_file_blocks"
<< " hash=" << file_block->get_hash_value().to_string()
<< " offset=" << file_block->offset() << " reason=" << reason;
}
};
std::for_each(to_evict.begin(), to_evict.end(), remove_file_block_if);
Expand Down Expand Up @@ -1242,6 +1249,7 @@ void BlockFileCache::try_evict_in_advance(size_t size, std::lock_guard<std::mute
// remove specific cache synchronously, for critical operations
// if in use, cache meta will be deleted after use and the block file is then deleted asynchronously
void BlockFileCache::remove_if_cached(const UInt128Wrapper& file_key) {
std::string reason = "remove_if_cached";
SCOPED_CACHE_LOCK(_mutex, this);
auto iter = _files.find(file_key);
std::vector<FileBlockCell*> to_remove;
Expand All @@ -1253,14 +1261,15 @@ void BlockFileCache::remove_if_cached(const UInt128Wrapper& file_key) {
cell.file_block->set_deleting();
}
}
remove_file_blocks(to_remove, cache_lock, true, reason);
}
remove_file_blocks(to_remove, cache_lock, true);
}

// the async version of remove_if_cached, for background operations
// cache meta is deleted synchronously if not in use, and the block file is deleted asynchronously
// if in use, cache meta will be deleted after use and the block file is then deleted asynchronously
void BlockFileCache::remove_if_cached_async(const UInt128Wrapper& file_key) {
std::string reason = "remove_if_cached_async";
SCOPED_CACHE_LOCK(_mutex, this);

auto iter = _files.find(file_key);
Expand All @@ -1275,8 +1284,8 @@ void BlockFileCache::remove_if_cached_async(const UInt128Wrapper& file_key) {
cell.file_block->set_deleting();
}
}
remove_file_blocks(to_remove, cache_lock, false, reason);
}
remove_file_blocks(to_remove, cache_lock, false);
}

std::vector<FileCacheType> BlockFileCache::get_other_cache_type_without_ttl(
Expand Down Expand Up @@ -1378,7 +1387,9 @@ bool BlockFileCache::try_reserve_from_other_queue_by_time_interval(
*(_evict_by_time_metrics_matrix[cache_type][cur_type]) << remove_size_per_type;
}
bool is_sync_removal = !evict_in_advance;
remove_file_blocks(to_evict, cache_lock, is_sync_removal);
std::string reason = std::string("try_reserve_by_time ") +
" evict_in_advance=" + (evict_in_advance ? "true" : "false");
remove_file_blocks(to_evict, cache_lock, is_sync_removal, reason);

return !is_overflow(removed_size, size, cur_cache_size, evict_in_advance);
}
Expand Down Expand Up @@ -1421,7 +1432,9 @@ bool BlockFileCache::try_reserve_from_other_queue_by_size(
*(_evict_by_size_metrics_matrix[cache_type][cur_type]) << cur_removed_size;
}
bool is_sync_removal = !evict_in_advance;
remove_file_blocks(to_evict, cache_lock, is_sync_removal);
std::string reason = std::string("try_reserve_by_size") +
" evict_in_advance=" + (evict_in_advance ? "true" : "false");
remove_file_blocks(to_evict, cache_lock, is_sync_removal, reason);
return !is_overflow(removed_size, size, cur_cache_size, evict_in_advance);
}

Expand Down Expand Up @@ -1468,7 +1481,10 @@ bool BlockFileCache::try_reserve_for_lru(const UInt128Wrapper& hash,
find_evict_candidates(queue, size, cur_cache_size, removed_size, to_evict, cache_lock,
cur_removed_size, evict_in_advance);
bool is_sync_removal = !evict_in_advance;
remove_file_blocks(to_evict, cache_lock, is_sync_removal);
std::string reason = std::string("try_reserve for cache type ") +
cache_type_to_string(context.cache_type) +
" evict_in_advance=" + (evict_in_advance ? "true" : "false");
remove_file_blocks(to_evict, cache_lock, is_sync_removal, reason);
*(_evict_by_self_lru_metrics_matrix[context.cache_type]) << cur_removed_size;

if (is_overflow(removed_size, size, cur_cache_size, evict_in_advance)) {
Expand Down Expand Up @@ -1534,6 +1550,11 @@ void BlockFileCache::remove(FileBlockSPtr file_block, T& cache_lock, U& block_lo
*_queue_evict_size_metrics[file_cache_type_index(file_block->cache_type())]
<< file_block->range().size();
*_total_evict_size_metrics << file_block->range().size();

VLOG_DEBUG << "Removing file block from cache. hash: " << hash.to_string()
<< ", offset: " << offset << ", size: " << file_block->range().size()
<< ", type: " << cache_type_to_string(type);

if (file_block->state_unlock(block_lock) == FileBlock::State::DOWNLOADED) {
FileCacheKey key;
key.hash = hash;
Expand Down Expand Up @@ -2246,7 +2267,8 @@ bool BlockFileCache::try_reserve_during_async_load(size_t size,
if (index_queue_size != 0) {
collect_eliminate_fragments(get_queue(FileCacheType::INDEX));
}
remove_file_blocks(to_evict, cache_lock, true);
std::string reason = "async load";
remove_file_blocks(to_evict, cache_lock, true, reason);

return !_disk_resource_limit_mode || removed_size >= size;
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/io/cache/block_file_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ class BlockFileCache {
bool is_overflow(size_t removed_size, size_t need_size, size_t cur_cache_size,
bool evict_in_advance) const;

void remove_file_blocks(std::vector<FileBlockCell*>&, std::lock_guard<std::mutex>&, bool sync);
void remove_file_blocks(std::vector<FileBlockCell*>&, std::lock_guard<std::mutex>&, bool sync,
std::string& reason);

void find_evict_candidates(LRUQueue& queue, size_t size, size_t cur_cache_size,
size_t& removed_size, std::vector<FileBlockCell*>& to_evict,
Expand Down
3 changes: 3 additions & 0 deletions be/src/io/fs/s3_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ Status S3FileReader::read_at_impl(size_t offset, Slice result, size_t* bytes_rea
size_t bytes_req = result.size;
char* to = result.data;
bytes_req = std::min(bytes_req, _file_size - offset);
VLOG_DEBUG << fmt::format("S3FileReader::read_at_impl offset={} size={} path={} hash={}",
offset, result.size, _path.native(),
io::BlockFileCache::hash(_path.native()).to_string());
VLOG_DEBUG << "enter s3 read_at_impl, off=" << offset << " n=" << bytes_req
<< " req=" << result.size << " file size=" << _file_size;
if (UNLIKELY(bytes_req == 0)) {
Expand Down
Loading