Skip to content

Commit 75936dd

Browse files
authored
YQ-3013: add retry for CURLE_GOT_NOTHING for FQ (#3565)
1 parent 8a724ac commit 75936dd

File tree

5 files changed

+65
-27
lines changed

5 files changed

+65
-27
lines changed

ydb/core/fq/libs/init/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void Init(
195195

196196
if (protoConfig.GetPrivateApi().GetEnabled()) {
197197
const auto& s3readConfig = protoConfig.GetReadActorsFactoryConfig().GetS3ReadActorFactoryConfig();
198-
auto s3HttpRetryPolicy = NYql::GetHTTPDefaultRetryPolicy(TDuration::Max());
198+
auto s3HttpRetryPolicy = NYql::GetHTTPDefaultRetryPolicy(NYql::THttpRetryPolicyOptions{.MaxTime = TDuration::Max(), .RetriedCurlCodes = NYql::FqRetriedCurlCodes()});
199199
NYql::NDq::TS3ReadActorFactoryConfig readActorFactoryCfg;
200200
if (const ui64 rowsInBatch = s3readConfig.GetRowsInBatch()) {
201201
readActorFactoryCfg.RowsInBatch = rowsInBatch;

ydb/core/kqp/compute_actor/kqp_compute_actor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ NYql::NDq::IDqAsyncIoFactory::TPtr CreateKqpAsyncIoFactory(
7777
RegisterSequencerActorFactory(*factory, counters);
7878

7979
if (federatedQuerySetup) {
80-
RegisterS3ReadActorFactory(*factory, federatedQuerySetup->CredentialsFactory, federatedQuerySetup->HttpGateway);
81-
RegisterS3WriteActorFactory(*factory, federatedQuerySetup->CredentialsFactory, federatedQuerySetup->HttpGateway);
80+
auto s3HttpRetryPolicy = NYql::GetHTTPDefaultRetryPolicy(NYql::THttpRetryPolicyOptions{.RetriedCurlCodes = NYql::FqRetriedCurlCodes()});
81+
RegisterS3ReadActorFactory(*factory, federatedQuerySetup->CredentialsFactory, federatedQuerySetup->HttpGateway, s3HttpRetryPolicy);
82+
RegisterS3WriteActorFactory(*factory, federatedQuerySetup->CredentialsFactory, federatedQuerySetup->HttpGateway, s3HttpRetryPolicy);
8283

8384
if (federatedQuerySetup->ConnectorClient) {
8485
RegisterGenericProviderFactories(*factory, federatedQuerySetup->CredentialsFactory, federatedQuerySetup->ConnectorClient);

ydb/library/yql/providers/common/http_gateway/yql_http_default_retry_policy.cpp

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,50 @@
22

33
namespace NYql {
44

5-
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(TDuration maxTime, size_t maxRetries) {
5+
std::unordered_set<CURLcode> YqlRetriedCurlCodes() {
6+
return {
7+
CURLE_COULDNT_CONNECT,
8+
CURLE_WEIRD_SERVER_REPLY,
9+
CURLE_WRITE_ERROR,
10+
CURLE_READ_ERROR,
11+
CURLE_OPERATION_TIMEDOUT,
12+
CURLE_SSL_CONNECT_ERROR,
13+
CURLE_BAD_DOWNLOAD_RESUME,
14+
CURLE_SEND_ERROR,
15+
CURLE_RECV_ERROR,
16+
CURLE_NO_CONNECTION_AVAILABLE
17+
};
18+
}
19+
20+
std::unordered_set<CURLcode> FqRetriedCurlCodes() {
21+
return {
22+
CURLE_COULDNT_CONNECT,
23+
CURLE_WEIRD_SERVER_REPLY,
24+
CURLE_WRITE_ERROR,
25+
CURLE_READ_ERROR,
26+
CURLE_OPERATION_TIMEDOUT,
27+
CURLE_SSL_CONNECT_ERROR,
28+
CURLE_BAD_DOWNLOAD_RESUME,
29+
CURLE_SEND_ERROR,
30+
CURLE_RECV_ERROR,
31+
CURLE_NO_CONNECTION_AVAILABLE,
32+
CURLE_GOT_NOTHING
33+
};
34+
}
35+
36+
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(THttpRetryPolicyOptions&& options) {
37+
auto maxTime = options.MaxTime;
38+
auto maxRetries = options.MaxRetries;
639
if (!maxTime) {
740
maxTime = TDuration::Minutes(5);
841
}
9-
return IHTTPGateway::TRetryPolicy::GetExponentialBackoffPolicy([](CURLcode curlCode, long httpCode) {
10-
11-
switch (curlCode) {
12-
case CURLE_OK:
13-
// look to http code
14-
break;
15-
case CURLE_COULDNT_CONNECT:
16-
case CURLE_WEIRD_SERVER_REPLY:
17-
case CURLE_WRITE_ERROR:
18-
case CURLE_READ_ERROR:
19-
case CURLE_OPERATION_TIMEDOUT:
20-
case CURLE_SSL_CONNECT_ERROR:
21-
case CURLE_BAD_DOWNLOAD_RESUME:
22-
case CURLE_SEND_ERROR:
23-
case CURLE_RECV_ERROR:
24-
case CURLE_NO_CONNECTION_AVAILABLE:
25-
// retry small number of known errors
26-
return ERetryErrorClass::ShortRetry;
27-
default:
28-
// do not retry others
29-
return ERetryErrorClass::NoRetry;
42+
return IHTTPGateway::TRetryPolicy::GetExponentialBackoffPolicy([options = std::move(options)](CURLcode curlCode, long httpCode) {
43+
if (curlCode == CURLE_OK) {
44+
// pass
45+
} else if (options.RetriedCurlCodes.contains(curlCode)) {
46+
return ERetryErrorClass::ShortRetry;
47+
} else {
48+
return ERetryErrorClass::NoRetry;
3049
}
3150

3251
switch (httpCode) {
@@ -52,4 +71,8 @@ IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(TDuration maxTime, si
5271
maxTime); // maxTime
5372
}
5473

74+
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(TDuration maxTime, size_t maxRetries) {
75+
return GetHTTPDefaultRetryPolicy(THttpRetryPolicyOptions{.MaxTime = maxTime, .MaxRetries = maxRetries});
76+
}
77+
5578
}

ydb/library/yql/providers/common/http_gateway/yql_http_default_retry_policy.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22

33
#include "yql_http_gateway.h"
44

5+
#include <curl/curl.h>
6+
#include <unordered_set>
7+
58
namespace NYql {
69

7-
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(TDuration maxTime = TDuration::Zero(), size_t maxRetries = std::numeric_limits<size_t>::max()); // Zero means default maxTime
10+
std::unordered_set<CURLcode> YqlRetriedCurlCodes();
11+
std::unordered_set<CURLcode> FqRetriedCurlCodes();
12+
13+
struct THttpRetryPolicyOptions {
14+
TDuration MaxTime = TDuration::Zero(); // Zero means default maxTime
15+
size_t MaxRetries = std::numeric_limits<size_t>::max();
16+
std::unordered_set<CURLcode> RetriedCurlCodes = YqlRetriedCurlCodes();
17+
};
18+
19+
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(THttpRetryPolicyOptions&& options = {});
20+
21+
IHTTPGateway::TRetryPolicy::TPtr GetHTTPDefaultRetryPolicy(TDuration maxTime, size_t maxRetries = std::numeric_limits<size_t>::max()); // Zero means default maxTime
822

923
}

ydb/library/yql/providers/s3/actors/yql_s3_applicator_actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class TS3ApplicatorActor : public NActors::TActorBootstrapped<TS3ApplicatorActor
231231
, CredentialsFactory(credentialsFactory)
232232
, ExternalEffect(externalEffect)
233233
, ActorSystem(NActors::TActivationContext::ActorSystem())
234-
, RetryPolicy(NYql::GetHTTPDefaultRetryPolicy(TDuration::Zero(), 3))
234+
, RetryPolicy(NYql::GetHTTPDefaultRetryPolicy(NYql::THttpRetryPolicyOptions{.MaxRetries = 3, .RetriedCurlCodes = NYql::FqRetriedCurlCodes()}))
235235
, RetryCount(GLOBAL_RETRY_LIMIT) {
236236
// ^^^ 3 retries in HTTP GW per operation
237237
// up to 100 retries at app level for all operations ^^^

0 commit comments

Comments
 (0)