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_EVENT_PREPROCESSOR_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_EVENT_PREPROCESSOR_H
7 #include "include/int_types.h"
8 #include "librbd/journal/Types.h"
9 #include "librbd/journal/TypeTraits.h"
12 #include <boost/variant/static_visitor.hpp>
16 namespace journal { class Journaler; }
17 namespace librbd { class ImageCtx; }
21 namespace image_replayer {
23 template <typename ImageCtxT = librbd::ImageCtx>
24 class EventPreprocessor {
26 using Journaler = typename librbd::journal::TypeTraits<ImageCtxT>::Journaler;
27 using EventEntry = librbd::journal::EventEntry;
28 using MirrorPeerClientMeta = librbd::journal::MirrorPeerClientMeta;
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);
39 static void destroy(EventPreprocessor* processor) {
43 EventPreprocessor(ImageCtxT &local_image_ctx, Journaler &remote_journaler,
44 const std::string &local_mirror_uuid,
45 MirrorPeerClientMeta *client_meta, ContextWQ *work_queue);
48 bool is_required(const EventEntry &event_entry);
49 void preprocess(EventEntry *event_entry, Context *on_finish);
57 * v (skip if not required)
60 * v (skip if not required)
63 * v (skip if not required)
69 typedef std::map<uint64_t, uint64_t> SnapSeqs;
71 class PreprocessEventVisitor : public boost::static_visitor<int> {
73 EventPreprocessor *event_preprocessor;
75 PreprocessEventVisitor(EventPreprocessor *event_preprocessor)
76 : event_preprocessor(event_preprocessor) {
80 inline int operator()(T&) const {
83 inline int operator()(librbd::journal::SnapRenameEvent &event) const {
84 return event_preprocessor->preprocess_snap_rename(event);
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;
94 bool m_in_progress = false;
95 EventEntry *m_event_entry = nullptr;
96 Context *m_on_finish = nullptr;
99 bool m_snap_seqs_updated = false;
101 bool prune_snap_map(SnapSeqs *snap_seqs);
103 void refresh_image();
104 void handle_refresh_image(int r);
106 void preprocess_event();
107 int preprocess_snap_rename(librbd::journal::SnapRenameEvent &event);
109 void update_client();
110 void handle_update_client(int r);
116 } // namespace image_replayer
117 } // namespace mirror
120 extern template class rbd::mirror::image_replayer::EventPreprocessor<librbd::ImageCtx>;
122 #endif // RBD_MIRROR_IMAGE_REPLAYER_EVENT_PREPROCESSOR_H