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 =
utils::path::create_api_path(is_encrypted ? key : api_path);
const auto read_bytes = [this, &cfg, &object_name, &stop_requested](
std::size_t read_size, std::size_t read_offset,
data_buffer &read_buffer) -> api_error {
curl::requests::http_get get{};
get.aws_service = "aws:amz:" + cfg.region + ":s3";
get.headers["response-content-type"] = "binary/octet-stream";
get.path = object_name;
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;
};
const auto read_bytes =
[this, &api_path, &cfg, &object_name,
&stop_requested](std::size_t read_size, std::size_t read_offset,
data_buffer &read_buffer) -> api_error {
auto res = api_error::error;
for (std::uint32_t i = 0U;
not stop_requested && res != api_error::success &&
i < config_.get_retry_read_count() + 1U;
i++) {
curl::requests::http_get get{};
get.aws_service = "aws:amz:" + cfg.region + ":s3";
get.headers["response-content-type"] = "binary/octet-stream";
get.path = object_name;
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{};
if (not comm_.make_request(get, response_code, stop_requested)) {
return api_error::comm_error;
long response_code{};
const auto notify_retry = [&]() {
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 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;
return res;
};
if (is_encrypted) {

View File

@ -914,15 +914,15 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
i++) {
long response_code{};
const auto notify_retry = [&]() {
if (response_code) {
if (response_code == 0) {
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) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));
} else {
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) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));