Failover operation by role-based fallback.
This type of failover strategy is dedicated to a DBM cluster with several hosts are playing different roles like Master, Replica, and so on.
For example, you have a high-load and high-availability system which should provide newest data from a master host under normal conditions, but it is ok to have outdated data from a replica host if the master is down or under some overload conditions.
For that kind of systems, the Role-Based Execution & Fallback strategy is.
The base entities are Roles which are represented by ozo::failover::role
template specializations. Every role can recover several error conditions which should be defined via ozo::failover::can_recover
customization. So if a new recover condition set is needed - a new role should be defined. This mechanism of static recovery conditions definition is a trade-off between framework complexity and usability.
There is a strategy which uses the roles. It is implemented via ozo::failover::role_based_strategy
class and can be instantiated via ozo::failover::role_based
function.
The strategy may work only with a special type of ConnectionProvider
which allows being bound to a specific role. Such provider is modelled by ozo::failover::role_based_connection_provider
. It has an additional method ozo::failover::role_based_connection_provider::rebind_role
which bind the provider to a specific role. Such a mechanism allows to switch between roles and get connections to their hosts during the execution of the strategy.
The example of the strategy use can be found in examples/role_based_request.cpp
.
Classes | |
struct | ozo::failover::role_based_options |
Options for role-based failover. More... | |
class | ozo::failover::role_based_connection_provider< Source > |
struct | ozo::failover::role_based_connection_source< SourcesMap, Role > |
class | ozo::failover::role_based_strategy< Options > |
Role-based strategy. More... | |
Functions | |
template<typename Role > | |
constexpr auto | ozo::failover::can_recover (const Role &role, const error_code &ec) |
Determines if an error can be recovered by executing an operation on host with a given role. More... | |
template<typename Key , typename Value , typename ... Pairs> | |
constexpr decltype(auto) | ozo::failover::make_role_based_connection_source (hana::pair< Key, Value > p1, Pairs &&...ps) |
template<typename ... Roles> | |
constexpr auto | ozo::failover::role_based (Roles ...roles) |
Variables | |
constexpr role< class master_tag > | ozo::failover::master |
constexpr role< class replica_tag > | ozo::failover::replica |
|
constexpr |
Determines if an error can be recovered by executing an operation on host with a given role.
role | — role which should be checked |
ec | — error code from the previous try of an operation execution |
This function should be customized for a new role via ozo::failover::can_recover_impl
template specialization.
E.g. for ozo::failover::replica
role the specialization may look like this:
Such a customization provides an ability to use roles objects which contains some additional compile-time or run-time information. E.g.:
|
constexpr |
Creates connection source which dispatches given connection sources for respective roles.
Specify different ozo::connection_info
objects for different roles.
|
constexpr |
Try to perform an operation on first role with fallback to next items of specified sequence which should recover an error. E.g., in case of sequence consists of role1, role2, role3 and role4. If role1 cause an error which could be recovered with role3 and can not be recovered with role2 then the role2 will be skipped and operation failover continues from fallback role3.
roles | — variadic of roles to try operation on. |
ozo::failover::role_based_strategy
specialization.ozo::failover::role_based_connection_provider
ConnectionProvider
implementation.Operation time constraint interval will be divided between tries as follow.
Given operation has a time constraint interval T, each try would have its own time constraint according to the rule:
Try number | Time constraint |
---|---|
1 | T/n |
2 | (T - t1) / (n - 1) |
3 | (T - (t1 + t2)) / (n - 2) |
... | |
N | (T - (t1 + t2 + ... + tn-1))) |
, there
Try to perform the request on master once and then twice on replica if error code is recoverable.
Each try has own time duration constraint calculated as:
|
constexpr |
General purpose master (read/write) host role.
This role can recover these error conditions
ozo::errc::connection_error
,ozo::errc::type_mismatch
,ozo::errc::protocol_error
,ozo::errc::database_readonly
ozo::failover::can_recover()
|
constexpr |
General purpose replica (read-only) host role.
This role can recover these error conditions
ozo::errc::connection_error
,ozo::errc::type_mismatch
,ozo::errc::protocol_error
ozo::failover::can_recover()