]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/mirroring: Show default stats on newly added dir_root
authorKotresh HR <khiremat@redhat.com>
Sun, 21 Jun 2026 17:35:30 +0000 (23:05 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 23 Jun 2026 15:19:29 +0000 (20:49 +0530)
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 <khiremat@redhat.com>
src/pybind/mgr/mirroring/fs/metrics/format.py
src/pybind/mgr/mirroring/fs/metrics/load.py
src/pybind/mgr/mirroring/fs/snapshot_mirror.py

index 87fc6c4a86aedcdbf4c767d9d7306f623b9fd94a..943eeb14e2c42848ca3e4082a1691b3bcc33b94a 100644 (file)
@@ -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))
index dc7682fa707896043c6fd8a5e14b119529ac769f..8b2ae3641aeb813e329141818fbde2c8dfe3ac16 100644 (file)
@@ -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(
index 5c6a1230d31d1dda00346f7e261a492ac2737f64..ec7e838af52f2a58460a378dc43c28483389f999 100644 (file)
@@ -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,