]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_meta_be_sobj.cc
6c06182af477f7431385121faa081a1e7bc89907
[ceph.git] / ceph / src / rgw / services / svc_meta_be_sobj.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include "svc_meta_be_sobj.h"
5 #include "svc_meta_be_params.h"
6 #include "svc_mdlog.h"
7
8 #include "rgw/rgw_tools.h"
9 #include "rgw/rgw_metadata.h"
10 #include "rgw/rgw_mdlog.h"
11
12 #define dout_subsys ceph_subsys_rgw
13
14 using namespace std;
15
16 RGWSI_MetaBackend_SObj::RGWSI_MetaBackend_SObj(CephContext *cct) : RGWSI_MetaBackend(cct) {
17 }
18
19 RGWSI_MetaBackend_SObj::~RGWSI_MetaBackend_SObj() {
20 }
21
22 RGWSI_MetaBackend_Handler *RGWSI_MetaBackend_SObj::alloc_be_handler()
23 {
24 return new RGWSI_MetaBackend_Handler_SObj(this);
25 }
26
27 RGWSI_MetaBackend::Context *RGWSI_MetaBackend_SObj::alloc_ctx()
28 {
29 return new Context_SObj(sysobj_svc);
30 }
31
32 int RGWSI_MetaBackend_SObj::pre_modify(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *_ctx,
33 const string& key,
34 RGWMetadataLogData& log_data,
35 RGWObjVersionTracker *objv_tracker,
36 RGWMDLogStatus op_type,
37 optional_yield y)
38 {
39 auto ctx = static_cast<Context_SObj *>(_ctx);
40 int ret = RGWSI_MetaBackend::pre_modify(dpp, ctx, key, log_data,
41 objv_tracker, op_type,
42 y);
43 if (ret < 0) {
44 return ret;
45 }
46
47 /* if write version has not been set, and there's a read version, set it so that we can
48 * log it
49 */
50 if (objv_tracker) {
51 log_data.read_version = objv_tracker->read_version;
52 log_data.write_version = objv_tracker->write_version;
53 }
54
55 log_data.status = op_type;
56
57 bufferlist logbl;
58 encode(log_data, logbl);
59
60 ret = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl);
61 if (ret < 0)
62 return ret;
63
64 return 0;
65 }
66
67 int RGWSI_MetaBackend_SObj::post_modify(const DoutPrefixProvider *dpp,
68 RGWSI_MetaBackend::Context *_ctx,
69 const string& key,
70 RGWMetadataLogData& log_data,
71 RGWObjVersionTracker *objv_tracker, int ret,
72 optional_yield y)
73 {
74 auto ctx = static_cast<Context_SObj *>(_ctx);
75 if (ret >= 0)
76 log_data.status = MDLOG_STATUS_COMPLETE;
77 else
78 log_data.status = MDLOG_STATUS_ABORT;
79
80 bufferlist logbl;
81 encode(log_data, logbl);
82
83 int r = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl);
84 if (ret < 0)
85 return ret;
86
87 if (r < 0)
88 return r;
89
90 return RGWSI_MetaBackend::post_modify(dpp, ctx, key, log_data, objv_tracker, ret, y);
91 }
92
93 int RGWSI_MetaBackend_SObj::get_shard_id(RGWSI_MetaBackend::Context *_ctx,
94 const std::string& key,
95 int *shard_id)
96 {
97 auto ctx = static_cast<Context_SObj *>(_ctx);
98 *shard_id = mdlog_svc->get_shard_id(ctx->module->get_hash_key(key), shard_id);
99 return 0;
100 }
101
102 int RGWSI_MetaBackend_SObj::call(std::optional<RGWSI_MetaBackend_CtxParams> opt,
103 std::function<int(RGWSI_MetaBackend::Context *)> f)
104 {
105 if (!opt) {
106 RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc);
107 return f(&ctx);
108 }
109
110 try {
111 auto& opt_sobj = std::get<RGWSI_MetaBackend_CtxParams_SObj>(*opt); // w contains int, not float: will throw
112
113 RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc, opt_sobj.sysobj_ctx);
114 return f(&ctx);
115 } catch (const std::bad_variant_access&) {
116 ldout(cct, 0) << "ERROR: possible bug: " << __FILE__ << ":" << __LINE__ << ":" << __func__ << "(): bad variant access" << dendl;
117 }
118
119 return -EINVAL;
120 }
121
122 void RGWSI_MetaBackend_SObj::Context_SObj::init(RGWSI_MetaBackend_Handler *h)
123 {
124 RGWSI_MetaBackend_Handler_SObj *handler = static_cast<RGWSI_MetaBackend_Handler_SObj *>(h);
125 module = handler->module;
126 if (!obj_ctx) {
127 _obj_ctx.emplace(sysobj_svc->init_obj_ctx());
128 obj_ctx = &(*_obj_ctx);
129 }
130 }
131
132 int RGWSI_MetaBackend_SObj::call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)> cb)
133 {
134 bufferlist bl;
135 RGWSI_MBSObj_GetParams params;
136 params.pmtime = pmtime;
137 params.pbl = &bl;
138 return cb(params);
139 }
140
141 int RGWSI_MetaBackend_SObj::get_entry(RGWSI_MetaBackend::Context *_ctx,
142 const string& key,
143 GetParams& _params,
144 RGWObjVersionTracker *objv_tracker,
145 optional_yield y,
146 const DoutPrefixProvider *dpp)
147 {
148 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
149 RGWSI_MBSObj_GetParams& params = static_cast<RGWSI_MBSObj_GetParams&>(_params);
150
151 rgw_pool pool;
152 string oid;
153 ctx->module->get_pool_and_oid(key, &pool, &oid);
154
155 return rgw_get_system_obj(*ctx->obj_ctx, pool, oid, *params.pbl,
156 objv_tracker, params.pmtime,
157 y, dpp,
158 params.pattrs, params.cache_info,
159 params.refresh_version);
160 }
161
162 int RGWSI_MetaBackend_SObj::put_entry(const DoutPrefixProvider *dpp,
163 RGWSI_MetaBackend::Context *_ctx,
164 const string& key,
165 PutParams& _params,
166 RGWObjVersionTracker *objv_tracker,
167 optional_yield y)
168 {
169 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
170 RGWSI_MBSObj_PutParams& params = static_cast<RGWSI_MBSObj_PutParams&>(_params);
171
172 rgw_pool pool;
173 string oid;
174 ctx->module->get_pool_and_oid(key, &pool, &oid);
175
176 return rgw_put_system_obj(dpp, *ctx->obj_ctx, pool, oid, params.bl, params.exclusive,
177 objv_tracker, params.mtime, y, params.pattrs);
178 }
179
180 int RGWSI_MetaBackend_SObj::remove_entry(const DoutPrefixProvider *dpp,
181 RGWSI_MetaBackend::Context *_ctx,
182 const string& key,
183 RemoveParams& params,
184 RGWObjVersionTracker *objv_tracker,
185 optional_yield y)
186 {
187 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
188
189 rgw_pool pool;
190 string oid;
191 ctx->module->get_pool_and_oid(key, &pool, &oid);
192 rgw_raw_obj k(pool, oid);
193
194 auto sysobj = ctx->obj_ctx->get_obj(k);
195 return sysobj.wop()
196 .set_objv_tracker(objv_tracker)
197 .remove(dpp, y);
198 }
199
200 int RGWSI_MetaBackend_SObj::list_init(const DoutPrefixProvider *dpp,
201 RGWSI_MetaBackend::Context *_ctx,
202 const string& marker)
203 {
204 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
205
206 rgw_pool pool;
207
208 string no_key;
209 ctx->module->get_pool_and_oid(no_key, &pool, nullptr);
210
211 ctx->list.pool = sysobj_svc->get_pool(pool);
212 ctx->list.op.emplace(ctx->list.pool->op());
213
214 string prefix = ctx->module->get_oid_prefix();
215 ctx->list.op->init(dpp, marker, prefix);
216
217 return 0;
218 }
219
220 int RGWSI_MetaBackend_SObj::list_next(const DoutPrefixProvider *dpp,
221 RGWSI_MetaBackend::Context *_ctx,
222 int max, list<string> *keys,
223 bool *truncated)
224 {
225 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
226
227 vector<string> oids;
228
229 keys->clear();
230
231 int ret = ctx->list.op->get_next(dpp, max, &oids, truncated);
232 if (ret < 0 && ret != -ENOENT)
233 return ret;
234 if (ret == -ENOENT) {
235 if (truncated)
236 *truncated = false;
237 return 0;
238 }
239
240 auto module = ctx->module;
241
242 for (auto& o : oids) {
243 if (!module->is_valid_oid(o)) {
244 continue;
245 }
246 keys->emplace_back(module->oid_to_key(o));
247 }
248
249 return 0;
250 }
251
252 int RGWSI_MetaBackend_SObj::list_get_marker(RGWSI_MetaBackend::Context *_ctx,
253 string *marker)
254 {
255 RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
256
257 return ctx->list.op->get_marker(marker);
258 }
259