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