return static_cast<uint64_t>((static_cast<double>(num) * 10000.0) / den);
}
+double monotime_to_double(monotime t) {
+ return sec_duration(t.time_since_epoch()).count();
+}
+
void PeerReplayer::create_directory_perf_counters(const std::string &dir_root) {
ceph_assert(m_directory_perf_counters.find(dir_root) ==
m_directory_perf_counters.end());
}
}
+void PeerReplayer::update_directory_last_sync_perf_counters(
+ PerfCounters *perf, const SnapSyncStat &sync_stat) {
+ if (!perf) {
+ return;
+ }
+
+ if (sync_stat.last_synced_snap) {
+ perf->set(l_cephfs_mirror_directory_last_snap_id,
+ sync_stat.last_synced_snap->first);
+ } else {
+ perf->set(l_cephfs_mirror_directory_last_snap_id, 0);
+ }
+
+ perf->set(l_cephfs_mirror_directory_last_crawl_duration_seconds,
+ sync_stat.last_sync_crawl_duration ?
+ static_cast<uint64_t>(*sync_stat.last_sync_crawl_duration) : 0);
+ perf->set(l_cephfs_mirror_directory_last_datasync_wait_duration_seconds,
+ sync_stat.last_sync_datasync_queue_wait_duration ?
+ static_cast<uint64_t>(*sync_stat.last_sync_datasync_queue_wait_duration) : 0);
+ perf->set(l_cephfs_mirror_directory_last_sync_duration_seconds,
+ sync_stat.last_sync_duration ?
+ static_cast<uint64_t>(*sync_stat.last_sync_duration) : 0);
+
+ utime_t t;
+ if (!clock::is_zero(sync_stat.last_synced)) {
+ t.set_from_double(monotime_to_double(sync_stat.last_synced));
+ } else {
+ t = utime_t();
+ }
+ perf->tset(l_cephfs_mirror_directory_last_sync_timestamp, t);
+
+ perf->set(l_cephfs_mirror_directory_last_sync_bytes,
+ sync_stat.last_sync_bytes ? *sync_stat.last_sync_bytes : 0);
+ perf->set(l_cephfs_mirror_directory_last_sync_files,
+ sync_stat.last_sync_files ? *sync_stat.last_sync_files : 0);
+}
+
+void PeerReplayer::update_directory_summary_perf_counters(
+ PerfCounters *perf, const SnapSyncStat &sync_stat) {
+ if (!perf) {
+ return;
+ }
+
+ perf->set(l_cephfs_mirror_directory_snaps_synced, sync_stat.synced_snap_count);
+ perf->set(l_cephfs_mirror_directory_snaps_deleted, sync_stat.deleted_snap_count);
+ perf->set(l_cephfs_mirror_directory_snaps_renamed, sync_stat.renamed_snap_count);
+}
+
void PeerReplayer::refresh_directory_current_sync_perf_counters(
const std::string &dir_root) {
// caller must hold m_lock
}
for (auto &dir_root : m_directories) {
create_directory_perf_counters(dir_root);
+ auto *dir_perf = find_directory_perf_counters(dir_root);
+ update_directory_last_sync_perf_counters(dir_perf,
+ m_snap_sync_stats.at(dir_root));
+ update_directory_summary_perf_counters(dir_perf,
+ m_snap_sync_stats.at(dir_root));
}
auto &remote_client = m_peer.remote.client_name;
m_directory_perf_counters.end()) {
create_directory_perf_counters(_dir_root);
}
+ auto *dir_perf = find_directory_perf_counters(_dir_root);
+ update_directory_last_sync_perf_counters(dir_perf,
+ m_snap_sync_stats.at(_dir_root));
+ update_directory_summary_perf_counters(dir_perf,
+ m_snap_sync_stats.at(_dir_root));
m_cond.notify_all();
}
} else {
_reset_failed_count(dir_root);
}
+ if (auto *dir_perf = find_directory_perf_counters(dir_root)) {
+ update_directory_current_sync_perf_counters(dir_perf,
+ m_snap_sync_stats.at(dir_root));
+ }
return r;
}
}
} else {
_inc_failed_count(*dir_root);
+ if (auto *dir_perf = find_directory_perf_counters(*dir_root)) {
+ update_directory_current_sync_perf_counters(
+ dir_perf, m_snap_sync_stats.at(*dir_root));
+ }
if (m_perf_counters) {
m_perf_counters->inc(l_cephfs_mirror_peer_replayer_snap_sync_failures);
}
const std::string &snap_name) {
std::scoped_lock locker(m_lock);
_set_last_synced_snap(dir_root, snap_id, snap_name);
+ if (auto *dir_perf = find_directory_perf_counters(dir_root)) {
+ update_directory_last_sync_perf_counters(dir_perf,
+ m_snap_sync_stats.at(dir_root));
+ }
}
void set_current_syncing_snap(const std::string &dir_root, uint64_t snap_id,
const std::string &snap_name) {
std::scoped_lock locker(m_lock);
auto &sync_stat = m_snap_sync_stats.at(dir_root);
++sync_stat.deleted_snap_count;
+ if (auto *dir_perf = find_directory_perf_counters(dir_root)) {
+ update_directory_summary_perf_counters(dir_perf, sync_stat);
+ }
}
void inc_renamed_snap(const std::string &dir_root) {
std::scoped_lock locker(m_lock);
auto &sync_stat = m_snap_sync_stats.at(dir_root);
++sync_stat.renamed_snap_count;
+ if (auto *dir_perf = find_directory_perf_counters(dir_root)) {
+ update_directory_summary_perf_counters(dir_perf, sync_stat);
+ }
}
void set_last_synced_stat(const std::string &dir_root, uint64_t snap_id,
const std::string &snap_name, double duration) {
sync_stat.last_sync_files = sync_stat.sync_files;
++sync_stat.synced_snap_count;
_reset_sync_stat(dir_root);
+ if (auto *dir_perf = find_directory_perf_counters(dir_root)) {
+ update_directory_last_sync_perf_counters(dir_perf, sync_stat);
+ update_directory_summary_perf_counters(dir_perf, sync_stat);
+ }
}
void set_snapdiff(const std::string &dir_root, bool snapdiff) {
std::scoped_lock locker(m_lock);
PerfCounters *find_directory_perf_counters(const std::string &dir_root);
void update_directory_current_sync_perf_counters(PerfCounters *perf,
const SnapSyncStat &sync_stat);
+ void update_directory_last_sync_perf_counters(PerfCounters *perf,
+ const SnapSyncStat &sync_stat);
+ void update_directory_summary_perf_counters(PerfCounters *perf,
+ const SnapSyncStat &sync_stat);
void refresh_directory_current_sync_perf_counters(const std::string &dir_root);
void run(SnapshotReplayerThread *replayer);