From: Kotresh HR Date: Sun, 21 Jun 2026 17:52:29 +0000 (+0530) Subject: mgr/mirroring: make snapshot mirror metrics cache optional X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=01dd9506f2c62a75841184ac9aa75cf72bf57b5b;p=ceph.git mgr/mirroring: make snapshot mirror metrics cache optional Add snapshot_mirror_metrics_cache_enabled (default true). When disabled, metrics_status reads omap directly and skips complete and partial caches. When enabled, behavior is unchanged. Fixes: https://tracker.ceph.com/issues/76686 Signed-off-by: Kotresh HR --- diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index 12279d6e84f..0d88613e2d6 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -767,6 +767,9 @@ class FSSnapshotMirror: except MirrorException as me: return me.args[0], '', me.args[1] + def _metrics_cache_enabled(self): + return self.mgr.get_module_option('snapshot_mirror_metrics_cache_enabled') + @lru_cache_timeout( lambda self, *_args, **_kwargs: self.mgr.get_module_option( 'snapshot_mirror_metrics_cache_ttl'), @@ -814,6 +817,22 @@ class FSSnapshotMirror: fspolicy.policy, fspolicy.get_live_instance_ids()) return metrics + def _load_sync_stat_metrics_from_omap(self, filesystem, mirrored_dir_path, + peer_uuid, peers, fspolicy): + ioctx = metrics_load.open_metadata_ioctx( + self.rados, self.fs_map, filesystem) + if mirrored_dir_path: + dir_path = norm_path(mirrored_dir_path) + metrics, _, _ = metrics_load.fetch_sync_stat_metrics( + ioctx, filesystem, peers, mirrored_dir_path, peer_uuid, + fspolicy.policy, fspolicy.get_live_instance_ids()) + return metrics_for_dir_and_peers(metrics, dir_path, peers) + complete_metrics = metrics_load.load_sync_stat_metrics( + ioctx, filesystem, None, fspolicy.policy, + fspolicy.get_live_instance_ids(), peers) + return try_get_from_complete( + complete_metrics, mirrored_dir_path, peer_uuid, peers) + def metrics_status(self, filesystem, mirrored_dir_path, peer_uuid): """Return persisted mirror directory snapshot metrics as JSON. @@ -848,6 +867,16 @@ class FSSnapshotMirror: else: requested_peers = all_peers + if not self._metrics_cache_enabled(): + log.debug('sync stat metrics for filesystem %s (dir=%s, peer=%s) ' + 'cache disabled; loading from omap', + filesystem, mirrored_dir_path or '*', + peer_uuid or '*') + metrics = self._load_sync_stat_metrics_from_omap( + filesystem, mirrored_dir_path, peer_uuid, + requested_peers, fspolicy) + return 0, json.dumps({'metrics': metrics}, indent=4), '' + if mirrored_dir_path: dir_path = norm_path(mirrored_dir_path) # Single-dir query: peek complete cache (key: filesystem diff --git a/src/pybind/mgr/mirroring/module.py b/src/pybind/mgr/mirroring/module.py index 37a8cb63747..3fbe145864e 100644 --- a/src/pybind/mgr/mirroring/module.py +++ b/src/pybind/mgr/mirroring/module.py @@ -9,6 +9,13 @@ from .fs.snapshot_mirror import FSSnapshotMirror class Module(MgrModule): CLICommand = MirroringCLICommand MODULE_OPTIONS: List[Option] = [ + Option( + 'snapshot_mirror_metrics_cache_enabled', + type='bool', + default=True, + desc='Cache fs snapshot mirror status omap metrics', + runtime=True, + ), Option( 'snapshot_mirror_metrics_cache_ttl', type='secs',