@@ -198,16 +198,16 @@ pub struct DbPoolStats {
198198 pub max : u32 ,
199199}
200200
201- /// Owns a detached Postgres session holding a relay advisory leader lock.
201+ /// Owns the detached Postgres session holding the relay usage-metrics advisory 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 AdvisoryLockLeader {
206+ pub struct UsageMetricsLeader {
207207 connection : PgConnection ,
208208}
209209
210- impl AdvisoryLockLeader {
210+ impl UsageMetricsLeader {
211211 /// Returns whether the lock-owning session is still reachable.
212212 ///
213213 /// Bounded to 5 seconds — a blackholed connection (no RST) would otherwise
@@ -508,20 +508,23 @@ impl Db {
508508 } )
509509 }
510510
511- /// Try to acquire a detached session advisory lock for singleton relay work .
511+ /// Try to acquire the detached session advisory lock for relay usage metrics .
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_advisory_lock ( & self , lock_key : i64 ) -> Result < Option < AdvisoryLockLeader > > {
517+ pub async fn try_lock_usage_metrics (
518+ & self ,
519+ lock_key : i64 ,
520+ ) -> Result < Option < UsageMetricsLeader > > {
518521 let mut connection = self . pool . acquire ( ) . await ?;
519522 let acquired = sqlx:: query_scalar :: < _ , bool > ( "SELECT pg_try_advisory_lock($1)" )
520523 . bind ( lock_key)
521524 . fetch_one ( & mut * connection)
522525 . await ?;
523526 if acquired {
524- Ok ( Some ( AdvisoryLockLeader {
527+ Ok ( Some ( UsageMetricsLeader {
525528 connection : connection. detach ( ) ,
526529 } ) )
527530 } else {
@@ -4660,14 +4663,14 @@ mod tests {
46604663 let key = 0x4255_5A5A_4D45_5452 ;
46614664
46624665 let mut leader = first
4663- . try_advisory_lock ( key)
4666+ . try_lock_usage_metrics ( key)
46644667 . await
46654668 . expect ( "first lock attempt" )
46664669 . expect ( "first database handle becomes leader" ) ;
46674670 assert ! ( leader. is_live( ) . await , "lock owner remains reachable" ) ;
46684671 assert ! (
46694672 second
4670- . try_advisory_lock ( key)
4673+ . try_lock_usage_metrics ( key)
46714674 . await
46724675 . expect( "second lock attempt" )
46734676 . is_none( ) ,
@@ -4677,7 +4680,7 @@ mod tests {
46774680 drop ( leader) ;
46784681 assert ! (
46794682 second
4680- . try_advisory_lock ( key)
4683+ . try_lock_usage_metrics ( key)
46814684 . await
46824685 . expect( "lock attempt after leader drop" )
46834686 . is_some( ) ,
0 commit comments