OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
ozo::failover::retry_strategy< Options > Class Template Reference

#include <ozo/failover/retry.h>

Description

template<typename Options = decltype(hana::make_map())>
class ozo::failover::retry_strategy< Options >

Retry strategy.

Retry strategy is a factory for ozo::fallback::basic_try object. This class is an options' factory (see ozo::options_factory_base).

Inherits ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >.

Public Member Functions

constexpr retry_strategy (Options options=Options{})
 Construct a new retry strategy object. More...
 
template<typename Operation , typename Allocator , typename ConnectionProvider , typename TimeConstraint , typename ... Args>
auto get_first_try (const Operation &, const Allocator &, ConnectionProvider &&provider, TimeConstraint t, Args &&...args) const
 Get the first try object. More...
 
constexpr decltype(auto) tries (int n) const &
 Specify number of tries. More...
 
constexpr int get_tries () const
 Number of maximum tries count are setted with ozo::retry_strategy::tries() More...
 
constexpr auto get_conditions () const
 Retry error conditions of the strategy. More...
 
constexpr decltype(auto) operator* (int n) const &
 Sintactic sugar for ozo::retry_strategy::tries() More...
 
- Public Member Functions inherited from ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >
constexpr options_factory_base (decltype(hana::make_map()) v)
 
constexpr decltype(auto) set (decltype(hana::make_map()) &&...options) &&
 
constexpr auto has (ozo::option< Key > op) const
 
constexpr decltype(auto) get (ozo::option< Key > op) const
 
constexpr const decltype(hana::make_map()) & options () const &
 
constexpr decltype(hana::make_map()) & options () &
 
constexpr decltype(hana::make_map()) && options () &&
 

Friends

class ozo::options_factory_base< retry_strategy< Options >, Options >
 

Constructors

◆ retry_strategy()

template<typename Options = decltype(hana::make_map())>
constexpr ozo::failover::retry_strategy< Options >::retry_strategy ( Options  options = Options{})
constexpr

Construct a new retry strategy object.

Parameters
optionsboost::hana::map of ozo::failover::retry_options and values.

Member Function Documentation

◆ get_conditions()

template<typename Options = decltype(hana::make_map())>
constexpr auto ozo::failover::retry_strategy< Options >::get_conditions ( ) const
constexpr

Retry error conditions of the strategy.

Returns
boost::hana::tuple — tuple of retryable error conditions setted for this strategy.

References ozo::failover::retry_options::conditions, and ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >::get().

◆ get_first_try()

template<typename Options = decltype(hana::make_map())>
template<typename Operation , typename Allocator , typename ConnectionProvider , typename TimeConstraint , typename ... Args>
auto ozo::failover::retry_strategy< Options >::get_first_try ( const Operation &  ,
const Allocator &  ,
ConnectionProvider &&  provider,
TimeConstraint  t,
Args &&...  args 
) const

Get the first try object.

Default implementation for ozo::fallback::get_first_try() failover strategy interface function.

Parameters
alloc— allocator which should be used for try context.
args— operation arguments.
Returns
basic_try — first try object.

References ozo::deadline(), ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >::has(), ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >::options(), and ozo::failover::retry_options::tries.

◆ get_tries()

template<typename Options = decltype(hana::make_map())>
constexpr int ozo::failover::retry_strategy< Options >::get_tries ( ) const
constexpr

Number of maximum tries count are setted with ozo::retry_strategy::tries()

Returns
int — number of operation tries

References ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >::get(), and ozo::failover::retry_options::tries.

◆ operator*()

template<typename Options = decltype(hana::make_map())>
constexpr decltype(auto) ozo::failover::retry_strategy< Options >::operator* ( int  n) const &
constexpr

Sintactic sugar for ozo::retry_strategy::tries()

Parameters
n— number of tries
Returns
retry_strategy specialization object

References ozo::failover::retry_strategy< Options >::tries().

◆ tries()

template<typename Options = decltype(hana::make_map())>
constexpr decltype(auto) ozo::failover::retry_strategy< Options >::tries ( int  n) const &
constexpr

Specify number of tries.

Specify number of tries for an operation.

Parameters
n— number of tries
Returns
retry_strategy specialization object

If operation has time constraint T each try would have its own time constraint according to the rule, there ti — actual time of ith try:

Try number Time constraint
1 T/n
2 (T - t1) / (n - 1)
3 (T - (t1 + t2)) / (n - 2)
...
N (T - (t1 + t2 + ... + tn-1)))

Example

Retry on a network problem and operation timed-out no more than 3 tries. Each try has own time duration constraint calculated as:

  • for the 1st try: 0,5/3 sec.
  • for the 2nd try: (0,5 - t1) / 2 >= 0,5/3 sec.
  • for the 3rd try: 0,5 - (t1 + t2) >= 0,5/3 sec.
auto retry = failover::retry(errc::network, errc::timeout);
ozo::request[retry*3](pool, query, .5s, out, yield);

References ozo::options_factory_base< retry_strategy< decltype(hana::make_map()) >, decltype(hana::make_map()) >::set(), and ozo::failover::retry_options::tries.

Referenced by ozo::failover::retry_strategy< Options >::operator*().

ozo::request
decltype(auto) request(ConnectionProvider &&provider, BinaryQueryConvertible &&query, TimeConstraint time_constraint, Out out, CompletionToken &&token)
Executes query and retrives a result from a database with time constraint.
ozo::failover::retry
constexpr auto retry(ErrorConditions ...ec)
Definition: retry.h:308