Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
Loading...
Searching...
No Matches
RetryPolicy.hpp
1
#pragma once
2
3
#include "data/cassandra/Error.hpp"
4
#include "data/cassandra/Types.hpp"
5
#include "util/Retry.hpp"
6
#include "util/log/Logger.hpp"
7
8
#include <boost/asio.hpp>
9
#include <boost/asio/io_context.hpp>
10
#include <boost/asio/strand.hpp>
11
12
#include <chrono>
13
14
namespace
data::cassandra::impl {
15
19
class
ExponentialBackoffRetryPolicy
{
20
util::Logger
log_{
"Backend"
};
21
22
util::Retry
retry_;
23
24
public
:
28
ExponentialBackoffRetryPolicy
(boost::asio::io_context& ioc)
29
: retry_(
30
util
::makeRetryExponentialBackoff(
31
{.initial = std::chrono::milliseconds(1), .max = std::chrono::seconds(1)},
32
boost::asio::make_strand(ioc)
33
)
34
)
35
{
36
}
37
43
[[nodiscard]]
bool
44
shouldRetry
([[maybe_unused]]
CassandraError
err)
45
{
46
auto
const
delayMs =
47
std::chrono::duration_cast<std::chrono::milliseconds>(retry_.delayValue()).count();
48
LOG(log_.error()) <<
"Cassandra write error: "
<< err <<
", current retries "
49
<< retry_.attemptNumber() <<
", retrying in "
<< delayMs
50
<<
" milliseconds"
;
51
52
return
true
;
// keep retrying forever
53
}
54
60
template
<
typename
Fn>
61
void
62
retry
(Fn&& fn)
63
{
64
retry_.retry(std::forward<Fn>(fn));
65
}
66
};
67
68
}
// namespace data::cassandra::impl
data::cassandra::CassandraError
A simple container for both error message and error code.
Definition
Error.hpp:15
data::cassandra::impl::ExponentialBackoffRetryPolicy::shouldRetry
bool shouldRetry(CassandraError err)
Computes next retry delay and returns true unconditionally.
Definition
RetryPolicy.hpp:44
data::cassandra::impl::ExponentialBackoffRetryPolicy::ExponentialBackoffRetryPolicy
ExponentialBackoffRetryPolicy(boost::asio::io_context &ioc)
Create a new retry policy instance with the io_context provided.
Definition
RetryPolicy.hpp:28
data::cassandra::impl::ExponentialBackoffRetryPolicy::retry
void retry(Fn &&fn)
Schedules next retry.
Definition
RetryPolicy.hpp:62
util::Logger
A simple thread-safe logger for the channel specified in the constructor.
Definition
Logger.hpp:78
util::Retry
A retry mechanism.
Definition
Retry.hpp:63
util
This namespace contains various utilities.
Definition
HandlerRegistry.hpp:24
src
data
cassandra
impl
RetryPolicy.hpp
Generated by
1.17.0