1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H
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"
13 namespace journal
{ class Journaler
; }
14 namespace librbd
{ class ImageCtx
; }
18 namespace image_replayer
{
21 template <typename ImageCtxT
= librbd::ImageCtx
>
22 class ReplayStatusFormatter
{
24 typedef typename
librbd::journal::TypeTraits
<ImageCtxT
>::Journaler Journaler
;
26 static ReplayStatusFormatter
* create(Journaler
*journaler
,
27 const std::string
&mirror_uuid
) {
28 return new ReplayStatusFormatter(journaler
, mirror_uuid
);
31 static void destroy(ReplayStatusFormatter
* formatter
) {
35 ReplayStatusFormatter(Journaler
*journaler
, const std::string
&mirror_uuid
);
37 bool get_or_send_update(std::string
*description
, Context
*on_finish
);
40 Journaler
*m_journaler
;
41 std::string m_mirror_uuid
;
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
;
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
,
54 void format(std::string
*description
);
57 } // namespace journal
58 } // namespace image_replayer
62 extern template class rbd::mirror::image_replayer::journal::ReplayStatusFormatter
<librbd::ImageCtx
>;
64 #endif // RBD_MIRROR_IMAGE_REPLAYER_REPLAY_STATUS_FORMATTER_H