]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_JOURNAL_JOURNALER_H | |
5 | #define CEPH_JOURNAL_JOURNALER_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/buffer_fwd.h" | |
9 | #include "include/Context.h" | |
10 | #include "include/rados/librados.hpp" | |
11 | #include "journal/Future.h" | |
12 | #include "journal/JournalMetadataListener.h" | |
13 | #include "cls/journal/cls_journal_types.h" | |
14 | #include <list> | |
15 | #include <map> | |
16 | #include <string> | |
11fdf7f2 | 17 | #include "include/ceph_assert.h" |
7c673cae FG |
18 | |
19 | class ContextWQ; | |
20 | class SafeTimer; | |
21 | class ThreadPool; | |
22 | ||
23 | namespace journal { | |
24 | ||
9f95a23c TL |
25 | struct CacheManagerHandler; |
26 | ||
7c673cae FG |
27 | class JournalTrimmer; |
28 | class ReplayEntry; | |
29 | class ReplayHandler; | |
30 | class Settings; | |
31 | ||
32 | class Journaler { | |
33 | public: | |
34 | struct Threads { | |
35 | Threads(CephContext *cct); | |
36 | ~Threads(); | |
37 | ||
38 | ThreadPool *thread_pool = nullptr; | |
39 | ContextWQ *work_queue = nullptr; | |
40 | ||
9f95a23c TL |
41 | SafeTimer *timer; |
42 | ceph::mutex timer_lock = ceph::make_mutex("Journaler::timer_lock"); | |
7c673cae FG |
43 | }; |
44 | ||
45 | typedef cls::journal::Tag Tag; | |
46 | typedef std::list<cls::journal::Tag> Tags; | |
47 | typedef std::set<cls::journal::Client> RegisteredClients; | |
48 | ||
49 | static std::string header_oid(const std::string &journal_id); | |
50 | static std::string object_oid_prefix(int pool_id, | |
51 | const std::string &journal_id); | |
52 | ||
53 | Journaler(librados::IoCtx &header_ioctx, const std::string &journal_id, | |
9f95a23c TL |
54 | const std::string &client_id, const Settings &settings, |
55 | CacheManagerHandler *cache_manager_handler); | |
56 | Journaler(ContextWQ *work_queue, SafeTimer *timer, ceph::mutex *timer_lock, | |
7c673cae | 57 | librados::IoCtx &header_ioctx, const std::string &journal_id, |
9f95a23c TL |
58 | const std::string &client_id, const Settings &settings, |
59 | CacheManagerHandler *cache_manager_handler); | |
7c673cae FG |
60 | ~Journaler(); |
61 | ||
62 | void exists(Context *on_finish) const; | |
63 | void create(uint8_t order, uint8_t splay_width, int64_t pool_id, Context *ctx); | |
64 | void remove(bool force, Context *on_finish); | |
65 | ||
66 | void init(Context *on_init); | |
67 | void shut_down(); | |
68 | void shut_down(Context *on_finish); | |
69 | ||
70 | bool is_initialized() const; | |
71 | ||
72 | void get_immutable_metadata(uint8_t *order, uint8_t *splay_width, | |
73 | int64_t *pool_id, Context *on_finish); | |
74 | void get_mutable_metadata(uint64_t *minimum_set, uint64_t *active_set, | |
75 | RegisteredClients *clients, Context *on_finish); | |
76 | ||
77 | void add_listener(JournalMetadataListener *listener); | |
78 | void remove_listener(JournalMetadataListener *listener); | |
79 | ||
80 | int register_client(const bufferlist &data); | |
81 | void register_client(const bufferlist &data, Context *on_finish); | |
82 | ||
83 | int unregister_client(); | |
84 | void unregister_client(Context *on_finish); | |
85 | ||
86 | void update_client(const bufferlist &data, Context *on_finish); | |
87 | void get_client(const std::string &client_id, cls::journal::Client *client, | |
88 | Context *on_finish); | |
89 | int get_cached_client(const std::string &client_id, | |
90 | cls::journal::Client *client); | |
91 | ||
92 | void flush_commit_position(Context *on_safe); | |
93 | ||
94 | void allocate_tag(const bufferlist &data, cls::journal::Tag *tag, | |
95 | Context *on_finish); | |
96 | void allocate_tag(uint64_t tag_class, const bufferlist &data, | |
97 | cls::journal::Tag *tag, Context *on_finish); | |
98 | void get_tag(uint64_t tag_tid, Tag *tag, Context *on_finish); | |
99 | void get_tags(uint64_t tag_class, Tags *tags, Context *on_finish); | |
100 | void get_tags(uint64_t start_after_tag_tid, uint64_t tag_class, Tags *tags, | |
101 | Context *on_finish); | |
102 | ||
9f95a23c TL |
103 | void start_replay(ReplayHandler* replay_handler); |
104 | void start_live_replay(ReplayHandler* replay_handler, double interval); | |
7c673cae FG |
105 | bool try_pop_front(ReplayEntry *replay_entry, uint64_t *tag_tid = nullptr); |
106 | void stop_replay(); | |
107 | void stop_replay(Context *on_finish); | |
108 | ||
109 | uint64_t get_max_append_size() const; | |
494da23a TL |
110 | void start_append(uint64_t max_in_flight_appends); |
111 | void set_append_batch_options(int flush_interval, uint64_t flush_bytes, | |
112 | double flush_age); | |
7c673cae FG |
113 | Future append(uint64_t tag_tid, const bufferlist &bl); |
114 | void flush_append(Context *on_safe); | |
115 | void stop_append(Context *on_safe); | |
116 | ||
117 | void committed(const ReplayEntry &replay_entry); | |
118 | void committed(const Future &future); | |
119 | ||
120 | void get_metadata(uint8_t *order, uint8_t *splay_width, int64_t *pool_id); | |
121 | ||
122 | private: | |
123 | struct C_InitJournaler : public Context { | |
124 | Journaler *journaler; | |
125 | Context *on_safe; | |
126 | C_InitJournaler(Journaler *_journaler, Context *_on_safe) | |
127 | : journaler(_journaler), on_safe(_on_safe) { | |
128 | } | |
129 | void finish(int r) override { | |
130 | if (r == 0) { | |
131 | r = journaler->init_complete(); | |
132 | } | |
133 | on_safe->complete(r); | |
134 | } | |
135 | }; | |
136 | ||
137 | Threads *m_threads = nullptr; | |
138 | ||
139 | mutable librados::IoCtx m_header_ioctx; | |
140 | librados::IoCtx m_data_ioctx; | |
141 | CephContext *m_cct; | |
142 | std::string m_client_id; | |
9f95a23c | 143 | CacheManagerHandler *m_cache_manager_handler; |
7c673cae FG |
144 | |
145 | std::string m_header_oid; | |
146 | std::string m_object_oid_prefix; | |
147 | ||
148 | bool m_initialized = false; | |
9f95a23c TL |
149 | ceph::ref_t<class JournalMetadata> m_metadata; |
150 | std::unique_ptr<class JournalPlayer> m_player; | |
151 | std::unique_ptr<class JournalRecorder> m_recorder; | |
7c673cae FG |
152 | JournalTrimmer *m_trimmer = nullptr; |
153 | ||
9f95a23c | 154 | void set_up(ContextWQ *work_queue, SafeTimer *timer, ceph::mutex *timer_lock, |
7c673cae FG |
155 | librados::IoCtx &header_ioctx, const std::string &journal_id, |
156 | const Settings &settings); | |
157 | ||
158 | int init_complete(); | |
9f95a23c | 159 | void create_player(ReplayHandler* replay_handler); |
7c673cae FG |
160 | |
161 | friend std::ostream &operator<<(std::ostream &os, | |
162 | const Journaler &journaler); | |
163 | }; | |
164 | ||
165 | std::ostream &operator<<(std::ostream &os, | |
166 | const Journaler &journaler); | |
167 | ||
168 | } // namespace journal | |
169 | ||
170 | #endif // CEPH_JOURNAL_JOURNALER_H |