]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/EventPreprocessor.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / EventPreprocessor.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_EVENT_PREPROCESSOR_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_EVENT_PREPROCESSOR_H
6
7 #include "include/int_types.h"
8 #include "librbd/journal/Types.h"
9 #include "librbd/journal/TypeTraits.h"
10 #include <map>
11 #include <string>
12 #include <boost/variant/static_visitor.hpp>
13
14 struct Context;
15 struct ContextWQ;
16 namespace journal { class Journaler; }
17 namespace librbd { class ImageCtx; }
18
19 namespace rbd {
20 namespace mirror {
21 namespace image_replayer {
22
23 template <typename ImageCtxT = librbd::ImageCtx>
24 class EventPreprocessor {
25 public:
26 using Journaler = typename librbd::journal::TypeTraits<ImageCtxT>::Journaler;
27 using EventEntry = librbd::journal::EventEntry;
28 using MirrorPeerClientMeta = librbd::journal::MirrorPeerClientMeta;
29
30 static EventPreprocessor *create(ImageCtxT &local_image_ctx,
31 Journaler &remote_journaler,
32 const std::string &local_mirror_uuid,
33 MirrorPeerClientMeta *client_meta,
34 ContextWQ *work_queue) {
35 return new EventPreprocessor(local_image_ctx, remote_journaler,
36 local_mirror_uuid, client_meta, work_queue);
37 }
38
39 static void destroy(EventPreprocessor* processor) {
40 delete processor;
41 }
42
43 EventPreprocessor(ImageCtxT &local_image_ctx, Journaler &remote_journaler,
44 const std::string &local_mirror_uuid,
45 MirrorPeerClientMeta *client_meta, ContextWQ *work_queue);
46 ~EventPreprocessor();
47
48 bool is_required(const EventEntry &event_entry);
49 void preprocess(EventEntry *event_entry, Context *on_finish);
50
51 private:
52 /**
53 * @verbatim
54 *
55 * <start>
56 * |
57 * v (skip if not required)
58 * REFRESH_IMAGE
59 * |
60 * v (skip if not required)
61 * PREPROCESS_EVENT
62 * |
63 * v (skip if not required)
64 * UPDATE_CLIENT
65 *
66 * @endverbatim
67 */
68
69 typedef std::map<uint64_t, uint64_t> SnapSeqs;
70
71 class PreprocessEventVisitor : public boost::static_visitor<int> {
72 public:
73 EventPreprocessor *event_preprocessor;
74
75 PreprocessEventVisitor(EventPreprocessor *event_preprocessor)
76 : event_preprocessor(event_preprocessor) {
77 }
78
79 template <typename T>
80 inline int operator()(T&) const {
81 return 0;
82 }
83 inline int operator()(librbd::journal::SnapRenameEvent &event) const {
84 return event_preprocessor->preprocess_snap_rename(event);
85 }
86 };
87
88 ImageCtxT &m_local_image_ctx;
89 Journaler &m_remote_journaler;
90 std::string m_local_mirror_uuid;
91 MirrorPeerClientMeta *m_client_meta;
92 ContextWQ *m_work_queue;
93
94 bool m_in_progress = false;
95 EventEntry *m_event_entry = nullptr;
96 Context *m_on_finish = nullptr;
97
98 SnapSeqs m_snap_seqs;
99 bool m_snap_seqs_updated = false;
100
101 bool prune_snap_map(SnapSeqs *snap_seqs);
102
103 void refresh_image();
104 void handle_refresh_image(int r);
105
106 void preprocess_event();
107 int preprocess_snap_rename(librbd::journal::SnapRenameEvent &event);
108
109 void update_client();
110 void handle_update_client(int r);
111
112 void finish(int r);
113
114 };
115
116 } // namespace image_replayer
117 } // namespace mirror
118 } // namespace rbd
119
120 extern template class rbd::mirror::image_replayer::EventPreprocessor<librbd::ImageCtx>;
121
122 #endif // RBD_MIRROR_IMAGE_REPLAYER_EVENT_PREPROCESSOR_H