mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-29 11:10:40 +00:00
qos: add a way of merging service level options
In order to combine multiple service level options coming from multiple roles, a helper function is provided to merge two of them. The semantics depend on each parameter, but for timeouts, which are the only parameters at the time of writing this message, the minimum value of the two is taken. That in particular means that when service level A has timeout = 50ms and service level B has timeout = 1s, the resulting service level options would set the timeout to 50ms.
This commit is contained in:
@@ -41,4 +41,22 @@ service_level_options service_level_options::replace_defaults(const service_leve
|
||||
return ret;
|
||||
}
|
||||
|
||||
service_level_options service_level_options::merge_with(const service_level_options& other) const {
|
||||
service_level_options ret = *this;
|
||||
std::visit(overloaded_functor {
|
||||
[&] (const unset_marker& um) {
|
||||
ret.timeout = other.timeout;
|
||||
},
|
||||
[&] (const delete_marker& dm) {
|
||||
ret.timeout = other.timeout;
|
||||
},
|
||||
[&] (const lowres_clock::duration& d) {
|
||||
if (auto* other_timeout = std::get_if<lowres_clock::duration>(&other.timeout)) {
|
||||
ret.timeout = std::min(d, *other_timeout);
|
||||
}
|
||||
},
|
||||
}, ret.timeout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ struct service_level_options {
|
||||
timeout_type timeout = unset_marker{};
|
||||
|
||||
service_level_options replace_defaults(const service_level_options& other) const;
|
||||
// Merges the values of two service level options. The semantics depends
|
||||
// on the type of the parameter - e.g. for timeouts, a min value is preferred.
|
||||
service_level_options merge_with(const service_level_options& other) const;
|
||||
|
||||
bool operator==(const service_level_options& other) const = default;
|
||||
bool operator!=(const service_level_options& other) const = default;
|
||||
|
||||
Reference in New Issue
Block a user