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<Snapshot> 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() {
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();
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<Snapshot> prev)
- : SyncMechanism(dir_root, local, remote, fh, peer, current, prev) {
+ : SyncMechanism(peer_replayer, dir_root, local, remote, fh, peer, current, prev) {
}
PeerReplayer::SnapDiffSync::~SnapDiffSync() {
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<Snapshot> prev)
- : SyncMechanism(dir_root, local, remote, fh, peer, current, prev) {
+ : SyncMechanism(peer_replayer, dir_root, local, remote, fh, peer, current, prev) {
}
PeerReplayer::RemoteSync::~RemoteSync() {
std::shared_ptr<SyncMechanism> syncm;
if (fh.p_mnt == m_local_mount) {
- syncm = std::make_shared<SnapDiffSync>(dir_root, m_local_mount, m_remote_mount,
+ syncm = std::make_shared<SnapDiffSync>(*this, dir_root, m_local_mount, m_remote_mount,
&fh, m_peer, current, prev);
} else {
- syncm = std::make_shared<RemoteSync>(dir_root, m_local_mount, m_remote_mount,
+ syncm = std::make_shared<RemoteSync>(*this, dir_root, m_local_mount, m_remote_mount,
&fh, m_peer, current, boost::none);
}
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<double>(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<double>(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");
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<Snapshot> 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<Snapshot> prev);
virtual ~SyncMechanism() = 0;
virtual int init_sync() = 0;
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;
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<Snapshot> prev);
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<Snapshot> prev);
~SnapDiffSync();
boost::optional<double> last_sync_duration;
boost::optional<uint64_t> 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) {
_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) {
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;