2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab ft=cpp
6 * Ceph - scalable distributed file system
8 * Copyright (C) 2019 Red Hat, Inc.
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.
20 #include "svc_meta_be_params.h"
22 #include "rgw/rgw_service.h"
23 #include "rgw/rgw_mdlog_types.h"
25 class RGWMetadataLogData
;
29 class RGWObjVersionTracker
;
30 class RGWSI_MetaBackend_Handler
;
32 class RGWSI_MetaBackend
: public RGWServiceInstance
34 friend class RGWSI_Meta
;
39 RGWSI_MDLog
*mdlog_svc
{nullptr};
41 void base_init(RGWSI_MDLog
*_mdlog_svc
) {
42 mdlog_svc
= _mdlog_svc
;
45 int prepare_mutate(RGWSI_MetaBackend::Context
*ctx
,
46 const std::string
& key
,
47 const ceph::real_time
& mtime
,
48 RGWObjVersionTracker
*objv_tracker
,
50 const DoutPrefixProvider
*dpp
);
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
,
57 std::function
<int()> f
,
59 const DoutPrefixProvider
*dpp
);
61 virtual int pre_modify(const DoutPrefixProvider
*dpp
,
63 const std::string
& key
,
64 RGWMetadataLogData
& log_data
,
65 RGWObjVersionTracker
*objv_tracker
,
66 RGWMDLogStatus op_type
,
68 virtual int post_modify(const DoutPrefixProvider
*dpp
,
70 const std::string
& key
,
71 RGWMetadataLogData
& log_data
,
72 RGWObjVersionTracker
*objv_tracker
, int ret
,
77 * Backend specialization module
80 virtual ~Module() = 0;
83 using ModuleRef
= std::shared_ptr
<Module
>;
86 * A single metadata operation context. Will be holding info about
87 * backend and operation itself; operation might span multiple backend
90 virtual ~Context() = 0;
92 virtual void init(RGWSI_MetaBackend_Handler
*h
) = 0;
95 virtual Context
*alloc_ctx() = 0;
98 ceph::real_time mtime
;
101 PutParams(const ceph::real_time
& _mtime
) : mtime(_mtime
) {}
102 virtual ~PutParams() = 0;
107 GetParams(ceph::real_time
*_pmtime
) : pmtime(_pmtime
) {}
108 virtual ~GetParams();
110 ceph::real_time
*pmtime
{nullptr};
113 struct RemoveParams
{
114 virtual ~RemoveParams() = 0;
116 ceph::real_time mtime
;
119 struct MutateParams
{
120 ceph::real_time mtime
;
121 RGWMDLogStatus op_type
;
124 MutateParams(const ceph::real_time
& _mtime
,
125 RGWMDLogStatus _op_type
) : mtime(_mtime
), op_type(_op_type
) {}
126 virtual ~MutateParams() {}
134 RGWSI_MetaBackend(CephContext
*cct
) : RGWServiceInstance(cct
) {}
135 virtual ~RGWSI_MetaBackend() {}
137 virtual Type
get_type() = 0;
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;
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
,
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
,
157 const std::string
& key
,
158 RGWSI_MetaBackend::RemoveParams
& params
,
159 RGWObjVersionTracker
*objv_tracker
,
160 optional_yield y
) = 0;
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;
170 int call(std::function
<int(RGWSI_MetaBackend::Context
*)> f
) {
171 return call(std::nullopt
, f
);
174 virtual int call(std::optional
<RGWSI_MetaBackend_CtxParams
> opt
,
175 std::function
<int(RGWSI_MetaBackend::Context
*)> f
) = 0;
177 virtual int get_shard_id(RGWSI_MetaBackend::Context
*ctx
,
178 const std::string
& key
,
182 virtual int get(Context
*ctx
,
183 const std::string
& key
,
185 RGWObjVersionTracker
*objv_tracker
,
187 const DoutPrefixProvider
*dpp
);
189 virtual int put(Context
*ctx
,
190 const std::string
& key
,
192 RGWObjVersionTracker
*objv_tracker
,
194 const DoutPrefixProvider
*dpp
);
196 virtual int remove(Context
*ctx
,
197 const std::string
& key
,
198 RemoveParams
& params
,
199 RGWObjVersionTracker
*objv_tracker
,
201 const DoutPrefixProvider
*dpp
);
203 virtual int mutate(Context
*ctx
,
204 const std::string
& key
,
205 MutateParams
& params
,
206 RGWObjVersionTracker
*objv_tracker
,
208 std::function
<int()> f
,
209 const DoutPrefixProvider
*dpp
);
212 class RGWSI_MetaBackend_Handler
{
213 RGWSI_MetaBackend
*be
{nullptr};
217 friend class RGWSI_MetaBackend_Handler
;
219 RGWSI_MetaBackend
*be
;
220 RGWSI_MetaBackend::Context
*be_ctx
;
222 Op(RGWSI_MetaBackend
*_be
,
223 RGWSI_MetaBackend::Context
*_ctx
) : be(_be
), be_ctx(_ctx
) {}
226 RGWSI_MetaBackend::Context
*ctx() {
230 int get(const std::string
& key
,
231 RGWSI_MetaBackend::GetParams
¶ms
,
232 RGWObjVersionTracker
*objv_tracker
,
233 optional_yield y
, const DoutPrefixProvider
*dpp
) {
234 return be
->get(be_ctx
, key
, params
, objv_tracker
, y
, dpp
);
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
);
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
);
251 int mutate(const std::string
& key
,
252 RGWSI_MetaBackend::MutateParams
& params
,
253 RGWObjVersionTracker
*objv_tracker
,
255 std::function
<int()> f
,
256 const DoutPrefixProvider
*dpp
) {
257 return be
->mutate(be_ctx
, key
, params
, objv_tracker
, y
, f
, dpp
);
260 int list_init(const DoutPrefixProvider
*dpp
, const std::string
& marker
) {
261 return be
->list_init(dpp
, be_ctx
, marker
);
263 int list_next(const DoutPrefixProvider
*dpp
, int max
, std::list
<std::string
> *keys
,
265 return be
->list_next(dpp
, be_ctx
, max
, keys
, truncated
);
267 int list_get_marker(std::string
*marker
) {
268 return be
->list_get_marker(be_ctx
, marker
);
271 int get_shard_id(const std::string
& key
, int *shard_id
) {
272 return be
->get_shard_id(be_ctx
, key
, shard_id
);
276 class Op_ManagedCtx
: public Op
{
277 std::unique_ptr
<RGWSI_MetaBackend::Context
> pctx
;
279 Op_ManagedCtx(RGWSI_MetaBackend_Handler
*handler
);
282 RGWSI_MetaBackend_Handler(RGWSI_MetaBackend
*_be
) : be(_be
) {}
283 virtual ~RGWSI_MetaBackend_Handler() {}
285 int call(std::function
<int(Op
*)> f
) {
286 return call(std::nullopt
, f
);
289 virtual int call(std::optional
<RGWSI_MetaBackend_CtxParams
> bectx_params
,
290 std::function
<int(Op
*)> f
);