]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
7c673cae FG |
3 | |
4 | #ifndef CEPH_RGW_METADATA_H | |
5 | #define CEPH_RGW_METADATA_H | |
6 | ||
7 | #include <string> | |
11fdf7f2 | 8 | #include <utility> |
7c673cae FG |
9 | #include <boost/optional.hpp> |
10 | ||
11 | #include "include/types.h" | |
12 | #include "rgw_common.h" | |
13 | #include "rgw_period_history.h" | |
9f95a23c | 14 | #include "rgw_mdlog_types.h" |
7c673cae FG |
15 | #include "cls/version/cls_version_types.h" |
16 | #include "cls/log/cls_log_types.h" | |
7c673cae FG |
17 | #include "common/RefCountedObj.h" |
18 | #include "common/ceph_time.h" | |
9f95a23c | 19 | #include "services/svc_meta_be.h" |
7c673cae FG |
20 | |
21 | ||
9f95a23c TL |
22 | namespace rgw { namespace sal { |
23 | class RGWRadosStore; | |
24 | } } | |
7c673cae FG |
25 | class RGWCoroutine; |
26 | class JSONObj; | |
27 | struct RGWObjVersionTracker; | |
28 | ||
29 | struct obj_version; | |
30 | ||
31 | ||
7c673cae FG |
32 | class RGWMetadataObject { |
33 | protected: | |
34 | obj_version objv; | |
35 | ceph::real_time mtime; | |
9f95a23c | 36 | std::map<string, bufferlist> *pattrs{nullptr}; |
7c673cae FG |
37 | |
38 | public: | |
39 | RGWMetadataObject() {} | |
40 | virtual ~RGWMetadataObject() {} | |
41 | obj_version& get_version(); | |
9f95a23c TL |
42 | real_time& get_mtime() { return mtime; } |
43 | void set_pattrs(std::map<string, bufferlist> *_pattrs) { | |
44 | pattrs = _pattrs; | |
45 | } | |
46 | std::map<string, bufferlist> *get_pattrs() { | |
47 | return pattrs; | |
48 | } | |
7c673cae | 49 | |
9f95a23c | 50 | virtual void dump(Formatter *f) const {} |
7c673cae FG |
51 | }; |
52 | ||
53 | class RGWMetadataManager; | |
54 | ||
55 | class RGWMetadataHandler { | |
56 | friend class RGWMetadataManager; | |
57 | ||
9f95a23c TL |
58 | protected: |
59 | CephContext *cct; | |
11fdf7f2 | 60 | |
9f95a23c TL |
61 | public: |
62 | RGWMetadataHandler() {} | |
7c673cae FG |
63 | virtual ~RGWMetadataHandler() {} |
64 | virtual string get_type() = 0; | |
65 | ||
9f95a23c TL |
66 | void base_init(CephContext *_cct) { |
67 | cct = _cct; | |
68 | } | |
69 | ||
70 | virtual RGWMetadataObject *get_meta_obj(JSONObj *jo, const obj_version& objv, const ceph::real_time& mtime) = 0; | |
71 | ||
72 | virtual int get(string& entry, RGWMetadataObject **obj, optional_yield) = 0; | |
73 | virtual int put(string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, optional_yield, RGWMDLogSyncType type) = 0; | |
74 | virtual int remove(string& entry, RGWObjVersionTracker& objv_tracker, optional_yield) = 0; | |
75 | ||
76 | virtual int mutate(const string& entry, | |
77 | const ceph::real_time& mtime, | |
78 | RGWObjVersionTracker *objv_tracker, | |
79 | optional_yield y, | |
80 | RGWMDLogStatus op_type, | |
81 | std::function<int()> f) = 0; | |
7c673cae | 82 | |
9f95a23c | 83 | virtual int list_keys_init(const string& marker, void **phandle) = 0; |
7c673cae FG |
84 | virtual int list_keys_next(void *handle, int max, list<string>& keys, bool *truncated) = 0; |
85 | virtual void list_keys_complete(void *handle) = 0; | |
86 | ||
181888fb FG |
87 | virtual string get_marker(void *handle) = 0; |
88 | ||
9f95a23c TL |
89 | virtual int get_shard_id(const string& entry, int *shard_id) { |
90 | *shard_id = 0; | |
91 | return 0; | |
7c673cae | 92 | } |
9f95a23c TL |
93 | virtual int attach(RGWMetadataManager *manager); |
94 | }; | |
95 | ||
96 | class RGWMetadataHandler_GenericMetaBE : public RGWMetadataHandler { | |
97 | friend class RGWSI_MetaBackend; | |
98 | friend class RGWMetadataManager; | |
99 | friend class Put; | |
100 | ||
101 | public: | |
102 | class Put; | |
7c673cae FG |
103 | |
104 | protected: | |
9f95a23c TL |
105 | RGWSI_MetaBackend_Handler *be_handler; |
106 | ||
107 | virtual int do_get(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject **obj, optional_yield y) = 0; | |
108 | virtual int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject *obj, | |
109 | RGWObjVersionTracker& objv_tracker, optional_yield y, RGWMDLogSyncType type) = 0; | |
110 | virtual int do_put_operate(Put *put_op); | |
111 | virtual int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y) = 0; | |
112 | ||
113 | public: | |
114 | RGWMetadataHandler_GenericMetaBE() {} | |
115 | ||
116 | void base_init(CephContext *_cct, | |
117 | RGWSI_MetaBackend_Handler *_be_handler) { | |
118 | RGWMetadataHandler::base_init(_cct); | |
119 | be_handler = _be_handler; | |
120 | } | |
121 | ||
122 | RGWSI_MetaBackend_Handler *get_be_handler() { | |
123 | return be_handler; | |
124 | } | |
125 | ||
126 | class Put { | |
127 | protected: | |
128 | RGWMetadataHandler_GenericMetaBE *handler; | |
129 | RGWSI_MetaBackend_Handler::Op *op; | |
130 | string& entry; | |
131 | RGWMetadataObject *obj; | |
132 | RGWObjVersionTracker& objv_tracker; | |
133 | RGWMDLogSyncType apply_type; | |
134 | optional_yield y; | |
135 | ||
136 | int get(RGWMetadataObject **obj) { | |
137 | return handler->do_get(op, entry, obj, y); | |
138 | } | |
139 | public: | |
140 | Put(RGWMetadataHandler_GenericMetaBE *_handler, RGWSI_MetaBackend_Handler::Op *_op, | |
141 | string& _entry, RGWMetadataObject *_obj, | |
142 | RGWObjVersionTracker& _objv_tracker, optional_yield _y, | |
143 | RGWMDLogSyncType _type); | |
144 | ||
145 | virtual ~Put() {} | |
146 | ||
147 | virtual int put_pre() { | |
148 | return 0; | |
149 | } | |
150 | virtual int put() { | |
151 | return 0; | |
152 | } | |
153 | virtual int put_post() { | |
154 | return 0; | |
155 | } | |
156 | virtual int finalize() { | |
157 | return 0; | |
158 | } | |
159 | }; | |
160 | ||
161 | int get(string& entry, RGWMetadataObject **obj, optional_yield) override; | |
162 | int put(string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, optional_yield, RGWMDLogSyncType type) override; | |
163 | int remove(string& entry, RGWObjVersionTracker& objv_tracker, optional_yield) override; | |
164 | ||
165 | int mutate(const string& entry, | |
166 | const ceph::real_time& mtime, | |
167 | RGWObjVersionTracker *objv_tracker, | |
168 | optional_yield y, | |
169 | RGWMDLogStatus op_type, | |
170 | std::function<int()> f) override; | |
171 | ||
172 | int get_shard_id(const string& entry, int *shard_id) override; | |
173 | ||
174 | int list_keys_init(const std::string& marker, void **phandle) override; | |
175 | int list_keys_next(void *handle, int max, std::list<string>& keys, bool *truncated) override; | |
176 | void list_keys_complete(void *handle) override; | |
177 | ||
178 | std::string get_marker(void *handle) override; | |
179 | ||
7c673cae FG |
180 | /** |
181 | * Compare an incoming versus on-disk tag/version+mtime combo against | |
182 | * the sync mode to see if the new one should replace the on-disk one. | |
183 | * | |
184 | * @return true if the update should proceed, false otherwise. | |
185 | */ | |
9f95a23c TL |
186 | static bool check_versions(bool exists, |
187 | const obj_version& ondisk, const real_time& ondisk_time, | |
11fdf7f2 | 188 | const obj_version& incoming, const real_time& incoming_time, |
9f95a23c | 189 | RGWMDLogSyncType sync_mode) { |
7c673cae FG |
190 | switch (sync_mode) { |
191 | case APPLY_UPDATES: | |
192 | if ((ondisk.tag != incoming.tag) || | |
193 | (ondisk.ver >= incoming.ver)) | |
194 | return false; | |
195 | break; | |
196 | case APPLY_NEWER: | |
197 | if (ondisk_time >= incoming_time) | |
198 | return false; | |
199 | break; | |
9f95a23c TL |
200 | case APPLY_EXCLUSIVE: |
201 | if (exists) | |
202 | return false; | |
203 | break; | |
7c673cae FG |
204 | case APPLY_ALWAYS: //deliberate fall-thru -- we always apply! |
205 | default: break; | |
206 | } | |
207 | return true; | |
208 | } | |
7c673cae FG |
209 | }; |
210 | ||
9f95a23c | 211 | class RGWMetadataTopHandler; |
7c673cae | 212 | |
9f95a23c TL |
213 | class RGWMetadataManager { |
214 | friend class RGWMetadataHandler; | |
7c673cae | 215 | |
7c673cae | 216 | CephContext *cct; |
9f95a23c | 217 | RGWSI_Meta *meta_svc; |
7c673cae | 218 | map<string, RGWMetadataHandler *> handlers; |
9f95a23c | 219 | std::unique_ptr<RGWMetadataTopHandler> md_top_handler; |
7c673cae | 220 | |
7c673cae | 221 | int find_handler(const string& metadata_key, RGWMetadataHandler **handler, string& entry); |
9f95a23c | 222 | int register_handler(RGWMetadataHandler *handler); |
11fdf7f2 | 223 | |
7c673cae | 224 | public: |
9f95a23c | 225 | RGWMetadataManager(RGWSI_Meta *_meta_svc); |
7c673cae FG |
226 | ~RGWMetadataManager(); |
227 | ||
7c673cae FG |
228 | RGWMetadataHandler *get_handler(const string& type); |
229 | ||
9f95a23c TL |
230 | int get(string& metadata_key, Formatter *f, optional_yield y); |
231 | int put(string& metadata_key, bufferlist& bl, optional_yield y, | |
232 | RGWMDLogSyncType sync_mode, | |
7c673cae | 233 | obj_version *existing_version = NULL); |
9f95a23c TL |
234 | int remove(string& metadata_key, optional_yield y); |
235 | ||
236 | int mutate(const string& metadata_key, | |
237 | const ceph::real_time& mtime, | |
238 | RGWObjVersionTracker *objv_tracker, | |
239 | optional_yield y, | |
240 | RGWMDLogStatus op_type, | |
241 | std::function<int()> f); | |
7c673cae | 242 | |
b32b8144 FG |
243 | int list_keys_init(const string& section, void **phandle); |
244 | int list_keys_init(const string& section, const string& marker, void **phandle); | |
7c673cae FG |
245 | int list_keys_next(void *handle, int max, list<string>& keys, bool *truncated); |
246 | void list_keys_complete(void *handle); | |
247 | ||
181888fb FG |
248 | string get_marker(void *handle); |
249 | ||
7c673cae FG |
250 | void dump_log_entry(cls_log_entry& entry, Formatter *f); |
251 | ||
252 | void get_sections(list<string>& sections); | |
11fdf7f2 TL |
253 | |
254 | void parse_metadata_key(const string& metadata_key, string& type, string& entry); | |
9f95a23c TL |
255 | |
256 | int get_shard_id(const string& section, const string& key, int *shard_id); | |
7c673cae FG |
257 | }; |
258 | ||
9f95a23c | 259 | class RGWMetadataHandlerPut_SObj : public RGWMetadataHandler_GenericMetaBE::Put |
11fdf7f2 | 260 | { |
9f95a23c TL |
261 | protected: |
262 | std::unique_ptr<RGWMetadataObject> oo; | |
263 | RGWMetadataObject *old_obj{nullptr}; | |
264 | bool exists{false}; | |
11fdf7f2 | 265 | |
9f95a23c TL |
266 | public: |
267 | RGWMetadataHandlerPut_SObj(RGWMetadataHandler_GenericMetaBE *handler, RGWSI_MetaBackend_Handler::Op *op, | |
268 | string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, | |
269 | optional_yield y, | |
270 | RGWMDLogSyncType type); | |
271 | ~RGWMetadataHandlerPut_SObj(); | |
272 | ||
273 | int put_pre() override; | |
274 | int put() override; | |
275 | virtual int put_check() { | |
276 | return 0; | |
11fdf7f2 | 277 | } |
9f95a23c TL |
278 | virtual int put_checked(); |
279 | virtual void encode_obj(bufferlist *bl) {} | |
280 | }; | |
11fdf7f2 | 281 | |
11fdf7f2 | 282 | |
7c673cae | 283 | #endif |