Change default retry count to 3, to avoid misleading people into thinking the program hangs

This commit is contained in:
Jinming Hu 2020-03-03 23:17:26 +08:00 коммит произвёл Vincent Jiang (LEI)
Родитель 2f95fb0af3
Коммит 4486a450dc
2 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@ -46,6 +46,11 @@ namespace azure { namespace storage_lite {
return m_retry_policy;
}
void set_retry_policy(std::shared_ptr<retry_policy_base> retry_policy)
{
m_retry_policy = std::move(retry_policy);
}
private:
std::shared_ptr<xml_parser_base> m_xml_parser;
std::shared_ptr<json_parser_base> m_json_parser;
@ -68,7 +73,7 @@ namespace azure { namespace storage_lite {
http->set_error_stream([](http_base::http_code) { return true; }, storage_iostream::create_storage_stream());
request->build_request(*account, *http);
retry_info info = context->retry_policy()->evaluate(*retry);
retry_info info = retry->numbers() == 0 ? retry_info(true, std::chrono::seconds(0)) : context->retry_policy()->evaluate(*retry);
if (info.should_retry())
{
http->submit([promise, outcome, account, request, http, context, retry](http_base::http_code result, storage_istream s, CURLcode code)
@ -143,7 +148,7 @@ namespace azure { namespace storage_lite {
http->set_error_stream(unsuccessful, storage_iostream::create_storage_stream());
request->build_request(*account, *http);
retry_info info = context->retry_policy()->evaluate(*retry);
retry_info info = retry->numbers() == 0 ? retry_info(true, std::chrono::seconds(0)) : context->retry_policy()->evaluate(*retry);
if (info.should_retry())
{
http->submit([promise, outcome, account, request, http, context, retry](http_base::http_code result, storage_istream s, CURLcode code)

Просмотреть файл

@ -75,22 +75,17 @@ namespace azure { namespace storage_lite {
virtual retry_info evaluate(const retry_context &context) const = 0;
};
// Default retry policy
class retry_policy final : public retry_policy_base
{
public:
retry_info evaluate(const retry_context &context) const override
retry_info evaluate(const retry_context& context) const override
{
if (context.numbers() == 0)
const int max_retry_count = 3;
if (context.numbers() <= max_retry_count && can_retry(context.result()))
{
return retry_info(true, std::chrono::seconds(0));
}
else if (context.numbers() < 26 && can_retry(context.result()))
{
double delay = (pow(1.2, context.numbers()-1)-1);
delay = std::min(delay, 60.0); // Maximum backoff delay of 1 minute
delay *= (((double)rand())/RAND_MAX)/2 + 0.75;
return retry_info(true, std::chrono::seconds((int)delay));
}
return retry_info(false, std::chrono::seconds(0));
}
@ -101,6 +96,17 @@ namespace azure { namespace storage_lite {
}
};
// No-retry policy
class no_retry_policy final : public retry_policy_base
{
public:
retry_info evaluate(const retry_context& context) const override
{
unused(context);
return retry_info(false, std::chrono::seconds(0));
}
};
}} // azure::storage_lite
#pragma pop_macro("min")