]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_meta_be.h
79f0a4aa1ae8ed5e1ee4556c1a766864117b1178
[ceph.git] / ceph / src / rgw / services / svc_meta_be.h
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,
49 optional_yield y,
50 const DoutPrefixProvider *dpp);
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,
58 bool generic_prepare,
59 const DoutPrefixProvider *dpp);
60
61 virtual int pre_modify(const DoutPrefixProvider *dpp,
62 Context *ctx,
63 const std::string& key,
64 RGWMetadataLogData& log_data,
65 RGWObjVersionTracker *objv_tracker,
66 RGWMDLogStatus op_type,
67 optional_yield y);
68 virtual int post_modify(const DoutPrefixProvider *dpp,
69 Context *ctx,
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,
147 optional_yield y,
148 const DoutPrefixProvider *dpp) = 0;
149 virtual int put_entry(const DoutPrefixProvider *dpp,
150 RGWSI_MetaBackend::Context *ctx,
151 const std::string& key,
152 RGWSI_MetaBackend::PutParams& params,
153 RGWObjVersionTracker *objv_tracker,
154 optional_yield y) = 0;
155 virtual int remove_entry(const DoutPrefixProvider *dpp,
156 Context *ctx,
157 const std::string& key,
158 RGWSI_MetaBackend::RemoveParams& params,
159 RGWObjVersionTracker *objv_tracker,
160 optional_yield y) = 0;
161
162 virtual int list_init(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const std::string& marker) = 0;
163 virtual int list_next(const DoutPrefixProvider *dpp,
164 RGWSI_MetaBackend::Context *ctx,
165 int max, std::list<std::string> *keys,
166 bool *truncated) = 0;
167 virtual int list_get_marker(RGWSI_MetaBackend::Context *ctx,
168 std::string *marker) = 0;
169
170 int call(std::function<int(RGWSI_MetaBackend::Context *)> f) {
171 return call(std::nullopt, f);
172 }
173
174 virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
175 std::function<int(RGWSI_MetaBackend::Context *)> f) = 0;
176
177 virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx,
178 const std::string& key,
179 int *shard_id) = 0;
180
181 /* higher level */
182 virtual int get(Context *ctx,
183 const std::string& key,
184 GetParams &params,
185 RGWObjVersionTracker *objv_tracker,
186 optional_yield y,
187 const DoutPrefixProvider *dpp);
188
189 virtual int put(Context *ctx,
190 const std::string& key,
191 PutParams& params,
192 RGWObjVersionTracker *objv_tracker,
193 optional_yield y,
194 const DoutPrefixProvider *dpp);
195
196 virtual int remove(Context *ctx,
197 const std::string& key,
198 RemoveParams& params,
199 RGWObjVersionTracker *objv_tracker,
200 optional_yield y,
201 const DoutPrefixProvider *dpp);
202
203 virtual int mutate(Context *ctx,
204 const std::string& key,
205 MutateParams& params,
206 RGWObjVersionTracker *objv_tracker,
207 optional_yield y,
208 std::function<int()> f,
209 const DoutPrefixProvider *dpp);
210 };
211
212 class RGWSI_MetaBackend_Handler {
213 RGWSI_MetaBackend *be{nullptr};
214
215 public:
216 class Op {
217 friend class RGWSI_MetaBackend_Handler;
218
219 RGWSI_MetaBackend *be;
220 RGWSI_MetaBackend::Context *be_ctx;
221
222 Op(RGWSI_MetaBackend *_be,
223 RGWSI_MetaBackend::Context *_ctx) : be(_be), be_ctx(_ctx) {}
224
225 public:
226 RGWSI_MetaBackend::Context *ctx() {
227 return be_ctx;
228 }
229
230 int get(const std::string& key,
231 RGWSI_MetaBackend::GetParams &params,
232 RGWObjVersionTracker *objv_tracker,
233 optional_yield y, const DoutPrefixProvider *dpp) {
234 return be->get(be_ctx, key, params, objv_tracker, y, dpp);
235 }
236
237 int put(const std::string& key,
238 RGWSI_MetaBackend::PutParams& params,
239 RGWObjVersionTracker *objv_tracker,
240 optional_yield y, const DoutPrefixProvider *dpp) {
241 return be->put(be_ctx, key, params, objv_tracker, y, dpp);
242 }
243
244 int remove(const std::string& key,
245 RGWSI_MetaBackend::RemoveParams& params,
246 RGWObjVersionTracker *objv_tracker,
247 optional_yield y, const DoutPrefixProvider *dpp) {
248 return be->remove(be_ctx, key, params, objv_tracker, y, dpp);
249 }
250
251 int mutate(const std::string& key,
252 RGWSI_MetaBackend::MutateParams& params,
253 RGWObjVersionTracker *objv_tracker,
254 optional_yield y,
255 std::function<int()> f,
256 const DoutPrefixProvider *dpp) {
257 return be->mutate(be_ctx, key, params, objv_tracker, y, f, dpp);
258 }
259
260 int list_init(const DoutPrefixProvider *dpp, const std::string& marker) {
261 return be->list_init(dpp, be_ctx, marker);
262 }
263 int list_next(const DoutPrefixProvider *dpp, int max, std::list<std::string> *keys,
264 bool *truncated) {
265 return be->list_next(dpp, be_ctx, max, keys, truncated);
266 }
267 int list_get_marker(std::string *marker) {
268 return be->list_get_marker(be_ctx, marker);
269 }
270
271 int get_shard_id(const std::string& key, int *shard_id) {
272 return be->get_shard_id(be_ctx, key, shard_id);
273 }
274 };
275
276 class Op_ManagedCtx : public Op {
277 std::unique_ptr<RGWSI_MetaBackend::Context> pctx;
278 public:
279 Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler);
280 };
281
282 RGWSI_MetaBackend_Handler(RGWSI_MetaBackend *_be) : be(_be) {}
283 virtual ~RGWSI_MetaBackend_Handler() {}
284
285 int call(std::function<int(Op *)> f) {
286 return call(std::nullopt, f);
287 }
288
289 virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> bectx_params,
290 std::function<int(Op *)> f);
291 };
292