summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h
blob: 2b6fb659be3434ae48c1f792e09ea61213d5d833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_PREPARE_REPLAY_REQUEST_H
#define RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_PREPARE_REPLAY_REQUEST_H

#include "include/int_types.h"
#include "cls/journal/cls_journal_types.h"
#include "librbd/journal/Types.h"
#include "librbd/mirror/Types.h"
#include "tools/rbd_mirror/BaseRequest.h"
#include <list>
#include <string>

struct Context;
namespace librbd { struct ImageCtx; }

namespace rbd {
namespace mirror {

class ProgressContext;

namespace image_replayer {
namespace journal {

template <typename> class StateBuilder;

template <typename ImageCtxT>
class PrepareReplayRequest : public BaseRequest {
public:
  static PrepareReplayRequest* create(
      const std::string& local_mirror_uuid,
      ProgressContext* progress_ctx,
      StateBuilder<ImageCtxT>* state_builder,
      bool* resync_requested,
      bool* syncing,
      Context* on_finish) {
    return new PrepareReplayRequest(
      local_mirror_uuid, progress_ctx, state_builder, resync_requested,
      syncing, on_finish);
  }

  PrepareReplayRequest(
      const std::string& local_mirror_uuid,
      ProgressContext* progress_ctx,
      StateBuilder<ImageCtxT>* state_builder,
      bool* resync_requested,
      bool* syncing,
      Context* on_finish)
    : BaseRequest(on_finish),
      m_local_mirror_uuid(local_mirror_uuid),
      m_progress_ctx(progress_ctx),
      m_state_builder(state_builder),
      m_resync_requested(resync_requested),
      m_syncing(syncing) {
  }

  void send() override;

private:
  /**
   * @verbatim
   *
   * <start>
   *    |
   *    v
   * UPDATE_CLIENT_STATE
   *    |
   *    v
   * GET_REMOTE_TAG_CLASS
   *    |
   *    v
   * GET_REMOTE_TAGS
   *    |
   *    v
   * <finish>
   *
   * @endverbatim
   */
  typedef std::list<cls::journal::Tag> Tags;

  std::string m_local_mirror_uuid;
  ProgressContext* m_progress_ctx;
  StateBuilder<ImageCtxT>* m_state_builder;
  bool* m_resync_requested;
  bool* m_syncing;

  uint64_t m_local_tag_tid = 0;
  librbd::journal::TagData m_local_tag_data;

  uint64_t m_remote_tag_class = 0;
  Tags m_remote_tags;
  cls::journal::Client m_client;

  void update_client_state();
  void handle_update_client_state(int r);

  void get_remote_tag_class();
  void handle_get_remote_tag_class(int r);

  void get_remote_tags();
  void handle_get_remote_tags(int r);

  void update_progress(const std::string& description);

};

} // namespace journal
} // namespace image_replayer
} // namespace mirror
} // namespace rbd

extern template class rbd::mirror::image_replayer::journal::PrepareReplayRequest<librbd::ImageCtx>;

#endif // RBD_MIRROR_IMAGE_REPLAYER_JOURNAL_PREPARE_REPLAY_REQUEST_H