]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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(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(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(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(RGWSI_MetaBackend::Context *_ctx, | |
67 | const string& key, | |
68 | RGWMetadataLogData& log_data, | |
69 | RGWObjVersionTracker *objv_tracker, int ret, | |
70 | optional_yield y) | |
71 | { | |
72 | auto ctx = static_cast<Context_SObj *>(_ctx); | |
73 | if (ret >= 0) | |
74 | log_data.status = MDLOG_STATUS_COMPLETE; | |
75 | else | |
76 | log_data.status = MDLOG_STATUS_ABORT; | |
77 | ||
78 | bufferlist logbl; | |
79 | encode(log_data, logbl); | |
80 | ||
81 | int r = mdlog_svc->add_entry(ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl); | |
82 | if (ret < 0) | |
83 | return ret; | |
84 | ||
85 | if (r < 0) | |
86 | return r; | |
87 | ||
88 | return RGWSI_MetaBackend::post_modify(ctx, key, log_data, objv_tracker, ret, y); | |
89 | } | |
90 | ||
91 | int RGWSI_MetaBackend_SObj::get_shard_id(RGWSI_MetaBackend::Context *_ctx, | |
92 | const std::string& key, | |
93 | int *shard_id) | |
94 | { | |
95 | auto ctx = static_cast<Context_SObj *>(_ctx); | |
96 | *shard_id = mdlog_svc->get_shard_id(ctx->module->get_hash_key(key), shard_id); | |
97 | return 0; | |
98 | } | |
99 | ||
100 | int RGWSI_MetaBackend_SObj::call(std::optional<RGWSI_MetaBackend_CtxParams> opt, | |
101 | std::function<int(RGWSI_MetaBackend::Context *)> f) | |
102 | { | |
103 | if (!opt) { | |
104 | RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc); | |
105 | return f(&ctx); | |
106 | } | |
107 | ||
108 | try { | |
109 | auto& opt_sobj = std::get<RGWSI_MetaBackend_CtxParams_SObj>(*opt); // w contains int, not float: will throw | |
110 | ||
111 | RGWSI_MetaBackend_SObj::Context_SObj ctx(sysobj_svc, opt_sobj.sysobj_ctx); | |
112 | return f(&ctx); | |
113 | } catch (const std::bad_variant_access&) { | |
114 | ldout(cct, 0) << "ERROR: possible bug: " << __FILE__ << ":" << __LINE__ << ":" << __func__ << "(): bad variant access" << dendl; | |
115 | } | |
116 | ||
117 | return -EINVAL; | |
118 | } | |
119 | ||
120 | void RGWSI_MetaBackend_SObj::Context_SObj::init(RGWSI_MetaBackend_Handler *h) | |
121 | { | |
122 | RGWSI_MetaBackend_Handler_SObj *handler = static_cast<RGWSI_MetaBackend_Handler_SObj *>(h); | |
123 | module = handler->module; | |
124 | if (!obj_ctx) { | |
125 | _obj_ctx.emplace(sysobj_svc->init_obj_ctx()); | |
126 | obj_ctx = &(*_obj_ctx); | |
127 | } | |
128 | } | |
129 | ||
130 | int RGWSI_MetaBackend_SObj::call_with_get_params(ceph::real_time *pmtime, std::function<int(RGWSI_MetaBackend::GetParams&)> cb) | |
131 | { | |
132 | bufferlist bl; | |
133 | RGWSI_MBSObj_GetParams params; | |
134 | params.pmtime = pmtime; | |
135 | params.pbl = &bl; | |
136 | return cb(params); | |
137 | } | |
138 | ||
139 | int RGWSI_MetaBackend_SObj::get_entry(RGWSI_MetaBackend::Context *_ctx, | |
140 | const string& key, | |
141 | GetParams& _params, | |
142 | RGWObjVersionTracker *objv_tracker, | |
143 | optional_yield y) | |
144 | { | |
145 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
146 | RGWSI_MBSObj_GetParams& params = static_cast<RGWSI_MBSObj_GetParams&>(_params); | |
147 | ||
148 | rgw_pool pool; | |
149 | string oid; | |
150 | ctx->module->get_pool_and_oid(key, &pool, &oid); | |
151 | ||
152 | return rgw_get_system_obj(*ctx->obj_ctx, pool, oid, *params.pbl, | |
153 | objv_tracker, params.pmtime, | |
154 | y, | |
155 | params.pattrs, params.cache_info, | |
156 | params.refresh_version); | |
157 | } | |
158 | ||
159 | int RGWSI_MetaBackend_SObj::put_entry(RGWSI_MetaBackend::Context *_ctx, | |
160 | const string& key, | |
161 | PutParams& _params, | |
162 | RGWObjVersionTracker *objv_tracker, | |
163 | optional_yield y) | |
164 | { | |
165 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
166 | RGWSI_MBSObj_PutParams& params = static_cast<RGWSI_MBSObj_PutParams&>(_params); | |
167 | ||
168 | rgw_pool pool; | |
169 | string oid; | |
170 | ctx->module->get_pool_and_oid(key, &pool, &oid); | |
171 | ||
172 | return rgw_put_system_obj(*ctx->obj_ctx, pool, oid, params.bl, params.exclusive, | |
173 | objv_tracker, params.mtime, y, params.pattrs); | |
174 | } | |
175 | ||
176 | int RGWSI_MetaBackend_SObj::remove_entry(RGWSI_MetaBackend::Context *_ctx, | |
177 | const string& key, | |
178 | RemoveParams& params, | |
179 | RGWObjVersionTracker *objv_tracker, | |
180 | optional_yield y) | |
181 | { | |
182 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
183 | ||
184 | rgw_pool pool; | |
185 | string oid; | |
186 | ctx->module->get_pool_and_oid(key, &pool, &oid); | |
187 | rgw_raw_obj k(pool, oid); | |
188 | ||
189 | auto sysobj = ctx->obj_ctx->get_obj(k); | |
190 | return sysobj.wop() | |
191 | .set_objv_tracker(objv_tracker) | |
192 | .remove(y); | |
193 | } | |
194 | ||
195 | int RGWSI_MetaBackend_SObj::list_init(RGWSI_MetaBackend::Context *_ctx, | |
196 | const string& marker) | |
197 | { | |
198 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
199 | ||
200 | rgw_pool pool; | |
201 | ||
202 | string no_key; | |
203 | ctx->module->get_pool_and_oid(no_key, &pool, nullptr); | |
204 | ||
205 | ctx->list.pool = sysobj_svc->get_pool(pool); | |
206 | ctx->list.op.emplace(ctx->list.pool->op()); | |
207 | ||
208 | string prefix = ctx->module->get_oid_prefix(); | |
209 | ctx->list.op->init(marker, prefix); | |
210 | ||
211 | return 0; | |
212 | } | |
213 | ||
214 | int RGWSI_MetaBackend_SObj::list_next(RGWSI_MetaBackend::Context *_ctx, | |
215 | int max, list<string> *keys, | |
216 | bool *truncated) | |
217 | { | |
218 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
219 | ||
220 | vector<string> oids; | |
221 | ||
222 | keys->clear(); | |
223 | ||
224 | int ret = ctx->list.op->get_next(max, &oids, truncated); | |
225 | if (ret < 0 && ret != -ENOENT) | |
226 | return ret; | |
227 | if (ret == -ENOENT) { | |
228 | if (truncated) | |
229 | *truncated = false; | |
230 | return 0; | |
231 | } | |
232 | ||
233 | auto module = ctx->module; | |
234 | ||
235 | for (auto& o : oids) { | |
236 | if (!module->is_valid_oid(o)) { | |
237 | continue; | |
238 | } | |
239 | keys->emplace_back(module->oid_to_key(o)); | |
240 | } | |
241 | ||
242 | return 0; | |
243 | } | |
244 | ||
245 | int RGWSI_MetaBackend_SObj::list_get_marker(RGWSI_MetaBackend::Context *_ctx, | |
246 | string *marker) | |
247 | { | |
248 | RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx); | |
249 | ||
250 | return ctx->list.op->get_marker(marker); | |
251 | } | |
252 |