]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: fix syncing_percent calculation logic in get_replay_status() 50180/head
authorN Balachandran <nibalach@redhat.com>
Thu, 16 Feb 2023 04:57:02 +0000 (10:27 +0530)
committerN Balachandran <nibalach@redhat.com>
Mon, 20 Feb 2023 11:21:44 +0000 (16:51 +0530)
When a snapshot sync is resumed and the get_replay_status function
is called before handle_copy_image_progress, the syncing_percent
value may be greater than 100 as the m_local_object_count is still
set to zero. This commit sets the syncing_percent to 0 in such cases.

Fixes: https://tracker.ceph.com/issues/58706
Signed-off-by: N Balachandran <nibalach@redhat.com>
(cherry picked from commit c7ae0f6eb6a8fb08859454d1b2e81d2dc7b0226f)

src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc

index 4a44a57bc223534ce51ffacb4f9c2c06b041bee0..b2a126b2fb8d46da6eaea52b5ea3c0edf1425b64 100644 (file)
@@ -277,9 +277,17 @@ bool Replayer<I>::get_replay_status(std::string* description,
       matching_remote_snap_it !=
         m_state_builder->remote_image_ctx->snap_info.end()) {
     root_obj["syncing_snapshot_timestamp"] = remote_snap_info->timestamp.sec();
-    root_obj["syncing_percent"] = static_cast<uint64_t>(
-        100 * m_local_mirror_snap_ns.last_copied_object_number /
-        static_cast<float>(std::max<uint64_t>(1U, m_local_object_count)));
+
+    if (m_local_object_count > 0) {
+      root_obj["syncing_percent"] =
+       100 * m_local_mirror_snap_ns.last_copied_object_number /
+       m_local_object_count;
+    } else {
+      // Set syncing_percent to 0 if m_local_object_count has
+      // not yet been set (last_copied_object_number may be > 0
+      // if the sync is being resumed).
+      root_obj["syncing_percent"] = 0;
+    }
   }
 
   m_bytes_per_second(0);