From: Kotresh HR Date: Wed, 21 Jan 2026 11:55:36 +0000 (+0530) Subject: tools/cephfs_mirror: Add bytes metric X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=185ecbaddb009b0f3b07d4e1f4bda1cf1aa0fae4;p=ceph-ci.git tools/cephfs_mirror: Add bytes metric Add sync_bytes, total_bytes and sync_percentage to current_syncing_snap as below { "/d0": { "state": "syncing", "current_syncing_snap": { "id": 3, "name": "d0_snap2", "bytes": { "sync_bytes": 149564940, "total_bytes": 149700128, "sync_percent": "99.91%" } }, "last_synced_snap": { "id": 2, "name": "d0_snap1", "sync_duration": 45, "sync_time_stamp": "32269.251196s", "sync_bytes": 149684224, }, "snaps_synced": 1, "snaps_deleted": 0, "snaps_renamed": 0 } } Fixes: https://tracker.ceph.com/issues/73453 Signed-off-by: Kotresh HR --- diff --git a/src/tools/cephfs_mirror/PeerReplayer.cc b/src/tools/cephfs_mirror/PeerReplayer.cc index 1284cc01145..68ee414d128 100644 --- a/src/tools/cephfs_mirror/PeerReplayer.cc +++ b/src/tools/cephfs_mirror/PeerReplayer.cc @@ -1303,18 +1303,19 @@ int PeerReplayer::sync_perms(const std::string& path) { return 0; } -PeerReplayer::SyncMechanism::SyncMechanism(std::string_view dir_root, +PeerReplayer::SyncMechanism::SyncMechanism(PeerReplayer& peer_replayer, std::string_view dir_root, MountRef local, MountRef remote, FHandles *fh, const Peer &peer, const Snapshot ¤t, boost::optional prev) - : m_local(local), + : m_peer_replayer(peer_replayer), + m_dir_root(dir_root), + m_local(local), m_remote(remote), m_fh(fh), m_peer(peer), m_current(current), m_prev(prev), - sdq_lock(ceph::make_mutex("cephfs::mirror::PeerReplayer::SyncMechanism" + stringify(peer.uuid))), - m_dir_root(dir_root) { + sdq_lock(ceph::make_mutex("cephfs::mirror::PeerReplayer::SyncMechanism" + stringify(peer.uuid))) { } PeerReplayer::SyncMechanism::~SyncMechanism() { @@ -1323,6 +1324,7 @@ PeerReplayer::SyncMechanism::~SyncMechanism() { void PeerReplayer::SyncMechanism::push_dataq_entry(SyncEntry e) { dout(10) << ": snapshot data replayer dataq pushed" << " syncm=" << this << " epath=" << e.epath << dendl; + m_peer_replayer.inc_total_bytes(std::string(m_dir_root), e.stx.stx_size); std::unique_lock lock(sdq_lock); m_sync_dataq.push(std::move(e)); sdq_cv.notify_all(); @@ -1415,10 +1417,11 @@ int PeerReplayer::SyncMechanism::get_changed_blocks(const std::string &epath, return callback(block.num_blocks, block.b); } -PeerReplayer::SnapDiffSync::SnapDiffSync(std::string_view dir_root, MountRef local, MountRef remote, - FHandles *fh, const Peer &peer, const Snapshot ¤t, +PeerReplayer::SnapDiffSync::SnapDiffSync(PeerReplayer& peer_replayer, std::string_view dir_root, + MountRef local, MountRef remote, FHandles *fh, + const Peer &peer, const Snapshot ¤t, boost::optional prev) - : SyncMechanism(dir_root, local, remote, fh, peer, current, prev) { + : SyncMechanism(peer_replayer, dir_root, local, remote, fh, peer, current, prev) { } PeerReplayer::SnapDiffSync::~SnapDiffSync() { @@ -1725,11 +1728,11 @@ void PeerReplayer::SnapDiffSync::finish_sync(int ret) { mark_crawl_finished(ret); } -PeerReplayer::RemoteSync::RemoteSync(std::string_view dir_root, +PeerReplayer::RemoteSync::RemoteSync(PeerReplayer& peer_replayer, std::string_view dir_root, MountRef local, MountRef remote, FHandles *fh, const Peer &peer, const Snapshot ¤t, boost::optional prev) - : SyncMechanism(dir_root, local, remote, fh, peer, current, prev) { + : SyncMechanism(peer_replayer, dir_root, local, remote, fh, peer, current, prev) { } PeerReplayer::RemoteSync::~RemoteSync() { @@ -1903,11 +1906,11 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu std::shared_ptr syncm; if (fh.p_mnt == m_local_mount) { - syncm = std::make_shared(dir_root, m_local_mount, m_remote_mount, + syncm = std::make_shared(*this, dir_root, m_local_mount, m_remote_mount, &fh, m_peer, current, prev); } else { - syncm = std::make_shared(dir_root, m_local_mount, m_remote_mount, + syncm = std::make_shared(*this, dir_root, m_local_mount, m_remote_mount, &fh, m_peer, current, boost::none); } @@ -2392,7 +2395,30 @@ void PeerReplayer::peer_status(Formatter *f) { f->open_object_section("current_syncing_snap"); f->dump_unsigned("id", (*sync_stat.current_syncing_snap).first); f->dump_string("name", (*sync_stat.current_syncing_snap).second); - f->close_section(); + /* + if (sync_stat.total_bytes > 0) { + const uint64_t synced = sync_stat.sync_bytes; + const uint64_t total = sync_stat.total_bytes; + const double percent = (static_cast(synced) * 100.0) / total; + + std::ostringstream os; + os << synced << "/" << total << " " + << std::fixed << std::setprecision(1) + << percent << "%"; + f->dump_string("bytes", os.str()); + }*/ + f->open_object_section("bytes"); + f->dump_unsigned("sync_bytes", sync_stat.sync_bytes); + f->dump_unsigned("total_bytes", sync_stat.total_bytes); + if (sync_stat.total_bytes > 0) { + double sync_pct = (static_cast(sync_stat.sync_bytes) * 100.0) / sync_stat.total_bytes; + std::ostringstream os; + os << std::fixed << std::setprecision(2) << sync_pct << "%"; + f->dump_string("sync_percent", os.str()); + } + + f->close_section(); //bytes + f->close_section(); //current_syncing_snap } if (sync_stat.last_synced_snap) { f->open_object_section("last_synced_snap"); diff --git a/src/tools/cephfs_mirror/PeerReplayer.h b/src/tools/cephfs_mirror/PeerReplayer.h index 98c94a4838e..930d727cd30 100644 --- a/src/tools/cephfs_mirror/PeerReplayer.h +++ b/src/tools/cephfs_mirror/PeerReplayer.h @@ -186,10 +186,10 @@ private: class SyncMechanism { public: - SyncMechanism(std::string_view dir_root, - MountRef local, MountRef remote, FHandles *fh, - const Peer &peer, /* keep dout happy */ - const Snapshot ¤t, boost::optional prev); + explicit SyncMechanism(PeerReplayer& peer_replayer, std::string_view dir_root, + MountRef local, MountRef remote, FHandles *fh, + const Peer &peer, /* keep dout happy */ + const Snapshot ¤t, boost::optional prev); virtual ~SyncMechanism() = 0; virtual int init_sync() = 0; @@ -265,6 +265,9 @@ private: int remote_mkdir(const std::string &epath, const struct ceph_statx &stx); protected: + PeerReplayer& m_peer_replayer; + // It's not used in RemoteSync but required to be accessed in datasync threads + std::string m_dir_root; MountRef m_local; MountRef m_remote; FHandles *m_fh; @@ -282,13 +285,11 @@ private: bool m_take_snapshot = false; bool m_datasync_error = false; int m_datasync_errno = 0; - // It's not used in RemoteSync but required to be accessed in datasync threads - std::string m_dir_root; }; class RemoteSync : public SyncMechanism { public: - RemoteSync(std::string_view dir_root, + RemoteSync(PeerReplayer& peer_replayer, std::string_view dir_root, MountRef local, MountRef remote, FHandles *fh, const Peer &peer, /* keep dout happy */ const Snapshot ¤t, boost::optional prev); @@ -305,8 +306,8 @@ private: class SnapDiffSync : public SyncMechanism { public: - SnapDiffSync(std::string_view dir_root, MountRef local, MountRef remote, - FHandles *fh, const Peer &peer, const Snapshot ¤t, + SnapDiffSync(PeerReplayer& peer_replayer, std::string_view dir_root, MountRef local, + MountRef remote, FHandles *fh, const Peer &peer, const Snapshot ¤t, boost::optional prev); ~SnapDiffSync(); @@ -351,6 +352,7 @@ private: boost::optional last_sync_duration; boost::optional last_sync_bytes; //last sync bytes for display in status uint64_t sync_bytes = 0; //sync bytes counter, independently for each directory sync. + uint64_t total_bytes = 0; //total bytes counter, independently for each directory sync. }; void _inc_failed_count(const std::string &dir_root) { @@ -392,6 +394,7 @@ private: _set_last_synced_snap(dir_root, snap_id, snap_name); auto &sync_stat = m_snap_sync_stats.at(dir_root); sync_stat.sync_bytes = 0; + sync_stat.total_bytes = 0; } void set_current_syncing_snap(const std::string &dir_root, uint64_t snap_id, const std::string &snap_name) { @@ -429,6 +432,11 @@ private: auto &sync_stat = m_snap_sync_stats.at(dir_root); sync_stat.sync_bytes += b; } + void inc_total_bytes(const std::string &dir_root, const uint64_t& b) { + std::scoped_lock locker(m_lock); + auto &sync_stat = m_snap_sync_stats.at(dir_root); + sync_stat.total_bytes += b; + } bool should_backoff(const std::string &dir_root, int *retval) { if (m_fs_mirror->is_blocklisted()) { *retval = -EBLOCKLISTED;