]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/journal/ReplayStatusFormatter.h
5ba000a16664c413ce663a88e354c292db31159d
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / journal / ReplayStatusFormatter.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H
6
7 #include "include/Context.h"
8 #include "common/ceph_mutex.h"
9 #include "cls/journal/cls_journal_types.h"
10 #include "librbd/journal/Types.h"
11 #include "librbd/journal/TypeTraits.h"
12
13 namespace journal { class Journaler; }
14 namespace librbd { class ImageCtx; }
15
16 namespace rbd {
17 namespace mirror {
18 namespace image_replayer {
19 namespace journal {
20
21 template <typename ImageCtxT = librbd::ImageCtx>
22 class ReplayStatusFormatter {
23 public:
24 typedef typename librbd::journal::TypeTraits<ImageCtxT>::Journaler Journaler;
25
26 static ReplayStatusFormatter* create(Journaler *journaler,
27 const std::string &mirror_uuid) {
28 return new ReplayStatusFormatter(journaler, mirror_uuid);
29 }
30
31 static void destroy(ReplayStatusFormatter* formatter) {
32 delete formatter;
33 }
34
35 ReplayStatusFormatter(Journaler *journaler, const std::string &mirror_uuid);
36
37 bool get_or_send_update(std::string *description, Context *on_finish);
38
39 private:
40 Journaler *m_journaler;
41 std::string m_mirror_uuid;
42 ceph::mutex m_lock;
43 Context *m_on_finish = nullptr;
44 cls::journal::ObjectPosition m_master_position;
45 cls::journal::ObjectPosition m_mirror_position;
46 int m_entries_behind_master = 0;
47 cls::journal::Tag m_tag;
48 std::map<uint64_t, librbd::journal::TagData> m_tag_cache;
49
50 bool calculate_behind_master_or_send_update();
51 void send_update_tag_cache(uint64_t master_tag_tid, uint64_t mirror_tag_tid);
52 void handle_update_tag_cache(uint64_t master_tag_tid, uint64_t mirror_tag_tid,
53 int r);
54 void format(std::string *description);
55 };
56
57 } // namespace journal
58 } // namespace image_replayer
59 } // namespace mirror
60 } // namespace rbd
61
62 extern template class rbd::mirror::image_replayer::journal::ReplayStatusFormatter<librbd::ImageCtx>;
63
64 #endif // RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H