From 58a8ea473dc8f79f39798c5160b4d21cb504482b Mon Sep 17 00:00:00 2001 From: Guihao Liang Date: Fri, 10 Apr 2020 13:11:41 -0700 Subject: [PATCH] better retry (#3098) --- src/core/storage/fileio/s3_api.cpp | 4 ++-- src/core/storage/fileio/s3_api.hpp | 7 +++++-- test/fileio/s3_filesys_test.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/storage/fileio/s3_api.cpp b/src/core/storage/fileio/s3_api.cpp index e40d655f08..b8f1271c05 100644 --- a/src/core/storage/fileio/s3_api.cpp +++ b/src/core/storage/fileio/s3_api.cpp @@ -512,9 +512,9 @@ list_objects_response list_objects_impl(s3url parsed_url, std::string proxy, break; } else { - auto error = outcome.GetError().GetResponseCode(); + auto error = outcome.GetError(); - if (error == Aws::Http::HttpResponseCode::TOO_MANY_REQUESTS) { + if (error.ShouldRetry()) { n_retry++; if (n_retry == 3) { diff --git a/src/core/storage/fileio/s3_api.hpp b/src/core/storage/fileio/s3_api.hpp index 4b8cf5f876..011e34be71 100644 --- a/src/core/storage/fileio/s3_api.hpp +++ b/src/core/storage/fileio/s3_api.hpp @@ -286,11 +286,14 @@ std::ostream& reportS3Error(std::ostream& ss, const s3url& parsed_url, S3Operation::ops_enum operation, const Aws::Client::ClientConfiguration& config, const Response& outcome) { + auto error = outcome.GetError(); ss << "('" << parsed_url << ", proxy: '" << config.proxyHost << "', region: '" << config.region << "')" << " Error while performing " << S3Operation::toString(operation) - << ". Error Name: " << outcome.GetError().GetExceptionName() - << ". Error Message: " << outcome.GetError().GetMessage(); + << ". Error Name: " << error.GetExceptionName() + << ". Error Message: " << error.GetMessage() + << ". HTTP Error Code: " << static_cast(error.GetResponseCode()); + return ss; } diff --git a/test/fileio/s3_filesys_test.cpp b/test/fileio/s3_filesys_test.cpp index 259f4c3b39..1fdf2708ce 100644 --- a/test/fileio/s3_filesys_test.cpp +++ b/test/fileio/s3_filesys_test.cpp @@ -91,15 +91,15 @@ int main(int argc, char** argv) { // force write all entries sa_ptr->materialize(); - /* teardown manually */ - turi::file_download_cache::get_instance().clear(); - turi::block_cache::release_instance(); - } catch (std::string& e) { std::cerr << "Exception: " << e << std::endl; } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; } + /* teardown manually */ + turi::file_download_cache::get_instance().clear(); + turi::block_cache::release_instance(); + return 0; }