@@ -198,16 +198,16 @@ pub struct DbPoolStats {
198198 pub max : u32 ,
199199}
200200
201- /// Owns the detached Postgres session holding the relay usage-metrics advisory lock.
201+ /// Owns a detached Postgres session holding a relay advisory leader lock.
202202///
203203/// The connection deliberately does not return to the main pool: session advisory
204204/// locks must remain bound to this exact physical connection, and the poller
205205/// pings it before each leader-only collection tick.
206- pub struct UsageMetricsLeader {
206+ pub struct AdvisoryLockLeader {
207207 connection : PgConnection ,
208208}
209209
210- impl UsageMetricsLeader {
210+ impl AdvisoryLockLeader {
211211 /// Returns whether the lock-owning session is still reachable.
212212 ///
213213 /// Bounded to 5 seconds — a blackholed connection (no RST) would otherwise
@@ -508,23 +508,20 @@ impl Db {
508508 } )
509509 }
510510
511- /// Try to acquire the detached session advisory lock for relay usage metrics .
511+ /// Try to acquire a detached session advisory lock for singleton relay work .
512512 ///
513513 /// The returned guard owns the exact connection that acquired the lock. It is
514514 /// detached from the shared pool so a stable leader neither returns a locked
515515 /// session to other callers nor permanently consumes a pool slot. Dropping the
516516 /// guard closes the connection and releases the session-scoped lock.
517- pub async fn try_lock_usage_metrics (
518- & self ,
519- lock_key : i64 ,
520- ) -> Result < Option < UsageMetricsLeader > > {
517+ pub async fn try_advisory_lock ( & self , lock_key : i64 ) -> Result < Option < AdvisoryLockLeader > > {
521518 let mut connection = self . pool . acquire ( ) . await ?;
522519 let acquired = sqlx:: query_scalar :: < _ , bool > ( "SELECT pg_try_advisory_lock($1)" )
523520 . bind ( lock_key)
524521 . fetch_one ( & mut * connection)
525522 . await ?;
526523 if acquired {
527- Ok ( Some ( UsageMetricsLeader {
524+ Ok ( Some ( AdvisoryLockLeader {
528525 connection : connection. detach ( ) ,
529526 } ) )
530527 } else {
@@ -4663,14 +4660,14 @@ mod tests {
46634660 let key = 0x4255_5A5A_4D45_5452 ;
46644661
46654662 let mut leader = first
4666- . try_lock_usage_metrics ( key)
4663+ . try_advisory_lock ( key)
46674664 . await
46684665 . expect ( "first lock attempt" )
46694666 . expect ( "first database handle becomes leader" ) ;
46704667 assert ! ( leader. is_live( ) . await , "lock owner remains reachable" ) ;
46714668 assert ! (
46724669 second
4673- . try_lock_usage_metrics ( key)
4670+ . try_advisory_lock ( key)
46744671 . await
46754672 . expect( "second lock attempt" )
46764673 . is_none( ) ,
@@ -4680,7 +4677,7 @@ mod tests {
46804677 drop ( leader) ;
46814678 assert ! (
46824679 second
4683- . try_lock_usage_metrics ( key)
4680+ . try_advisory_lock ( key)
46844681 . await
46854682 . expect( "lock attempt after leader drop" )
46864683 . is_some( ) ,
0 commit comments