service/qos: Move effective SL cache to auth_integration

Since `auth_integration` manages effective service levels, let's move
the relevant cache from `service_level_controller` to it.
This commit is contained in:
Dawid Mędrek
2025-08-26 16:20:44 +02:00
parent dd5a35dc67
commit fc1c41536c
2 changed files with 12 additions and 9 deletions

View File

@@ -54,7 +54,7 @@ future<> service_level_controller::auth_integration::stop() {
}
void service_level_controller::auth_integration::clear_cache() {
_sl_controller._effective_service_levels_db.clear();
_cache.clear();
}
service_level_controller::service_level_controller(sharded<auth::service>& auth_service, locator::shared_token_metadata& tm, abort_source& as, service_level_options default_service_level_config, scheduling_group default_scheduling_group, bool destroy_default_sg_on_drain)
@@ -387,7 +387,11 @@ future<> service_level_controller::auth_integration::reload_cache() {
}
co_await _sl_controller.container().invoke_on_all([effective_sl_map] (service_level_controller& sl_controller) -> future<> {
sl_controller._effective_service_levels_db = std::move(effective_sl_map);
// We probably cannot predict if `auth_integration` is still in place on another shard,
// so let's play it safe here.
if (sl_controller._auth_integration) {
sl_controller._auth_integration->_cache = std::move(effective_sl_map);
}
co_await sl_controller.notify_effective_service_levels_cache_reloaded();
});
}
@@ -416,8 +420,8 @@ future<std::optional<service_level_options>> service_level_controller::auth_inte
const auto _ = _stop_gate.hold();
if (_sl_controller._sl_data_accessor->can_use_effective_service_level_cache()) {
auto effective_sl_it = _sl_controller._effective_service_levels_db.find(role_name);
co_return effective_sl_it != _sl_controller._effective_service_levels_db.end()
auto effective_sl_it = _cache.find(role_name);
co_return effective_sl_it != _cache.end()
? std::optional<service_level_options>(effective_sl_it->second)
: std::nullopt;
} else {
@@ -468,8 +472,8 @@ std::optional<service_level_options> service_level_controller::auth_integration:
return std::nullopt;
}
auto effective_sl_it = _sl_controller._effective_service_levels_db.find(role_name);
return effective_sl_it != _sl_controller._effective_service_levels_db.end()
auto effective_sl_it = _cache.find(role_name);
return effective_sl_it != _cache.end()
? std::optional<service_level_options>(effective_sl_it->second)
: std::nullopt;
}

View File

@@ -127,10 +127,11 @@ public:
friend class service_level_controller;
private:
// FIXME: Will be extended in an upcoming commit.
service_level_controller& _sl_controller;
auth::service& _auth_service;
/// Mappings `role name` -> `service level options`.
std::map<sstring, service_level_options> _cache;
/// This gate is supposed to synchronize `stop` with other tasks that
/// this interface performs. Because of that, EVERY coroutine function
/// of this class should hold it throughout its execution.
@@ -208,8 +209,6 @@ private:
// Invariant: Non-null strictly within the lifetime of `auth::service`.
std::unique_ptr<auth_integration> _auth_integration = nullptr;
// role name -> effective service_level_options
std::map<sstring, service_level_options> _effective_service_levels_db;
// Keeps names of effectively dropped service levels. Those service levels exits in the table but are not present in _service_levels_db cache
std::set<sstring> _effectively_dropped_sls;