Skip to content

Commit f3b343f

Browse files
github-actions[bot]ypatiashaunrd0
authored
[Backport release-2.26] Enable curl error retries. (#5273) (#5275)
Backport of #5273 to release-2.26 --- TYPE: IMPROVEMENT DESC: Enable curl error retries. --------- Co-authored-by: Ypatia Tsavliri <[email protected]> Co-authored-by: Shaun M Reed <[email protected]>
1 parent f5934ea commit f3b343f

File tree

8 files changed

+357
-139
lines changed

8 files changed

+357
-139
lines changed

test/src/unit-capi-config.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ void check_save_to_file() {
228228
ss << "filestore.buffer_size 104857600\n";
229229
ss << "rest.capnp_traversal_limit 2147483648\n";
230230
ss << "rest.curl.buffer_size 524288\n";
231+
ss << "rest.curl.retry_errors true\n";
231232
ss << "rest.curl.verbose false\n";
232233
ss << "rest.http_compressor any\n";
233234
ss << "rest.load_enumerations_on_array_open false\n";
@@ -609,6 +610,7 @@ TEST_CASE("C API: Test config iter", "[capi][config]") {
609610
all_param_values["rest.retry_http_codes"] = "503";
610611
all_param_values["rest.capnp_traversal_limit"] = "2147483648";
611612
all_param_values["rest.curl.buffer_size"] = "524288";
613+
all_param_values["rest.curl.retry_errors"] = "true";
612614
all_param_values["rest.curl.verbose"] = "false";
613615
all_param_values["rest.load_metadata_on_array_open"] = "false";
614616
all_param_values["rest.load_non_empty_domain_on_array_open"] = "false";

test/src/unit-curl.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,40 @@ TEST_CASE(
182182
const auto& extra_headers = resources.rest_client()->extra_headers();
183183
CHECK(extra_headers.at("X-Payer") == "foo");
184184
}
185+
186+
TEST_CASE("Test retry logic", "[rest-client][retries]") {
187+
// set the HTTP codes to retry
188+
tiledb::sm::Config cfg;
189+
REQUIRE(cfg.set("rest.retry_http_codes", "503").ok());
190+
191+
std::unordered_map<std::string, std::string> extra_headers;
192+
std::unordered_map<std::string, std::string> res_headers;
193+
std::mutex res_mtx;
194+
Curl curl(tiledb::test::g_helper_logger());
195+
auto rc = curl.init(&cfg, extra_headers, &res_headers, &res_mtx);
196+
197+
// http error not in retry list
198+
CURLcode curl_code = CURLE_OK;
199+
long http_code = 504;
200+
REQUIRE(curl.should_retry_request(curl_code, http_code) == false);
201+
202+
// http error in retry list
203+
http_code = 503;
204+
REQUIRE(curl.should_retry_request(curl_code, http_code) == true);
205+
206+
// Curl error not in retry list
207+
curl_code = CURLE_SSL_SHUTDOWN_FAILED;
208+
REQUIRE(curl.should_retry_request(curl_code, http_code) == false);
209+
210+
// Curl error in retry list
211+
curl_code = CURLE_RECV_ERROR;
212+
// and http error not in retry list
213+
http_code = 504;
214+
REQUIRE(curl.should_retry_request(curl_code, http_code) == true);
215+
216+
// Curl error in retry list but retries disabled in config
217+
REQUIRE(cfg.set("rest.curl.retry_errors", "false").ok());
218+
rc = curl.init(&cfg, extra_headers, &res_headers, &res_mtx);
219+
curl_code = CURLE_RECV_ERROR;
220+
REQUIRE(curl.should_retry_request(curl_code, http_code) == false);
221+
}

tiledb/api/c_api/config/config_api_external.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ TILEDB_EXPORT void tiledb_config_free(tiledb_config_t** config) TILEDB_NOEXCEPT;
728728
* The delay factor to exponentially wait until further retries of a failed
729729
* REST request <br>
730730
* **Default**: 1.25
731+
* - `rest.curl.retry_errors` <br>
732+
* If true any curl requests that returned an error will be retried <br>
733+
* **Default**: true
731734
* - `rest.curl.verbose` <br>
732735
* Set curl to run in verbose mode for REST requests <br>
733736
* curl will print to stdout with this option

tiledb/sm/config/config.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const std::string Config::REST_RETRY_DELAY_FACTOR = "1.25";
9191
const std::string Config::REST_CURL_BUFFER_SIZE = "524288";
9292
const std::string Config::REST_CAPNP_TRAVERSAL_LIMIT = "2147483648";
9393
const std::string Config::REST_CURL_VERBOSE = "false";
94+
const std::string Config::REST_CURL_RETRY_ERRORS = "true";
9495
const std::string Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN = "false";
9596
const std::string Config::REST_LOAD_METADATA_ON_ARRAY_OPEN = "true";
9697
const std::string Config::REST_LOAD_NON_EMPTY_DOMAIN_ON_ARRAY_OPEN = "true";
@@ -256,6 +257,7 @@ const std::map<std::string, std::string> default_config_values = {
256257
std::make_pair(
257258
"rest.capnp_traversal_limit", Config::REST_CAPNP_TRAVERSAL_LIMIT),
258259
std::make_pair("rest.curl.verbose", Config::REST_CURL_VERBOSE),
260+
std::make_pair("rest.curl.retry_errors", Config::REST_CURL_RETRY_ERRORS),
259261
std::make_pair(
260262
"rest.load_enumerations_on_array_open",
261263
Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN),

tiledb/sm/config/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class Config {
110110
/** The default for Curl's verbose mode used by REST. */
111111
static const std::string REST_CURL_VERBOSE;
112112

113+
/** If we should retry Curl errors in requests to REST. */
114+
static const std::string REST_CURL_RETRY_ERRORS;
115+
113116
/** If the array enumerations should be loaded on array open */
114117
static const std::string REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN;
115118

tiledb/sm/cpp_api/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,9 @@ class Config {
903903
* The delay factor to exponentially wait until further retries of a failed
904904
* REST request <br>
905905
* **Default**: 1.25
906+
* - `rest.curl.retry_errors` <br>
907+
* If true any curl requests that returned an error will be retried <br>
908+
* **Default**: true
906909
* - `rest.curl.verbose` <br>
907910
* Set curl to run in verbose mode for REST requests <br>
908911
* curl will print to stdout with this option

0 commit comments

Comments
 (0)