@@ -64,6 +64,7 @@ use parking_lot::{Condvar, Mutex, MutexGuard};
6464use crate :: { manager:: CommittedRevision , root_store:: RootStore } ;
6565use crossbeam:: channel:: { self , Receiver , Sender } ;
6666
67+ use firewood_metrics:: firewood_increment;
6768use firewood_storage:: logger:: error;
6869
6970/// Error type for persistence operations.
@@ -266,8 +267,11 @@ impl PersistSemaphore {
266267 #[ inline]
267268 fn acquire ( & self ) {
268269 let mut permits = self . state . lock ( ) ;
269- while * permits == 0 {
270- self . condvar . wait ( & mut permits) ;
270+ if * permits == 0 {
271+ firewood_increment ! ( crate :: registry:: PERSIST_THROTTLE_BLOCKS , 1 ) ;
272+ while * permits == 0 {
273+ self . condvar . wait ( & mut permits) ;
274+ }
271275 }
272276 // The background loop guarantees permits > 0
273277 * permits = permits. saturating_sub ( 1 ) ;
@@ -385,6 +389,7 @@ impl PersistLoop {
385389 }
386390
387391 /// Persists the given revision and releases semaphore permits.
392+ #[ crate :: metrics( "persist.total" , "persist revision to storage" ) ]
388393 fn persist (
389394 & mut self ,
390395 revision : & CommittedRevision ,
@@ -444,9 +449,17 @@ impl PersistLoop {
444449 if let Some ( ref store) = self . shared . root_store
445450 && let ( Some ( hash) , Some ( addr) ) = ( revision. root_hash ( ) , revision. root_address ( ) )
446451 {
447- store
452+ let start = coarsetime:: Instant :: now ( ) ;
453+
454+ let result = store
448455 . add_root ( & hash, & addr)
449- . map_err ( |e| PersistError :: RootStore ( e. into ( ) ) ) ?;
456+ . map_err ( |e| PersistError :: RootStore ( e. into ( ) ) ) ;
457+
458+ let success = if result. is_err ( ) { "false" } else { "true" } ;
459+ firewood_increment ! ( crate :: registry:: PERSIST_ROOT_STORE , 1 , "success" => success) ;
460+ firewood_increment ! ( crate :: registry:: PERSIST_ROOT_STORE_MS , start. elapsed( ) . as_millis( ) , "success" => success) ;
461+
462+ result?;
450463 }
451464
452465 Ok ( ( ) )
0 commit comments