]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | |
2 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
3 | // vim: ts=8 sw=2 smarttab ft=cpp | |
4 | ||
5 | /* | |
6 | * Ceph - scalable distributed file system | |
7 | * | |
8 | * Copyright (C) 2019 Red Hat, Inc. | |
9 | * | |
10 | * This is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU Lesser General Public | |
12 | * License version 2.1, as published by the Free Software | |
13 | * Foundation. See file COPYING. | |
14 | * | |
15 | */ | |
16 | ||
17 | ||
18 | #pragma once | |
19 | ||
20 | #include "svc_meta_be_params.h" | |
21 | ||
22 | #include "rgw/rgw_service.h" | |
23 | #include "rgw/rgw_mdlog_types.h" | |
24 | ||
25 | class RGWMetadataLogData; | |
26 | ||
27 | class RGWSI_MDLog; | |
28 | class RGWSI_Meta; | |
29 | class RGWObjVersionTracker; | |
30 | class RGWSI_MetaBackend_Handler; | |
31 | ||
32 | class RGWSI_MetaBackend : public RGWServiceInstance | |
33 | { | |
34 | friend class RGWSI_Meta; | |
35 | public: | |
36 | class Module; | |
37 | class Context; | |
38 | protected: | |
39 | RGWSI_MDLog *mdlog_svc{nullptr}; | |
40 | ||
41 | void base_init(RGWSI_MDLog *_mdlog_svc) { | |
42 | mdlog_svc = _mdlog_svc; | |
43 | } | |
44 | ||
45 | int prepare_mutate(RGWSI_MetaBackend::Context *ctx, | |
46 | const std::string& key, | |
47 | const ceph::real_time& mtime, | |
48 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
49 | optional_yield y, |
50 | const DoutPrefixProvider *dpp); | |
9f95a23c TL |
51 | |
52 | virtual int do_mutate(Context *ctx, | |
53 | const std::string& key, | |
54 | const ceph::real_time& mtime, RGWObjVersionTracker *objv_tracker, | |
55 | RGWMDLogStatus op_type, | |
56 | optional_yield y, | |
57 | std::function<int()> f, | |
b3b6e05e TL |
58 | bool generic_prepare, |
59 | const DoutPrefixProvider *dpp); | |
9f95a23c | 60 | |
b3b6e05e TL |
61 | virtual int pre_modify(const DoutPrefixProvider *dpp, |
62 | Context *ctx, | |
9f95a23c TL |
63 | const std::string& key, |
64 | RGWMetadataLogData& log_data, | |
65 | RGWObjVersionTracker *objv_tracker, | |
66 | RGWMDLogStatus op_type, | |
67 | optional_yield y); | |
b3b6e05e TL |
68 | virtual int post_modify(const DoutPrefixProvider *dpp, |
69 | Context *ctx, | |
9f95a23c TL |
70 | const std::string& key, |
71 | RGWMetadataLogData& log_data, | |
72 | RGWObjVersionTracker *objv_tracker, int ret, | |
73 | optional_yield y); | |
74 | public: | |
75 | class Module { | |
76 | /* | |
77 | * Backend specialization module | |
78 | */ | |
79 | public: | |
80 | virtual ~Module() = 0; | |
81 | }; | |
82 | ||
83 | using ModuleRef = std::shared_ptr<Module>; | |
84 | ||
85 | struct Context { /* | |
86 | * A single metadata operation context. Will be holding info about | |
87 | * backend and operation itself; operation might span multiple backend | |
88 | * calls. | |
89 | */ | |
90 | virtual ~Context() = 0; | |
91 | ||
92 | virtual void init(RGWSI_MetaBackend_Handler *h) = 0; | |
93 | }; | |
94 | ||
95 | virtual Context *alloc_ctx() = 0; | |
96 | ||
97 | struct PutParams { | |
98 | ceph::real_time mtime; | |
99 | ||
100 | PutParams() {} | |
101 | PutParams(const ceph::real_time& _mtime) : mtime(_mtime) {} | |
102 | virtual ~PutParams() = 0; | |
103 | }; | |
104 | ||
105 | struct GetParams { | |
106 | GetParams() {} | |
107 | GetParams(ceph::real_time *_pmtime) : pmtime(_pmtime) {} | |
108 | virtual ~GetParams(); | |
109 | ||
110 | ceph::real_time *pmtime{nullptr}; | |
111 | }; | |
112 | ||
113 | struct RemoveParams { | |
114 | virtual ~RemoveParams() = 0; | |
115 | ||
116 | ceph::real_time mtime; | |
117 | }; | |
118 | ||
119 | struct MutateParams { | |
120 | ceph::real_time mtime; | |
121 | RGWMDLogStatus op_type; | |
122 | ||
123 | MutateParams() {} | |
124 | MutateParams(const ceph::real_time& _mtime, | |
125 | RGWMDLogStatus _op_type) : mtime(_mtime), op_type(_op_type) {} | |
126 | virtual ~MutateParams() {} | |
127 | }; | |
128 | ||
129 | enum Type { | |
130 | MDBE_SOBJ = 0, | |
131 | MDBE_OTP = 1, | |
132 | }; | |
133 | ||
134 | RGWSI_MetaBackend(CephContext *cct) : RGWServiceInstance(cct) {} | |
135 | virtual ~RGWSI_MetaBackend() {} | |
136 | ||
137 | virtual Type get_type() = 0; | |
138 | ||
139 | virtual RGWSI_MetaBackend_Handler *alloc_be_handler() = 0; | |
140 | virtual int call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)>) = 0; | |
141 | ||
142 | /* these should be implemented by backends */ | |
143 | virtual int get_entry(RGWSI_MetaBackend::Context *ctx, | |
144 | const std::string& key, | |
145 | RGWSI_MetaBackend::GetParams& params, | |
146 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
147 | optional_yield y, |
148 | const DoutPrefixProvider *dpp) = 0; | |
149 | virtual int put_entry(const DoutPrefixProvider *dpp, | |
150 | RGWSI_MetaBackend::Context *ctx, | |
9f95a23c TL |
151 | const std::string& key, |
152 | RGWSI_MetaBackend::PutParams& params, | |
153 | RGWObjVersionTracker *objv_tracker, | |
154 | optional_yield y) = 0; | |
b3b6e05e TL |
155 | virtual int remove_entry(const DoutPrefixProvider *dpp, |
156 | Context *ctx, | |
9f95a23c TL |
157 | const std::string& key, |
158 | RGWSI_MetaBackend::RemoveParams& params, | |
159 | RGWObjVersionTracker *objv_tracker, | |
160 | optional_yield y) = 0; | |
161 | ||
b3b6e05e | 162 | virtual int list_init(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const string& marker) = 0; |
9f95a23c TL |
163 | virtual int list_next(RGWSI_MetaBackend::Context *ctx, |
164 | int max, list<string> *keys, | |
165 | bool *truncated) = 0; | |
166 | virtual int list_get_marker(RGWSI_MetaBackend::Context *ctx, | |
167 | string *marker) = 0; | |
168 | ||
169 | int call(std::function<int(RGWSI_MetaBackend::Context *)> f) { | |
170 | return call(nullopt, f); | |
171 | } | |
172 | ||
173 | virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> opt, | |
174 | std::function<int(RGWSI_MetaBackend::Context *)> f) = 0; | |
175 | ||
176 | virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx, | |
177 | const std::string& key, | |
178 | int *shard_id) = 0; | |
179 | ||
180 | /* higher level */ | |
181 | virtual int get(Context *ctx, | |
182 | const std::string& key, | |
183 | GetParams ¶ms, | |
184 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
185 | optional_yield y, |
186 | const DoutPrefixProvider *dpp); | |
9f95a23c TL |
187 | |
188 | virtual int put(Context *ctx, | |
189 | const std::string& key, | |
190 | PutParams& params, | |
191 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
192 | optional_yield y, |
193 | const DoutPrefixProvider *dpp); | |
9f95a23c TL |
194 | |
195 | virtual int remove(Context *ctx, | |
196 | const std::string& key, | |
197 | RemoveParams& params, | |
198 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
199 | optional_yield y, |
200 | const DoutPrefixProvider *dpp); | |
9f95a23c TL |
201 | |
202 | virtual int mutate(Context *ctx, | |
203 | const std::string& key, | |
204 | MutateParams& params, | |
205 | RGWObjVersionTracker *objv_tracker, | |
206 | optional_yield y, | |
b3b6e05e TL |
207 | std::function<int()> f, |
208 | const DoutPrefixProvider *dpp); | |
9f95a23c TL |
209 | }; |
210 | ||
211 | class RGWSI_MetaBackend_Handler { | |
212 | RGWSI_MetaBackend *be{nullptr}; | |
213 | ||
214 | public: | |
215 | class Op { | |
216 | friend class RGWSI_MetaBackend_Handler; | |
217 | ||
218 | RGWSI_MetaBackend *be; | |
219 | RGWSI_MetaBackend::Context *be_ctx; | |
220 | ||
221 | Op(RGWSI_MetaBackend *_be, | |
222 | RGWSI_MetaBackend::Context *_ctx) : be(_be), be_ctx(_ctx) {} | |
223 | ||
224 | public: | |
225 | RGWSI_MetaBackend::Context *ctx() { | |
226 | return be_ctx; | |
227 | } | |
228 | ||
229 | int get(const std::string& key, | |
230 | RGWSI_MetaBackend::GetParams ¶ms, | |
231 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
232 | optional_yield y, const DoutPrefixProvider *dpp) { |
233 | return be->get(be_ctx, key, params, objv_tracker, y, dpp); | |
9f95a23c TL |
234 | } |
235 | ||
236 | int put(const std::string& key, | |
237 | RGWSI_MetaBackend::PutParams& params, | |
238 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
239 | optional_yield y, const DoutPrefixProvider *dpp) { |
240 | return be->put(be_ctx, key, params, objv_tracker, y, dpp); | |
9f95a23c TL |
241 | } |
242 | ||
243 | int remove(const std::string& key, | |
244 | RGWSI_MetaBackend::RemoveParams& params, | |
245 | RGWObjVersionTracker *objv_tracker, | |
b3b6e05e TL |
246 | optional_yield y, const DoutPrefixProvider *dpp) { |
247 | return be->remove(be_ctx, key, params, objv_tracker, y, dpp); | |
9f95a23c TL |
248 | } |
249 | ||
250 | int mutate(const std::string& key, | |
251 | RGWSI_MetaBackend::MutateParams& params, | |
252 | RGWObjVersionTracker *objv_tracker, | |
253 | optional_yield y, | |
b3b6e05e TL |
254 | std::function<int()> f, |
255 | const DoutPrefixProvider *dpp) { | |
256 | return be->mutate(be_ctx, key, params, objv_tracker, y, f, dpp); | |
9f95a23c TL |
257 | } |
258 | ||
b3b6e05e TL |
259 | int list_init(const DoutPrefixProvider *dpp, const string& marker) { |
260 | return be->list_init(dpp, be_ctx, marker); | |
9f95a23c TL |
261 | } |
262 | int list_next(int max, list<string> *keys, | |
263 | bool *truncated) { | |
264 | return be->list_next(be_ctx, max, keys, truncated); | |
265 | } | |
266 | int list_get_marker(string *marker) { | |
267 | return be->list_get_marker(be_ctx, marker); | |
268 | } | |
269 | ||
270 | int get_shard_id(const std::string& key, int *shard_id) { | |
271 | return be->get_shard_id(be_ctx, key, shard_id); | |
272 | } | |
273 | }; | |
274 | ||
275 | class Op_ManagedCtx : public Op { | |
276 | std::unique_ptr<RGWSI_MetaBackend::Context> pctx; | |
277 | public: | |
278 | Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler); | |
279 | }; | |
280 | ||
281 | RGWSI_MetaBackend_Handler(RGWSI_MetaBackend *_be) : be(_be) {} | |
282 | virtual ~RGWSI_MetaBackend_Handler() {} | |
283 | ||
284 | int call(std::function<int(Op *)> f) { | |
285 | return call(nullopt, f); | |
286 | } | |
287 | ||
288 | virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> bectx_params, | |
289 | std::function<int(Op *)> f); | |
290 | }; | |
291 |