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
,
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
,
56 std::function
<int()> f
,
57 bool generic_prepare
);
59 virtual int pre_modify(Context
*ctx
,
60 const std::string
& key
,
61 RGWMetadataLogData
& log_data
,
62 RGWObjVersionTracker
*objv_tracker
,
63 RGWMDLogStatus op_type
,
65 virtual int post_modify(Context
*ctx
,
66 const std::string
& key
,
67 RGWMetadataLogData
& log_data
,
68 RGWObjVersionTracker
*objv_tracker
, int ret
,
73 * Backend specialization module
76 virtual ~Module() = 0;
79 using ModuleRef
= std::shared_ptr
<Module
>;
82 * A single metadata operation context. Will be holding info about
83 * backend and operation itself; operation might span multiple backend
86 virtual ~Context() = 0;
88 virtual void init(RGWSI_MetaBackend_Handler
*h
) = 0;
91 virtual Context
*alloc_ctx() = 0;
94 ceph::real_time mtime
;
97 PutParams(const ceph::real_time
& _mtime
) : mtime(_mtime
) {}
98 virtual ~PutParams() = 0;
103 GetParams(ceph::real_time
*_pmtime
) : pmtime(_pmtime
) {}
104 virtual ~GetParams();
106 ceph::real_time
*pmtime
{nullptr};
109 struct RemoveParams
{
110 virtual ~RemoveParams() = 0;
112 ceph::real_time mtime
;
115 struct MutateParams
{
116 ceph::real_time mtime
;
117 RGWMDLogStatus op_type
;
120 MutateParams(const ceph::real_time
& _mtime
,
121 RGWMDLogStatus _op_type
) : mtime(_mtime
), op_type(_op_type
) {}
122 virtual ~MutateParams() {}
130 RGWSI_MetaBackend(CephContext
*cct
) : RGWServiceInstance(cct
) {}
131 virtual ~RGWSI_MetaBackend() {}
133 virtual Type
get_type() = 0;
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;
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;
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
,
162 int call(std::function
<int(RGWSI_MetaBackend::Context
*)> f
) {
163 return call(nullopt
, f
);
166 virtual int call(std::optional
<RGWSI_MetaBackend_CtxParams
> opt
,
167 std::function
<int(RGWSI_MetaBackend::Context
*)> f
) = 0;
169 virtual int get_shard_id(RGWSI_MetaBackend::Context
*ctx
,
170 const std::string
& key
,
174 virtual int get(Context
*ctx
,
175 const std::string
& key
,
177 RGWObjVersionTracker
*objv_tracker
,
180 virtual int put(Context
*ctx
,
181 const std::string
& key
,
183 RGWObjVersionTracker
*objv_tracker
,
186 virtual int remove(Context
*ctx
,
187 const std::string
& key
,
188 RemoveParams
& params
,
189 RGWObjVersionTracker
*objv_tracker
,
192 virtual int mutate(Context
*ctx
,
193 const std::string
& key
,
194 MutateParams
& params
,
195 RGWObjVersionTracker
*objv_tracker
,
197 std::function
<int()> f
);
200 class RGWSI_MetaBackend_Handler
{
201 RGWSI_MetaBackend
*be
{nullptr};
205 friend class RGWSI_MetaBackend_Handler
;
207 RGWSI_MetaBackend
*be
;
208 RGWSI_MetaBackend::Context
*be_ctx
;
210 Op(RGWSI_MetaBackend
*_be
,
211 RGWSI_MetaBackend::Context
*_ctx
) : be(_be
), be_ctx(_ctx
) {}
214 RGWSI_MetaBackend::Context
*ctx() {
218 int get(const std::string
& key
,
219 RGWSI_MetaBackend::GetParams
¶ms
,
220 RGWObjVersionTracker
*objv_tracker
,
222 return be
->get(be_ctx
, key
, params
, objv_tracker
, y
);
225 int put(const std::string
& key
,
226 RGWSI_MetaBackend::PutParams
& params
,
227 RGWObjVersionTracker
*objv_tracker
,
229 return be
->put(be_ctx
, key
, params
, objv_tracker
, y
);
232 int remove(const std::string
& key
,
233 RGWSI_MetaBackend::RemoveParams
& params
,
234 RGWObjVersionTracker
*objv_tracker
,
236 return be
->remove(be_ctx
, key
, params
, objv_tracker
, y
);
239 int mutate(const std::string
& key
,
240 RGWSI_MetaBackend::MutateParams
& params
,
241 RGWObjVersionTracker
*objv_tracker
,
243 std::function
<int()> f
) {
244 return be
->mutate(be_ctx
, key
, params
, objv_tracker
, y
, f
);
247 int list_init(const string
& marker
) {
248 return be
->list_init(be_ctx
, marker
);
250 int list_next(int max
, list
<string
> *keys
,
252 return be
->list_next(be_ctx
, max
, keys
, truncated
);
254 int list_get_marker(string
*marker
) {
255 return be
->list_get_marker(be_ctx
, marker
);
258 int get_shard_id(const std::string
& key
, int *shard_id
) {
259 return be
->get_shard_id(be_ctx
, key
, shard_id
);
263 class Op_ManagedCtx
: public Op
{
264 std::unique_ptr
<RGWSI_MetaBackend::Context
> pctx
;
266 Op_ManagedCtx(RGWSI_MetaBackend_Handler
*handler
);
269 RGWSI_MetaBackend_Handler(RGWSI_MetaBackend
*_be
) : be(_be
) {}
270 virtual ~RGWSI_MetaBackend_Handler() {}
272 int call(std::function
<int(Op
*)> f
) {
273 return call(nullopt
, f
);
276 virtual int call(std::optional
<RGWSI_MetaBackend_CtxParams
> bectx_params
,
277 std::function
<int(Op
*)> f
);