From: Kotresh HR Date: Sun, 21 Jun 2026 17:35:30 +0000 (+0530) Subject: mgr/mirroring: Show default stats on newly added dir_root X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c24b8d3cc2fb36ea77276598a2d1c2f90b1304ec;p=ceph.git mgr/mirroring: Show default stats on newly added dir_root When the directory is added for mirroring and the snapshot is not taken yet, the peer_status show the following default metrics. { 'state': 'idle', 'snaps_synced': 0, 'snaps_deleted': 0, 'snaps_renamed': 0, } The mgr interface should also match that. Fixes: https://tracker.ceph.com/issues/76686 Signed-off-by: Kotresh HR --- diff --git a/src/pybind/mgr/mirroring/fs/metrics/format.py b/src/pybind/mgr/mirroring/fs/metrics/format.py index 87fc6c4a86a..943eeb14e2c 100644 --- a/src/pybind/mgr/mirroring/fs/metrics/format.py +++ b/src/pybind/mgr/mirroring/fs/metrics/format.py @@ -1,3 +1,12 @@ +def default_sync_stat_metrics(): + return { + 'state': 'idle', + 'snaps_synced': 0, + 'snaps_deleted': 0, + 'snaps_renamed': 0, + } + + # Matches the format_time function used in peer_status def _format_time(total_seconds_d): total_seconds = int(round(total_seconds_d)) diff --git a/src/pybind/mgr/mirroring/fs/metrics/load.py b/src/pybind/mgr/mirroring/fs/metrics/load.py index dc7682fa707..8b2ae3641ae 100644 --- a/src/pybind/mgr/mirroring/fs/metrics/load.py +++ b/src/pybind/mgr/mirroring/fs/metrics/load.py @@ -16,7 +16,11 @@ from ..utils import ( parse_sync_stat_omap_key, sync_stat_omap_key, ) -from .format import format_and_order_sync_stat_for_display, format_peer_status_metrics +from .format import ( + default_sync_stat_metrics, + format_and_order_sync_stat_for_display, + format_peer_status_metrics, +) log = logging.getLogger(__name__) @@ -57,8 +61,23 @@ def open_metadata_ioctx(rados_inst, fs_map, filesystem): f'failed to open metadata pool for {filesystem}') +def _fill_missing_sync_stat_defaults(metrics, dir_paths, peers, policy, + live_instance_ids, peer_uuid=None): + default_stat = default_sync_stat_metrics() + for dir_path in dir_paths: + for peer in peers: + if peer_uuid is not None and peer != peer_uuid: + continue + if metrics.get(dir_path, {}).get('peer', {}).get(peer) is not None: + continue + format_peer_status_metrics( + metrics, dir_path, peer, + format_and_order_sync_stat_for_display( + default_stat, policy, dir_path, live_instance_ids)) + + def load_sync_stat_metrics(ioctx, filesystem, peer_uuid=None, policy=None, - live_instance_ids=None): + live_instance_ids=None, peers=None): metrics: Dict[str, Any] = {} prefix = f'{SYNC_STAT_KEY_PREFIX}/{filesystem}/' if peer_uuid: @@ -96,6 +115,11 @@ def load_sync_stat_metrics(ioctx, filesystem, peer_uuid=None, policy=None, except rados.Error as e: log.error(f'failed to read sync stat omap: {e}') raise MirrorException(-e.errno, 'failed to read sync stat omap') + if policy is not None and peers: + with policy.lock: + dir_paths = list(policy.dir_states.keys()) + _fill_missing_sync_stat_defaults( + metrics, dir_paths, peers, policy, live_instance_ids, peer_uuid) return metrics @@ -106,14 +130,14 @@ def fetch_sync_stat_metrics(ioctx, filesystem, peers, mirrored_dir_path, keys = [sync_stat_omap_key(filesystem, peer, dir_path) for peer in peers] omap_stats = load_sync_stat_by_keys(ioctx, keys) metrics: Dict[str, Any] = {} + default_stat = default_sync_stat_metrics() for peer in peers: omap_key = sync_stat_omap_key(filesystem, peer, dir_path) - stat = omap_stats.get(omap_key) - if stat is not None: - format_peer_status_metrics( - metrics, dir_path, peer, - format_and_order_sync_stat_for_display( - stat, policy, dir_path, live_instance_ids)) + stat = omap_stats.get(omap_key, default_stat) + format_peer_status_metrics( + metrics, dir_path, peer, + format_and_order_sync_stat_for_display( + stat, policy, dir_path, live_instance_ids)) return metrics, False, dir_path metrics = load_sync_stat_metrics( diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index 5c6a1230d31..ec7e838af52 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -786,7 +786,8 @@ class FSSnapshotMirror: self.rados, self.fs_map, filesystem) return metrics_load.load_sync_stat_metrics( ioctx, filesystem, None, fspolicy.policy, - fspolicy.get_live_instance_ids()) + fspolicy.get_live_instance_ids(), + self.get_filesystem_peers(filesystem)) @lru_cache_timeout( lambda self, *_args, **_kwargs: CACHE_TTL_SECS,