Use TokenSet for roomid_mutex_state

This commit is contained in:
Lambda 2024-06-23 18:39:56 +00:00
parent 07b5233980
commit 34ccb2cd06
15 changed files with 243 additions and 429 deletions

View file

@ -33,8 +33,11 @@ use tracing::{error, Instrument};
use trust_dns_resolver::TokioAsyncResolver;
use crate::{
api::server_server::FedDest, observability::FilterReloadHandles, services,
utils::on_demand_hashmap::OnDemandHashMap, Config, Error, Result,
api::server_server::FedDest,
observability::FilterReloadHandles,
services,
utils::on_demand_hashmap::{OnDemandHashMap, TokenSet},
Config, Error, Result,
};
type WellKnownMap = HashMap<OwnedServerName, (FedDest, String)>;
@ -42,6 +45,15 @@ type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>;
// Time if last failed try, number of failed tries
type RateLimitState = (Instant, u32);
// Markers for
// [`Service::roomid_mutex_state`]/[`Service::roomid_mutex_insert`]/
// [`Service::roomid_mutex_federation`]
pub(crate) mod marker {
pub(crate) enum State {}
pub(crate) enum Insert {}
pub(crate) enum Federation {}
}
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
pub(crate) reload_handles: FilterReloadHandles,
@ -69,7 +81,7 @@ pub(crate) struct Service {
OnDemandHashMap<OwnedServerName, Semaphore>,
pub(crate) roomid_mutex_insert:
RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub(crate) roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub(crate) roomid_mutex_state: TokenSet<OwnedRoomId, marker::State>,
// this lock will be held longer
pub(crate) roomid_mutex_federation:
@ -266,7 +278,7 @@ impl Service {
servername_ratelimiter: OnDemandHashMap::new(
"servername_ratelimiter".to_owned(),
),
roomid_mutex_state: RwLock::new(HashMap::new()),
roomid_mutex_state: TokenSet::new("roomid_mutex_state".to_owned()),
roomid_mutex_insert: RwLock::new(HashMap::new()),
roomid_mutex_federation: RwLock::new(HashMap::new()),
roomid_federationhandletime: RwLock::new(HashMap::new()),