Classes and functions for performing hedged requests.
To perform hedged request you need to define RequestStrategy - a class similar to the following ExampleStrategy:
Then call any of these functions:
Definition in file hedged_request.hpp.
Go to the source code of this file.
#include <chrono>#include <cstddef>#include <optional>#include <type_traits>#include <utility>#include <vector>#include <userver/compiler/impl/lifetime.hpp>#include <userver/engine/awaitable.hpp>#include <userver/engine/task/cancel.hpp>#include <userver/engine/wait_any.hpp>#include <userver/utils/assert.hpp>#include <userver/utils/async.hpp>#include <userver/utils/hedging_settings.hpp>#include <userver/utils/impl/hedging_plan.hpp>Classes | |
| struct | utils::hedging::RequestTraits< RequestStrategy > |
| struct | utils::hedging::HedgedRequestBulkFuture< RequestStrategy > |
| Future of hedged bulk request. More... | |
| struct | utils::hedging::HedgedRequestFuture< RequestStrategy > |
| Future of hedged request. More... | |
Namespaces | |
| namespace | utils |
| General-purpose utilities used across userver libraries. | |
Functions | |
| template<typename RequestStrategy> | |
| auto | utils::hedging::HedgeRequestsBulk (std::vector< RequestStrategy > inputs, HedgingSettings hedging_settings) |
| Synchronously perform bulk hedged requests described by RequestStrategy and return result of type std::vector<std::optional<ResultType>>. | |
| template<typename RequestStrategy> | |
| auto | utils::hedging::HedgeRequestsBulkAsync (std::vector< RequestStrategy > inputs, HedgingSettings settings) |
| Asynchronously perform bulk hedged requests described by RequestStrategy and return future which returns Result of type std::vector<std::optional<ResultType>>. | |
| template<typename RequestStrategy> | |
| std::optional< typename RequestTraits< RequestStrategy >::ReplyType > | utils::hedging::HedgeRequest (RequestStrategy input, HedgingSettings settings) |
| template<typename RequestStrategy> | |
| auto | utils::hedging::HedgeRequestAsync (RequestStrategy input, HedgingSettings settings) |
| std::optional< typename RequestTraits< RequestStrategy >::ReplyType > utils::hedging::HedgeRequest | ( | RequestStrategy | input, |
| HedgingSettings | settings ) |
Synchronously Perform hedged request described by RequestStrategy and return result or throw runtime_error. Exception can be thrown in case of timeout or if request was denied by strategy e.g. ProcessReply always returned std::nullopt or ExtractReply returned std::nullopt
Definition at line 331 of file hedged_request.hpp.
| auto utils::hedging::HedgeRequestAsync | ( | RequestStrategy | input, |
| HedgingSettings | settings ) |
Create future which perform hedged request described by RequestStrategy and return result or throw runtime_error. Exception can be thrown in case of timeout or if request was denied by strategy e.g. ProcessReply always returned std::nullopt or ExtractReply returned std::nullopt
Definition at line 349 of file hedged_request.hpp.
| auto utils::hedging::HedgeRequestsBulk | ( | std::vector< RequestStrategy > | inputs, |
| HedgingSettings | hedging_settings ) |
Synchronously perform bulk hedged requests described by RequestStrategy and return result of type std::vector<std::optional<ResultType>>.
Result contains replies for each element in inputs or std::nullopt in case of either timeouts or bad replies (RequestStrategy::ProcessReply(RequestType&&) returned std::nullopt and RequestStrategy::ExtractReply() returned std::nullopt).
timeout - need to process plan
Timeout but we don't have planned actions any more
Got reply but it's not OK and user wants to retry over some delay
No need to check, the stop entry is planned until the stop
Definition at line 234 of file hedged_request.hpp.
| auto utils::hedging::HedgeRequestsBulkAsync | ( | std::vector< RequestStrategy > | inputs, |
| HedgingSettings | settings ) |
Asynchronously perform bulk hedged requests described by RequestStrategy and return future which returns Result of type std::vector<std::optional<ResultType>>.
Result contains replies for each element in inputs or std::nullopt in case of either timeouts or bad replies (RequestStrategy::ProcessReply(RequestType&&) returned std::nullopt and RequestStrategy::ExtractReply() returned std::nullopt).
Definition at line 317 of file hedged_request.hpp.