Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(bulk_load): redownload file if local file damaged #826

Merged
merged 3 commits into from
Apr 27, 2021
Merged
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
31 changes: 25 additions & 6 deletions src/replica/bulk_load/replica_bulk_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,31 @@ error_code replica_bulk_loader::download_sst_files(const std::string &remote_dir
remote_dir, local_dir, f_meta.name, fs, f_size);
const std::string &file_name =
utils::filesystem::path_combine(local_dir, f_meta.name);
if (ec == ERR_OK || ec == ERR_PATH_ALREADY_EXIST) {
if (!utils::filesystem::verify_file(file_name, f_meta.md5, f_meta.size)) {
ec = ERR_CORRUPTION;
} else if (ec == ERR_PATH_ALREADY_EXIST) {
bool verified = false;
if (ec == ERR_PATH_ALREADY_EXIST) {
if (utils::filesystem::verify_file(file_name, f_meta.md5, f_meta.size)) {
// local file exist and is verified
ec = ERR_OK;
f_size = f_meta.size;
verified = true;
} else {
derror_replica(
"file({}) exists, but not verified, try to remove local file "
"and redownload it",
file_name);
if (!utils::filesystem::remove_path(file_name)) {
derror_replica("failed to remove file({})", file_name);
ec = ERR_FILE_OPERATION_FAILED;
} else {
ec = _stub->_block_service_manager.download_file(
remote_dir, local_dir, f_meta.name, fs, f_size);
levy5307 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
if (ec == ERR_OK && !verified &&
!utils::filesystem::verify_file(file_name, f_meta.md5, f_meta.size)) {
ec = ERR_CORRUPTION;
}
if (ec != ERR_OK) {
try_decrease_bulk_load_download_count();
_download_status.store(ec);
Expand Down Expand Up @@ -485,8 +501,11 @@ void replica_bulk_loader::update_bulk_load_download_progress(uint64_t file_size,
const std::string &file_name)
{
if (_metadata.file_total_size <= 0) {
derror_replica("bulk_load_metadata has invalid file_total_size({})",
_metadata.file_total_size);
derror_replica("update downloading file({}) progress failed, metadata has invalid "
"file_total_size({}), current status = {}",
file_name,
_metadata.file_total_size,
enum_to_string(_status));
return;
}

Expand Down