@@ -4,7 +4,7 @@ use tokio::time::{self, Duration, Instant};
44use bytes:: Bytes ;
55use std:: collections:: { BTreeMap , HashMap } ;
66use std:: sync:: { Arc , Mutex } ;
7- use tracing:: debug;
7+ use tracing:: { debug, instrument } ;
88
99/// A wrapper around a `Db` instance. This exists to allow orderly cleanup
1010/// of the `Db` by signalling the background purge task to shut down when
@@ -150,6 +150,7 @@ impl Db {
150150 /// Returns `None` if there is no value associated with the key. This may be
151151 /// due to never having assigned a value to the key or a previously assigned
152152 /// value expired.
153+ #[ instrument( level = "trace" , name = "Db::get" , skip( self ) ) ]
153154 pub ( crate ) fn get ( & self , key : & str ) -> Option < Bytes > {
154155 // Acquire the lock, get the entry and clone the value.
155156 //
@@ -163,6 +164,7 @@ impl Db {
163164 /// Duration.
164165 ///
165166 /// If a value is already associated with the key, it is removed.
167+ #[ instrument( level = "trace" , name = "Db::set" , skip( self , value) ) ]
166168 pub ( crate ) fn set ( & self , key : String , value : Bytes , expire : Option < Duration > ) {
167169 let mut state = self . shared . state . lock ( ) . unwrap ( ) ;
168170
@@ -231,6 +233,7 @@ impl Db {
231233 ///
232234 /// The returned `Receiver` is used to receive values broadcast by `PUBLISH`
233235 /// commands.
236+ #[ instrument( level = "trace" , name = "Db::subscribe" , skip( self , key) ) ]
234237 pub ( crate ) fn subscribe ( & self , key : String ) -> broadcast:: Receiver < Bytes > {
235238 use std:: collections:: hash_map:: Entry ;
236239
@@ -262,6 +265,7 @@ impl Db {
262265
263266 /// Publish a message to the channel. Returns the number of subscribers
264267 /// listening on the channel.
268+ #[ instrument( level = "trace" , name = "Db::publish" , skip( self , value) ) ]
265269 pub ( crate ) fn publish ( & self , key : & str , value : Bytes ) -> usize {
266270 let state = self . shared . state . lock ( ) . unwrap ( ) ;
267271
@@ -279,6 +283,7 @@ impl Db {
279283
280284 /// Signals the purge background task to shut down. This is called by the
281285 /// `DbShutdown`s `Drop` implementation.
286+ #[ instrument( name = "Db::shutdown_purge_task" , skip( self ) ) ]
282287 fn shutdown_purge_task ( & self ) {
283288 // The background task must be signaled to shut down. This is done by
284289 // setting `State::shutdown` to `true` and signalling the task.
@@ -296,6 +301,7 @@ impl Db {
296301impl Shared {
297302 /// Purge all expired keys and return the `Instant` at which the **next**
298303 /// key will expire. The background task will sleep until this instant.
304+ #[ instrument( name = "Shared::purge_expired_keys" , skip( self ) ) ]
299305 fn purge_expired_keys ( & self ) -> Option < Instant > {
300306 let mut state = self . state . lock ( ) . unwrap ( ) ;
301307
@@ -323,6 +329,10 @@ impl Shared {
323329 }
324330
325331 // The key expired, remove it
332+ debug ! {
333+ key = & key. as_str( ) ,
334+ "purged_expired_key" ,
335+ }
326336 state. entries . remove ( key) ;
327337 state. expirations . remove ( & ( when, id) ) ;
328338 }
@@ -352,6 +362,7 @@ impl State {
352362///
353363/// Wait to be notified. On notification, purge any expired keys from the shared
354364/// state handle. If `shutdown` is set, terminate the task.
365+ #[ instrument( skip( shared) ) ]
355366async fn purge_expired_tasks ( shared : Arc < Shared > ) {
356367 // If the shutdown flag is set, then the task should exit.
357368 while !shared. is_shutdown ( ) {
0 commit comments