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:
Piotr Sarna
2021-04-12 10:23:38 +02:00
parent 4ba1ac57a1
commit cbedefb0f9
2 changed files with 21 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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;