Skip to content

Commit fa256fa

Browse files
Merge pull request ceph#55701 from joscollin/wip-B62265-use-monotonic-clocks
cephfs-mirror: use monotonic clocks Reviewed-by: Dhairya Parmar <[email protected]> Reviewed-by: Rishabh Dave <[email protected]>
2 parents ac26868 + 7f0e7fe commit fa256fa

File tree

9 files changed

+35
-34
lines changed

9 files changed

+35
-34
lines changed

src/tools/cephfs_mirror/FSMirror.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FSMirror {
5252
m_mirror_watcher->is_failed();
5353
}
5454

55-
utime_t get_failed_ts() {
55+
monotime get_failed_ts() {
5656
std::scoped_lock locker(m_lock);
5757
if (m_instance_watcher) {
5858
return m_instance_watcher->get_failed_ts();
@@ -61,15 +61,15 @@ class FSMirror {
6161
return m_mirror_watcher->get_failed_ts();
6262
}
6363

64-
return utime_t();
64+
return clock::now();
6565
}
6666

6767
bool is_blocklisted() {
6868
std::scoped_lock locker(m_lock);
6969
return is_blocklisted(locker);
7070
}
7171

72-
utime_t get_blocklisted_ts() {
72+
monotime get_blocklisted_ts() {
7373
std::scoped_lock locker(m_lock);
7474
if (m_instance_watcher) {
7575
return m_instance_watcher->get_blocklisted_ts();
@@ -78,7 +78,7 @@ class FSMirror {
7878
return m_mirror_watcher->get_blocklisted_ts();
7979
}
8080

81-
return utime_t();
81+
return clock::now();
8282
}
8383

8484
Peers get_peers() {

src/tools/cephfs_mirror/InstanceWatcher.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ void InstanceWatcher::handle_rewatch_complete(int r) {
116116
dout(0) << ": client blocklisted" <<dendl;
117117
std::scoped_lock locker(m_lock);
118118
m_blocklisted = true;
119-
m_blocklisted_ts = ceph_clock_now();
119+
m_blocklisted_ts = clock::now();
120120
} else if (r == -ENOENT) {
121121
derr << ": mirroring object deleted" << dendl;
122122
m_failed = true;
123-
m_failed_ts = ceph_clock_now();
123+
m_failed_ts = clock::now();
124124
} else if (r < 0) {
125125
derr << ": rewatch error: " << cpp_strerror(r) << dendl;
126126
m_failed = true;
127-
m_failed_ts = ceph_clock_now();
127+
m_failed_ts = clock::now();
128128
}
129129
}
130130

src/tools/cephfs_mirror/InstanceWatcher.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "include/Context.h"
1111
#include "include/rados/librados.hpp"
1212
#include "Watcher.h"
13+
#include "Types.h"
1314

1415
class ContextWQ;
1516

@@ -49,7 +50,7 @@ class InstanceWatcher : public Watcher {
4950
return m_blocklisted;
5051
}
5152

52-
utime_t get_blocklisted_ts() {
53+
monotime get_blocklisted_ts() {
5354
std::scoped_lock locker(m_lock);
5455
return m_blocklisted_ts;
5556
}
@@ -59,7 +60,7 @@ class InstanceWatcher : public Watcher {
5960
return m_failed;
6061
}
6162

62-
utime_t get_failed_ts() {
63+
monotime get_failed_ts() {
6364
std::scoped_lock locker(m_lock);
6465
return m_failed_ts;
6566
}
@@ -76,8 +77,8 @@ class InstanceWatcher : public Watcher {
7677
bool m_blocklisted = false;
7778
bool m_failed = false;
7879

79-
utime_t m_blocklisted_ts;
80-
utime_t m_failed_ts;
80+
monotime m_blocklisted_ts;
81+
monotime m_failed_ts;
8182

8283
void create_instance();
8384
void handle_create_instance(int r);

src/tools/cephfs_mirror/Mirror.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#undef dout_prefix
2323
#define dout_prefix *_dout << "cephfs::mirror::Mirror " << __func__
2424

25+
using namespace std::chrono;
26+
2527
// Performance Counters
2628
enum {
2729
l_cephfs_mirror_first = 4000,
@@ -247,7 +249,7 @@ int Mirror::init_mon_client() {
247249
return r;
248250
}
249251

250-
r = m_monc->authenticate(std::chrono::duration<double>(m_cct->_conf.get_val<std::chrono::seconds>("client_mount_timeout")).count());
252+
r = m_monc->authenticate(duration<double>(m_cct->_conf.get_val<seconds>("client_mount_timeout")).count());
251253
if (r < 0) {
252254
derr << ": failed to authenticate to monitor: " << cpp_strerror(r) << dendl;
253255
return r;
@@ -547,19 +549,18 @@ void Mirror::peer_removed(const Filesystem &filesystem, const Peer &peer) {
547549
void Mirror::update_fs_mirrors() {
548550
dout(20) << dendl;
549551

550-
auto now = ceph_clock_now();
551-
double blocklist_interval = g_ceph_context->_conf.get_val<std::chrono::seconds>
552-
("cephfs_mirror_restart_mirror_on_blocklist_interval").count();
553-
double failed_interval = g_ceph_context->_conf.get_val<std::chrono::seconds>
554-
("cephfs_mirror_restart_mirror_on_failure_interval").count();
552+
seconds blocklist_interval = g_ceph_context->_conf.get_val<seconds>
553+
("cephfs_mirror_restart_mirror_on_blocklist_interval");
554+
seconds failed_interval = g_ceph_context->_conf.get_val<seconds>
555+
("cephfs_mirror_restart_mirror_on_failure_interval");
555556

556557
{
557558
std::scoped_lock locker(m_lock);
558559
for (auto &[filesystem, mirror_action] : m_mirror_actions) {
559560
auto failed_restart = mirror_action.fs_mirror && mirror_action.fs_mirror->is_failed() &&
560-
(failed_interval > 0 && (mirror_action.fs_mirror->get_failed_ts() - now) > failed_interval);
561+
(failed_interval.count() > 0 && duration_cast<seconds>(mirror_action.fs_mirror->get_failed_ts() - clock::now()) > failed_interval);
561562
auto blocklisted_restart = mirror_action.fs_mirror && mirror_action.fs_mirror->is_blocklisted() &&
562-
(blocklist_interval > 0 && (mirror_action.fs_mirror->get_blocklisted_ts() - now) > blocklist_interval);
563+
(blocklist_interval.count() > 0 && duration_cast<seconds>(mirror_action.fs_mirror->get_blocklisted_ts() - clock::now()) > blocklist_interval);
563564

564565
if (!mirror_action.action_in_progress && !_is_restarting(filesystem)) {
565566
if (failed_restart || blocklisted_restart) {
@@ -592,7 +593,7 @@ void Mirror::schedule_mirror_update_task() {
592593
m_timer_task = nullptr;
593594
update_fs_mirrors();
594595
});
595-
double after = g_ceph_context->_conf.get_val<std::chrono::seconds>
596+
double after = g_ceph_context->_conf.get_val<seconds>
596597
("cephfs_mirror_action_update_interval").count();
597598
dout(20) << ": scheduling fs mirror update (" << m_timer_task << ") after "
598599
<< after << " seconds" << dendl;

src/tools/cephfs_mirror/MirrorWatcher.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "aio_utils.h"
1212
#include "MirrorWatcher.h"
1313
#include "FSMirror.h"
14-
#include "Types.h"
1514

1615
#define dout_context g_ceph_context
1716
#define dout_subsys ceph_subsys_cephfs_mirror
@@ -93,15 +92,15 @@ void MirrorWatcher::handle_rewatch_complete(int r) {
9392
dout(0) << ": client blocklisted" <<dendl;
9493
std::scoped_lock locker(m_lock);
9594
m_blocklisted = true;
96-
m_blocklisted_ts = ceph_clock_now();
95+
m_blocklisted_ts = clock::now();
9796
} else if (r == -ENOENT) {
9897
derr << ": mirroring object deleted" << dendl;
9998
m_failed = true;
100-
m_failed_ts = ceph_clock_now();
99+
m_failed_ts = clock::now();
101100
} else if (r < 0) {
102101
derr << ": rewatch error: " << cpp_strerror(r) << dendl;
103102
m_failed = true;
104-
m_failed_ts = ceph_clock_now();
103+
m_failed_ts = clock::now();
105104
}
106105
}
107106

src/tools/cephfs_mirror/MirrorWatcher.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "include/Context.h"
1111
#include "include/rados/librados.hpp"
1212
#include "Watcher.h"
13+
#include "Types.h"
1314

1415
class ContextWQ;
1516
class Messenger;
@@ -47,7 +48,7 @@ class MirrorWatcher : public Watcher {
4748
return m_blocklisted;
4849
}
4950

50-
utime_t get_blocklisted_ts() {
51+
monotime get_blocklisted_ts() {
5152
std::scoped_lock locker(m_lock);
5253
return m_blocklisted_ts;
5354
}
@@ -57,7 +58,7 @@ class MirrorWatcher : public Watcher {
5758
return m_failed;
5859
}
5960

60-
utime_t get_failed_ts() {
61+
monotime get_failed_ts() {
6162
std::scoped_lock locker(m_lock);
6263
return m_failed_ts;
6364
}
@@ -76,8 +77,8 @@ class MirrorWatcher : public Watcher {
7677
bool m_blocklisted = false;
7778
bool m_failed = false;
7879

79-
utime_t m_blocklisted_ts;
80-
utime_t m_failed_ts;
80+
monotime m_blocklisted_ts;
81+
monotime m_failed_ts;
8182

8283
void register_watcher();
8384
void handle_register_watcher(int r);

src/tools/cephfs_mirror/PeerReplayer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ void PeerReplayer::sync_snaps(const std::string &dir_root,
17271727
void PeerReplayer::run(SnapshotReplayerThread *replayer) {
17281728
dout(10) << ": snapshot replayer=" << replayer << dendl;
17291729

1730-
time last_directory_scan = clock::zero();
1730+
monotime last_directory_scan = clock::zero();
17311731
auto scan_interval = g_ceph_context->_conf.get_val<uint64_t>(
17321732
"cephfs_mirror_directory_scan_interval");
17331733

src/tools/cephfs_mirror/PeerReplayer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ class PeerReplayer {
132132
}
133133
};
134134

135-
using clock = ceph::coarse_mono_clock;
136-
using time = ceph::coarse_mono_time;
137-
138135
// stats sent to service daemon
139136
struct ServiceDaemonStats {
140137
uint64_t failed_dir_count = 0;
@@ -143,14 +140,14 @@ class PeerReplayer {
143140

144141
struct SnapSyncStat {
145142
uint64_t nr_failures = 0; // number of consecutive failures
146-
boost::optional<time> last_failed; // lat failed timestamp
143+
boost::optional<monotime> last_failed; // lat failed timestamp
147144
bool failed = false; // hit upper cap for consecutive failures
148145
boost::optional<std::pair<uint64_t, std::string>> last_synced_snap;
149146
boost::optional<std::pair<uint64_t, std::string>> current_syncing_snap;
150147
uint64_t synced_snap_count = 0;
151148
uint64_t deleted_snap_count = 0;
152149
uint64_t renamed_snap_count = 0;
153-
time last_synced = clock::zero();
150+
monotime last_synced = clock::zero();
154151
boost::optional<double> last_sync_duration;
155152
};
156153

src/tools/cephfs_mirror/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ typedef std::shared_ptr<librados::IoCtx> IoCtxRef;
8181
// not a shared_ptr since the type is incomplete
8282
typedef ceph_mount_info *MountRef;
8383

84+
using clock = ceph::coarse_mono_clock;
85+
using monotime = ceph::coarse_mono_time;
8486
} // namespace mirror
8587
} // namespace cephfs
8688

0 commit comments

Comments
 (0)