added read retry to s3 provider
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2023-11-11 21:04:21 -06:00
parent cc49536755
commit 4e62156b70
2 changed files with 55 additions and 31 deletions

View File

@ -983,37 +983,61 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
const auto object_name = const auto object_name =
utils::path::create_api_path(is_encrypted ? key : api_path); utils::path::create_api_path(is_encrypted ? key : api_path);
const auto read_bytes = [this, &cfg, &object_name, &stop_requested]( const auto read_bytes =
std::size_t read_size, std::size_t read_offset, [this, &api_path, &cfg, &object_name,
data_buffer &read_buffer) -> api_error { &stop_requested](std::size_t read_size, std::size_t read_offset,
curl::requests::http_get get{}; data_buffer &read_buffer) -> api_error {
get.aws_service = "aws:amz:" + cfg.region + ":s3"; auto res = api_error::error;
get.headers["response-content-type"] = "binary/octet-stream"; for (std::uint32_t i = 0U;
get.path = object_name; not stop_requested && res != api_error::success &&
get.range = {{ i < config_.get_retry_read_count() + 1U;
read_offset, i++) {
read_offset + read_size - 1U, curl::requests::http_get get{};
}}; get.aws_service = "aws:amz:" + cfg.region + ":s3";
get.response_handler = [&read_buffer](const data_buffer &response_data, get.headers["response-content-type"] = "binary/octet-stream";
long /*response_code*/) { get.path = object_name;
read_buffer = response_data; get.range = {{
}; read_offset,
read_offset + read_size - 1U,
}};
get.response_handler = [&read_buffer](const data_buffer &response_data,
long /*response_code*/) {
read_buffer = response_data;
};
long response_code{}; long response_code{};
if (not comm_.make_request(get, response_code, stop_requested)) { const auto notify_retry = [&]() {
return api_error::comm_error; if (response_code == 0) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
} else {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
}
std::this_thread::sleep_for(1s);
};
if (not comm_.make_request(get, response_code, stop_requested)) {
notify_retry();
continue;
}
if (response_code < http_error_codes::ok ||
response_code >= http_error_codes::multiple_choices) {
notify_retry();
continue;
}
res = api_error::success;
} }
if (response_code == http_error_codes::not_found) { return res;
return api_error::item_not_found;
}
if (response_code < http_error_codes::ok ||
response_code >= http_error_codes::multiple_choices) {
return api_error::comm_error;
}
return api_error::success;
}; };
if (is_encrypted) { if (is_encrypted) {

View File

@ -914,15 +914,15 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
i++) { i++) {
long response_code{}; long response_code{};
const auto notify_retry = [&]() { const auto notify_retry = [&]() {
if (response_code) { if (response_code == 0) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
__FUNCTION__, api_path, response_code, __FUNCTION__, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(offset) + "read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" + "|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(i + 1U));
} else { } else {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error, __FUNCTION__, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(offset) + "read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" + "|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(i + 1U));