From cf4e8a0d57a5188afb54161987316ae78ade8a3e Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Wed, 11 Dec 2024 08:59:59 -0800 Subject: [PATCH] scmstore: add counter for indexedlog rotations Summary: Expose a counter for number of indexedlog rotations. We don't want the hgcache logs to rotate too frequently (because that drops all the data in the final log), and this will help us see how often they rotate. Reviewed By: sggutier Differential Revision: D66903539 fbshipit-source-id: 1526594e454944b376b943ae84547dcff2aab5de --- eden/scm/lib/indexedlog/src/rotate.rs | 6 ++++++ eden/scm/lib/revisionstore/src/scmstore/file.rs | 3 +++ eden/scm/tests/test-remotefilelog-prefetch.t | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/eden/scm/lib/indexedlog/src/rotate.rs b/eden/scm/lib/indexedlog/src/rotate.rs index 00db8cf37705f..4e8dbe3982c9e 100644 --- a/eden/scm/lib/indexedlog/src/rotate.rs +++ b/eden/scm/lib/indexedlog/src/rotate.rs @@ -12,7 +12,9 @@ use std::fs; use std::io; use std::path::Path; use std::path::PathBuf; +use std::sync::atomic::AtomicU64; use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; use std::sync::atomic::Ordering::SeqCst; use minibytes::Bytes; @@ -37,6 +39,8 @@ use crate::repair::OpenOptionsRepair; use crate::repair::RepairMessage; use crate::utils; +pub static ROTATE_COUNT: AtomicU64 = AtomicU64::new(0); + /// A collection of [`Log`]s that get rotated or deleted automatically when they /// exceed size or count limits. /// @@ -586,6 +590,8 @@ impl RotateLog { /// callsite makes sure that [`Log`]s are consistent (ex. up-to-date, /// and do not have dirty entries in non-writable logs). fn rotate_internal(&mut self, lock: &ScopedDirLock) -> crate::Result<()> { + ROTATE_COUNT.fetch_add(1, Ordering::Relaxed); + let span = debug_span!("RotateLog::rotate", latest = self.latest as u32); if let Some(dir) = &self.dir { span.record("dir", dir.to_string_lossy().as_ref()); diff --git a/eden/scm/lib/revisionstore/src/scmstore/file.rs b/eden/scm/lib/revisionstore/src/scmstore/file.rs index 6f2281a86c2e9..6a0dba18545ac 100644 --- a/eden/scm/lib/revisionstore/src/scmstore/file.rs +++ b/eden/scm/lib/revisionstore/src/scmstore/file.rs @@ -28,6 +28,7 @@ use clientinfo::set_client_request_info_thread_local; use crossbeam::channel::unbounded; use indexedlog::log::AUTO_SYNC_COUNT; use indexedlog::log::SYNC_COUNT; +use indexedlog::rotate::ROTATE_COUNT; use itertools::Itertools; use minibytes::Bytes; use parking_lot::Mutex; @@ -140,6 +141,7 @@ macro_rules! try_local_content { static FILESTORE_FLUSH_COUNT: Counter = Counter::new_counter("scmstore.file.flush"); static INDEXEDLOG_SYNC_COUNT: Counter = Counter::new_counter("scmstore.indexedlog.sync"); static INDEXEDLOG_AUTO_SYNC_COUNT: Counter = Counter::new_counter("scmstore.indexedlog.auto_sync"); +static INDEXEDLOG_ROTATE_COUNT: Counter = Counter::new_counter("scmstore.indexedlog.rotate"); impl FileStore { /// Get the "local content" without going through the heavyweight "fetch" API. @@ -329,6 +331,7 @@ impl FileStore { // These aren't technically filestore specific, but this will keep them updated. INDEXEDLOG_SYNC_COUNT.add(SYNC_COUNT.swap(0, Ordering::Relaxed) as usize); INDEXEDLOG_AUTO_SYNC_COUNT.add(AUTO_SYNC_COUNT.swap(0, Ordering::Relaxed) as usize); + INDEXEDLOG_ROTATE_COUNT.add(ROTATE_COUNT.swap(0, Ordering::Relaxed) as usize); if let Some(activity_logger) = activity_logger { if let Err(err) = activity_logger.lock().log_file_fetch( diff --git a/eden/scm/tests/test-remotefilelog-prefetch.t b/eden/scm/tests/test-remotefilelog-prefetch.t index f5209fec7cdc2..eddd2da98f81b 100644 --- a/eden/scm/tests/test-remotefilelog-prefetch.t +++ b/eden/scm/tests/test-remotefilelog-prefetch.t @@ -43,7 +43,8 @@ Prefetch (and also check we get counters): scmstore.file.fetch.indexedlog.local.singles: 1 scmstore.file.fetch.indexedlog.local.time: * (glob) (?) scmstore.file.flush: * (glob) - scmstore.indexedlog.sync: * (glob) + scmstore.indexedlog.rotate: * (glob) (?) + scmstore.indexedlog.sync: * (glob) (?) scmstore.tree.fetch.edenapi.keys: 1 scmstore.tree.fetch.edenapi.requests: 1 scmstore.tree.fetch.edenapi.singles: 1