]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_meta_be.h
0308c239e115b745b6f4ec0c87789bcbe73996d5
[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
51 virtual int do_mutate(Context *ctx,
52 const std::string& key,
53 const ceph::real_time& mtime, RGWObjVersionTracker *objv_tracker,
54 RGWMDLogStatus op_type,
55 optional_yield y,
56 std::function<int()> f,
57 bool generic_prepare);
58
59 virtual int pre_modify(Context *ctx,
60 const std::string& key,
61 RGWMetadataLogData& log_data,
62 RGWObjVersionTracker *objv_tracker,
63 RGWMDLogStatus op_type,
64 optional_yield y);
65 virtual int post_modify(Context *ctx,
66 const std::string& key,
67 RGWMetadataLogData& log_data,
68 RGWObjVersionTracker *objv_tracker, int ret,
69 optional_yield y);
70 public:
71 class Module {
72 /*
73 * Backend specialization module
74 */
75 public:
76 virtual ~Module() = 0;
77 };
78
79 using ModuleRef = std::shared_ptr<Module>;
80
81 struct Context { /*
82 * A single metadata operation context. Will be holding info about
83 * backend and operation itself; operation might span multiple backend
84 * calls.
85 */
86 virtual ~Context() = 0;
87
88 virtual void init(RGWSI_MetaBackend_Handler *h) = 0;
89 };
90
91 virtual Context *alloc_ctx() = 0;
92
93 struct PutParams {
94 ceph::real_time mtime;
95
96 PutParams() {}
97 PutParams(const ceph::real_time& _mtime) : mtime(_mtime) {}
98 virtual ~PutParams() = 0;
99 };
100
101 struct GetParams {
102 GetParams() {}
103 GetParams(ceph::real_time *_pmtime) : pmtime(_pmtime) {}
104 virtual ~GetParams();
105
106 ceph::real_time *pmtime{nullptr};
107 };
108
109 struct RemoveParams {
110 virtual ~RemoveParams() = 0;
111
112 ceph::real_time mtime;
113 };
114
115 struct MutateParams {
116 ceph::real_time mtime;
117 RGWMDLogStatus op_type;
118
119 MutateParams() {}
120 MutateParams(const ceph::real_time& _mtime,
121 RGWMDLogStatus _op_type) : mtime(_mtime), op_type(_op_type) {}
122 virtual ~MutateParams() {}
123 };
124
125 enum Type {
126 MDBE_SOBJ = 0,
127 MDBE_OTP = 1,
128 };
129
130 RGWSI_MetaBackend(CephContext *cct) : RGWServiceInstance(cct) {}
131 virtual ~RGWSI_MetaBackend() {}
132
133 virtual Type get_type() = 0;
134
135 virtual RGWSI_MetaBackend_Handler *alloc_be_handler() = 0;
136 virtual int call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)>) = 0;
137
138 /* these should be implemented by backends */
139 virtual int get_entry(RGWSI_MetaBackend::Context *ctx,
140 const std::string& key,
141 RGWSI_MetaBackend::GetParams& params,
142 RGWObjVersionTracker *objv_tracker,
143 optional_yield y) = 0;
144 virtual int put_entry(RGWSI_MetaBackend::Context *ctx,
145 const std::string& key,
146 RGWSI_MetaBackend::PutParams& params,
147 RGWObjVersionTracker *objv_tracker,
148 optional_yield y) = 0;
149 virtual int remove_entry(Context *ctx,
150 const std::string& key,
151 RGWSI_MetaBackend::RemoveParams& params,
152 RGWObjVersionTracker *objv_tracker,
153 optional_yield y) = 0;
154
155 virtual int list_init(RGWSI_MetaBackend::Context *ctx, const string& marker) = 0;
156 virtual int list_next(RGWSI_MetaBackend::Context *ctx,
157 int max, list<string> *keys,
158 bool *truncated) = 0;
159 virtual int list_get_marker(RGWSI_MetaBackend::Context *ctx,
160 string *marker) = 0;
161
162 int call(std::function<int(RGWSI_MetaBackend::Context *)> f) {
163 return call(nullopt, f);
164 }
165
166 virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
167 std::function<int(RGWSI_MetaBackend::Context *)> f) = 0;
168
169 virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx,
170 const std::string& key,
171 int *shard_id) = 0;
172
173 /* higher level */
174 virtual int get(Context *ctx,
175 const std::string& key,
176 GetParams &params,
177 RGWObjVersionTracker *objv_tracker,
178 optional_yield y);
179
180 virtual int put(Context *ctx,
181 const std::string& key,
182 PutParams& params,
183 RGWObjVersionTracker *objv_tracker,
184 optional_yield y);
185
186 virtual int remove(Context *ctx,
187 const std::string& key,
188 RemoveParams& params,
189 RGWObjVersionTracker *objv_tracker,
190 optional_yield y);
191
192 virtual int mutate(Context *ctx,
193 const std::string& key,
194 MutateParams& params,
195 RGWObjVersionTracker *objv_tracker,
196 optional_yield y,
197 std::function<int()> f);
198 };
199
200 class RGWSI_MetaBackend_Handler {
201 RGWSI_MetaBackend *be{nullptr};
202
203 public:
204 class Op {
205 friend class RGWSI_MetaBackend_Handler;
206
207 RGWSI_MetaBackend *be;
208 RGWSI_MetaBackend::Context *be_ctx;
209
210 Op(RGWSI_MetaBackend *_be,
211 RGWSI_MetaBackend::Context *_ctx) : be(_be), be_ctx(_ctx) {}
212
213 public:
214 RGWSI_MetaBackend::Context *ctx() {
215 return be_ctx;
216 }
217
218 int get(const std::string& key,
219 RGWSI_MetaBackend::GetParams &params,
220 RGWObjVersionTracker *objv_tracker,
221 optional_yield y) {
222 return be->get(be_ctx, key, params, objv_tracker, y);
223 }
224
225 int put(const std::string& key,
226 RGWSI_MetaBackend::PutParams& params,
227 RGWObjVersionTracker *objv_tracker,
228 optional_yield y) {
229 return be->put(be_ctx, key, params, objv_tracker, y);
230 }
231
232 int remove(const std::string& key,
233 RGWSI_MetaBackend::RemoveParams& params,
234 RGWObjVersionTracker *objv_tracker,
235 optional_yield y) {
236 return be->remove(be_ctx, key, params, objv_tracker, y);
237 }
238
239 int mutate(const std::string& key,
240 RGWSI_MetaBackend::MutateParams& params,
241 RGWObjVersionTracker *objv_tracker,
242 optional_yield y,
243 std::function<int()> f) {
244 return be->mutate(be_ctx, key, params, objv_tracker, y, f);
245 }
246
247 int list_init(const string& marker) {
248 return be->list_init(be_ctx, marker);
249 }
250 int list_next(int max, list<string> *keys,
251 bool *truncated) {
252 return be->list_next(be_ctx, max, keys, truncated);
253 }
254 int list_get_marker(string *marker) {
255 return be->list_get_marker(be_ctx, marker);
256 }
257
258 int get_shard_id(const std::string& key, int *shard_id) {
259 return be->get_shard_id(be_ctx, key, shard_id);
260 }
261 };
262
263 class Op_ManagedCtx : public Op {
264 std::unique_ptr<RGWSI_MetaBackend::Context> pctx;
265 public:
266 Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler);
267 };
268
269 RGWSI_MetaBackend_Handler(RGWSI_MetaBackend *_be) : be(_be) {}
270 virtual ~RGWSI_MetaBackend_Handler() {}
271
272 int call(std::function<int(Op *)> f) {
273 return call(nullopt, f);
274 }
275
276 virtual int call(std::optional<RGWSI_MetaBackend_CtxParams> bectx_params,
277 std::function<int(Op *)> f);
278 };
279