Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debug](FileCache) fail over to remote file reader if local cache failed #24097

Merged
merged 1 commit into from
Sep 10, 2023
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
1 change: 1 addition & 0 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ DEFINE_Validator(file_cache_min_file_segment_size, [](const int64_t config) -> b
});
DEFINE_Bool(clear_file_cache, "false");
DEFINE_Bool(enable_file_cache_query_limit, "false");
DEFINE_mInt32(file_cache_wait_sec_after_fail, "0"); // // zero for no waiting and retrying

DEFINE_mInt32(index_cache_entry_stay_time_after_lookup_s, "1800");
DEFINE_mInt32(inverted_index_cache_stale_sweep_time_sec, "600");
Expand Down
2 changes: 2 additions & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ DECLARE_Int64(file_cache_min_file_segment_size);
DECLARE_Int64(file_cache_max_file_segment_size);
DECLARE_Bool(clear_file_cache);
DECLARE_Bool(enable_file_cache_query_limit);
// only for debug, will be removed after finding out the root cause
DECLARE_mInt32(file_cache_wait_sec_after_fail); // zero for no waiting and retrying

// inverted index searcher cache
// cache entry stay time after lookup
Expand Down
51 changes: 37 additions & 14 deletions be/src/io/cache/block/cached_remote_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,9 @@ std::pair<size_t, size_t> CachedRemoteFileReader::_align_size(size_t offset,
return std::make_pair(align_left, align_size);
}

Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t* bytes_read,
const IOContext* io_ctx) {
DCHECK(!closed());
DCHECK(io_ctx);
if (offset > size()) {
return Status::IOError(
fmt::format("offset exceeds file size(offset: {), file size: {}, path: {})", offset,
size(), path().native()));
}
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);
if (UNLIKELY(bytes_req == 0)) {
*bytes_read = 0;
return Status::OK();
}
ReadStatistics stats;
auto [align_left, align_size] = _align_size(offset, bytes_req);
CacheContext cache_context(io_ctx);
Expand Down Expand Up @@ -224,6 +212,41 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
return Status::OK();
}

Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t* bytes_read,
const IOContext* io_ctx) {
DCHECK(!closed());
DCHECK(io_ctx);
if (offset > size()) {
return Status::IOError(
fmt::format("offset exceeds file size(offset: {), file size: {}, path: {})", offset,
size(), path().native()));
}
size_t bytes_req = result.size;
bytes_req = std::min(bytes_req, size() - offset);
if (UNLIKELY(bytes_req == 0)) {
*bytes_read = 0;
return Status::OK();
}
Status cache_st = _read_from_cache(offset, result, bytes_read, io_ctx);
if (UNLIKELY(!cache_st.ok())) {
if (config::file_cache_wait_sec_after_fail > 0) {
// only for debug, wait and retry to load data from file cache
// return error if failed again
LOG(WARNING) << "Failed to read data from file cache, and wait "
<< config::file_cache_wait_sec_after_fail
<< " seconds to reload data: " << cache_st.to_string();
sleep(config::file_cache_wait_sec_after_fail);
cache_st = _read_from_cache(offset, result, bytes_read, io_ctx);
} else {
// fail over to remote file reader, and return the status of remote read
LOG(WARNING) << "Failed to read data from file cache, and fail over to remote file: "
<< cache_st.to_string();
return _remote_file_reader->read_at(offset, result, bytes_read, io_ctx);
}
}
return cache_st;
}

void CachedRemoteFileReader::_update_state(const ReadStatistics& read_stats,
FileCacheStatistics* statis) const {
if (statis == nullptr) {
Expand Down
3 changes: 3 additions & 0 deletions be/src/io/cache/block/cached_remote_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class CachedRemoteFileReader final : public FileReader {
int64_t local_write_timer = 0;
};
void _update_state(const ReadStatistics& stats, FileCacheStatistics* state) const;

Status _read_from_cache(size_t offset, Slice result, size_t* bytes_read,
const IOContext* io_ctx);
};

} // namespace io
Expand Down