]>
Commit | Line | Data |
---|---|---|
a8e16298 | 1 | #include "include/compat.h" |
7c673cae FG |
2 | #include "rgw_rados.h" |
3 | #include "rgw_coroutine.h" | |
7c673cae FG |
4 | #include "rgw_cr_rados.h" |
5 | ||
6 | #include "cls/lock/cls_lock_client.h" | |
b32b8144 | 7 | #include "cls/rgw/cls_rgw_client.h" |
7c673cae | 8 | |
31f18b77 FG |
9 | #include <boost/asio/yield.hpp> |
10 | ||
7c673cae FG |
11 | #define dout_context g_ceph_context |
12 | #define dout_subsys ceph_subsys_rgw | |
13 | ||
14 | bool RGWAsyncRadosProcessor::RGWWQ::_enqueue(RGWAsyncRadosRequest *req) { | |
15 | if (processor->is_going_down()) { | |
16 | return false; | |
17 | } | |
18 | req->get(); | |
19 | processor->m_req_queue.push_back(req); | |
20 | dout(20) << "enqueued request req=" << hex << req << dec << dendl; | |
21 | _dump_queue(); | |
22 | return true; | |
23 | } | |
24 | ||
25 | bool RGWAsyncRadosProcessor::RGWWQ::_empty() { | |
26 | return processor->m_req_queue.empty(); | |
27 | } | |
28 | ||
29 | RGWAsyncRadosRequest *RGWAsyncRadosProcessor::RGWWQ::_dequeue() { | |
30 | if (processor->m_req_queue.empty()) | |
31 | return NULL; | |
32 | RGWAsyncRadosRequest *req = processor->m_req_queue.front(); | |
33 | processor->m_req_queue.pop_front(); | |
34 | dout(20) << "dequeued request req=" << hex << req << dec << dendl; | |
35 | _dump_queue(); | |
36 | return req; | |
37 | } | |
38 | ||
39 | void RGWAsyncRadosProcessor::RGWWQ::_process(RGWAsyncRadosRequest *req, ThreadPool::TPHandle& handle) { | |
40 | processor->handle_request(req); | |
41 | processor->req_throttle.put(1); | |
42 | } | |
43 | ||
44 | void RGWAsyncRadosProcessor::RGWWQ::_dump_queue() { | |
45 | if (!g_conf->subsys.should_gather(ceph_subsys_rgw, 20)) { | |
46 | return; | |
47 | } | |
48 | deque<RGWAsyncRadosRequest *>::iterator iter; | |
49 | if (processor->m_req_queue.empty()) { | |
50 | dout(20) << "RGWWQ: empty" << dendl; | |
51 | return; | |
52 | } | |
53 | dout(20) << "RGWWQ:" << dendl; | |
54 | for (iter = processor->m_req_queue.begin(); iter != processor->m_req_queue.end(); ++iter) { | |
55 | dout(20) << "req: " << hex << *iter << dec << dendl; | |
56 | } | |
57 | } | |
58 | ||
59 | RGWAsyncRadosProcessor::RGWAsyncRadosProcessor(RGWRados *_store, int num_threads) | |
60 | : store(_store), m_tp(store->ctx(), "RGWAsyncRadosProcessor::m_tp", "rados_async", num_threads), | |
61 | req_throttle(store->ctx(), "rgw_async_rados_ops", num_threads * 2), | |
62 | req_wq(this, g_conf->rgw_op_thread_timeout, | |
63 | g_conf->rgw_op_thread_suicide_timeout, &m_tp) { | |
64 | } | |
65 | ||
66 | void RGWAsyncRadosProcessor::start() { | |
67 | m_tp.start(); | |
68 | } | |
69 | ||
70 | void RGWAsyncRadosProcessor::stop() { | |
71 | going_down = true; | |
72 | m_tp.drain(&req_wq); | |
73 | m_tp.stop(); | |
74 | for (auto iter = m_req_queue.begin(); iter != m_req_queue.end(); ++iter) { | |
75 | (*iter)->put(); | |
76 | } | |
77 | } | |
78 | ||
79 | void RGWAsyncRadosProcessor::handle_request(RGWAsyncRadosRequest *req) { | |
80 | req->send_request(); | |
81 | req->put(); | |
82 | } | |
83 | ||
84 | void RGWAsyncRadosProcessor::queue(RGWAsyncRadosRequest *req) { | |
85 | req_throttle.get(1); | |
86 | req_wq.queue(req); | |
87 | } | |
88 | ||
89 | int RGWAsyncGetSystemObj::_send_request() | |
90 | { | |
91327a77 AA |
91 | map<string, bufferlist> *pattrs = want_attrs ? &attrs : nullptr; |
92 | ||
93 | return store->get_system_obj(obj_ctx, read_state, &objv_tracker, | |
94 | obj, bl, ofs, end, pattrs, nullptr); | |
7c673cae FG |
95 | } |
96 | ||
91327a77 | 97 | RGWAsyncGetSystemObj::RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, |
7c673cae | 98 | RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, |
91327a77 AA |
99 | off_t _ofs, off_t _end, bool want_attrs) |
100 | : RGWAsyncRadosRequest(caller, cn), store(_store), obj_ctx(_store), | |
101 | obj(_obj), ofs(_ofs), end(_end), want_attrs(want_attrs) | |
7c673cae | 102 | { |
91327a77 AA |
103 | if (_objv_tracker) { |
104 | objv_tracker = *_objv_tracker; | |
105 | } | |
7c673cae FG |
106 | } |
107 | ||
108 | int RGWSimpleRadosReadAttrsCR::send_request() | |
109 | { | |
110 | req = new RGWAsyncGetSystemObj(this, stack->create_completion_notifier(), | |
91327a77 | 111 | store, nullptr, obj, 0, -1, true); |
7c673cae FG |
112 | async_rados->queue(req); |
113 | return 0; | |
114 | } | |
115 | ||
116 | int RGWSimpleRadosReadAttrsCR::request_complete() | |
117 | { | |
91327a77 AA |
118 | if (pattrs) { |
119 | *pattrs = std::move(req->attrs); | |
120 | } | |
7c673cae FG |
121 | return req->get_ret_status(); |
122 | } | |
123 | ||
124 | int RGWAsyncPutSystemObj::_send_request() | |
125 | { | |
91327a77 | 126 | return store->put_system_obj_data(NULL, obj, bl, -1, exclusive, &objv_tracker); |
7c673cae FG |
127 | } |
128 | ||
129 | RGWAsyncPutSystemObj::RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, | |
91327a77 AA |
130 | RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, |
131 | bool _exclusive, bufferlist _bl) | |
132 | : RGWAsyncRadosRequest(caller, cn), store(_store), | |
133 | obj(_obj), exclusive(_exclusive), bl(std::move(_bl)) | |
7c673cae | 134 | { |
91327a77 AA |
135 | if (_objv_tracker) { |
136 | objv_tracker = *_objv_tracker; | |
137 | } | |
7c673cae FG |
138 | } |
139 | ||
140 | int RGWAsyncPutSystemObjAttrs::_send_request() | |
141 | { | |
91327a77 | 142 | return store->system_obj_set_attrs(nullptr, obj, attrs, nullptr, &objv_tracker); |
7c673cae FG |
143 | } |
144 | ||
145 | RGWAsyncPutSystemObjAttrs::RGWAsyncPutSystemObjAttrs(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, | |
146 | RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, | |
91327a77 AA |
147 | map<string, bufferlist> _attrs) |
148 | : RGWAsyncRadosRequest(caller, cn), store(_store), | |
149 | obj(_obj), attrs(std::move(_attrs)) | |
7c673cae FG |
150 | { |
151 | } | |
152 | ||
153 | ||
154 | RGWOmapAppend::RGWOmapAppend(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, const rgw_raw_obj& _obj, | |
155 | uint64_t _window_size) | |
156 | : RGWConsumerCR<string>(_store->ctx()), async_rados(_async_rados), | |
157 | store(_store), obj(_obj), going_down(false), num_pending_entries(0), window_size(_window_size), total_entries(0) | |
158 | { | |
159 | } | |
160 | ||
161 | int RGWAsyncLockSystemObj::_send_request() | |
162 | { | |
163 | rgw_rados_ref ref; | |
164 | int r = store->get_raw_obj_ref(obj, &ref); | |
165 | if (r < 0) { | |
166 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
167 | return r; | |
168 | } | |
169 | ||
170 | rados::cls::lock::Lock l(lock_name); | |
171 | utime_t duration(duration_secs, 0); | |
172 | l.set_duration(duration); | |
173 | l.set_cookie(cookie); | |
f64942e4 | 174 | l.set_may_renew(true); |
7c673cae FG |
175 | |
176 | return l.lock_exclusive(&ref.ioctx, ref.oid); | |
177 | } | |
178 | ||
179 | RGWAsyncLockSystemObj::RGWAsyncLockSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, | |
180 | RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, | |
181 | const string& _name, const string& _cookie, uint32_t _duration_secs) : RGWAsyncRadosRequest(caller, cn), store(_store), | |
182 | obj(_obj), | |
183 | lock_name(_name), | |
184 | cookie(_cookie), | |
185 | duration_secs(_duration_secs) | |
186 | { | |
187 | } | |
188 | ||
189 | int RGWAsyncUnlockSystemObj::_send_request() | |
190 | { | |
191 | rgw_rados_ref ref; | |
192 | int r = store->get_raw_obj_ref(obj, &ref); | |
193 | if (r < 0) { | |
194 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
195 | return r; | |
196 | } | |
197 | ||
198 | rados::cls::lock::Lock l(lock_name); | |
199 | ||
200 | l.set_cookie(cookie); | |
201 | ||
202 | return l.unlock(&ref.ioctx, ref.oid); | |
203 | } | |
204 | ||
205 | RGWAsyncUnlockSystemObj::RGWAsyncUnlockSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, | |
206 | RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, | |
207 | const string& _name, const string& _cookie) : RGWAsyncRadosRequest(caller, cn), store(_store), | |
208 | obj(_obj), | |
209 | lock_name(_name), cookie(_cookie) | |
210 | { | |
211 | } | |
212 | ||
7c673cae FG |
213 | RGWRadosSetOmapKeysCR::RGWRadosSetOmapKeysCR(RGWRados *_store, |
214 | const rgw_raw_obj& _obj, | |
215 | map<string, bufferlist>& _entries) : RGWSimpleCoroutine(_store->ctx()), | |
216 | store(_store), | |
217 | entries(_entries), | |
218 | obj(_obj), cn(NULL) | |
219 | { | |
220 | stringstream& s = set_description(); | |
221 | s << "set omap keys dest=" << obj << " keys=[" << s.str() << "]"; | |
222 | for (auto i = entries.begin(); i != entries.end(); ++i) { | |
223 | if (i != entries.begin()) { | |
224 | s << ", "; | |
225 | } | |
226 | s << i->first; | |
227 | } | |
228 | s << "]"; | |
229 | } | |
230 | ||
7c673cae FG |
231 | int RGWRadosSetOmapKeysCR::send_request() |
232 | { | |
233 | int r = store->get_raw_obj_ref(obj, &ref); | |
234 | if (r < 0) { | |
235 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
236 | return r; | |
237 | } | |
238 | ||
239 | set_status() << "sending request"; | |
240 | ||
241 | librados::ObjectWriteOperation op; | |
242 | op.omap_set(entries); | |
243 | ||
244 | cn = stack->create_completion_notifier(); | |
7c673cae FG |
245 | return ref.ioctx.aio_operate(ref.oid, cn->completion(), &op); |
246 | } | |
247 | ||
248 | int RGWRadosSetOmapKeysCR::request_complete() | |
249 | { | |
250 | int r = cn->completion()->get_return_value(); | |
251 | ||
252 | set_status() << "request complete; ret=" << r; | |
253 | ||
254 | return r; | |
255 | } | |
256 | ||
257 | RGWRadosGetOmapKeysCR::RGWRadosGetOmapKeysCR(RGWRados *_store, | |
258 | const rgw_raw_obj& _obj, | |
259 | const string& _marker, | |
28e407b8 | 260 | std::set<std::string> *_entries, int _max_entries) : RGWSimpleCoroutine(_store->ctx()), |
7c673cae FG |
261 | store(_store), |
262 | marker(_marker), | |
28e407b8 | 263 | entries(_entries), max_entries(_max_entries), |
7c673cae FG |
264 | obj(_obj), cn(NULL) |
265 | { | |
266 | set_description() << "set omap keys dest=" << obj << " marker=" << marker; | |
267 | } | |
268 | ||
7c673cae FG |
269 | int RGWRadosGetOmapKeysCR::send_request() { |
270 | int r = store->get_raw_obj_ref(obj, &ref); | |
271 | if (r < 0) { | |
272 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
273 | return r; | |
274 | } | |
275 | ||
276 | set_status() << "send request"; | |
277 | ||
278 | librados::ObjectReadOperation op; | |
28e407b8 | 279 | op.omap_get_keys2(marker, max_entries, entries, nullptr, nullptr); |
7c673cae FG |
280 | |
281 | cn = stack->create_completion_notifier(); | |
282 | return ref.ioctx.aio_operate(ref.oid, cn->completion(), &op, NULL); | |
283 | } | |
284 | ||
28e407b8 AA |
285 | int RGWRadosGetOmapKeysCR::request_complete() |
286 | { | |
287 | int r = cn->completion()->get_return_value(); | |
288 | ||
289 | set_status() << "request complete; ret=" << r; | |
290 | ||
291 | return r; | |
292 | } | |
293 | ||
7c673cae FG |
294 | RGWRadosRemoveOmapKeysCR::RGWRadosRemoveOmapKeysCR(RGWRados *_store, |
295 | const rgw_raw_obj& _obj, | |
296 | const set<string>& _keys) : RGWSimpleCoroutine(_store->ctx()), | |
297 | store(_store), | |
298 | keys(_keys), | |
299 | obj(_obj), cn(NULL) | |
300 | { | |
301 | set_description() << "remove omap keys dest=" << obj << " keys=" << keys; | |
302 | } | |
303 | ||
7c673cae FG |
304 | int RGWRadosRemoveOmapKeysCR::send_request() { |
305 | int r = store->get_raw_obj_ref(obj, &ref); | |
306 | if (r < 0) { | |
307 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
308 | return r; | |
309 | } | |
310 | ||
311 | set_status() << "send request"; | |
312 | ||
313 | librados::ObjectWriteOperation op; | |
314 | op.omap_rm_keys(keys); | |
315 | ||
316 | cn = stack->create_completion_notifier(); | |
317 | return ref.ioctx.aio_operate(ref.oid, cn->completion(), &op); | |
318 | } | |
319 | ||
224ce89b WB |
320 | int RGWRadosRemoveOmapKeysCR::request_complete() |
321 | { | |
322 | int r = cn->completion()->get_return_value(); | |
323 | ||
324 | set_status() << "request complete; ret=" << r; | |
325 | ||
326 | return r; | |
327 | } | |
328 | ||
7c673cae FG |
329 | RGWRadosRemoveCR::RGWRadosRemoveCR(RGWRados *store, const rgw_raw_obj& obj) |
330 | : RGWSimpleCoroutine(store->ctx()), store(store), obj(obj) | |
331 | { | |
332 | set_description() << "remove dest=" << obj; | |
333 | } | |
334 | ||
335 | int RGWRadosRemoveCR::send_request() | |
336 | { | |
337 | auto rados = store->get_rados_handle(); | |
338 | int r = rados->ioctx_create(obj.pool.name.c_str(), ioctx); | |
339 | if (r < 0) { | |
340 | lderr(cct) << "ERROR: failed to open pool (" << obj.pool.name << ") ret=" << r << dendl; | |
341 | return r; | |
342 | } | |
343 | ioctx.locator_set_key(obj.loc); | |
344 | ||
345 | set_status() << "send request"; | |
346 | ||
347 | librados::ObjectWriteOperation op; | |
348 | op.remove(); | |
349 | ||
350 | cn = stack->create_completion_notifier(); | |
351 | return ioctx.aio_operate(obj.oid, cn->completion(), &op); | |
352 | } | |
353 | ||
354 | int RGWRadosRemoveCR::request_complete() | |
355 | { | |
356 | int r = cn->completion()->get_return_value(); | |
357 | ||
358 | set_status() << "request complete; ret=" << r; | |
359 | ||
360 | return r; | |
361 | } | |
362 | ||
363 | RGWSimpleRadosLockCR::RGWSimpleRadosLockCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, | |
364 | const rgw_raw_obj& _obj, | |
365 | const string& _lock_name, | |
366 | const string& _cookie, | |
367 | uint32_t _duration) : RGWSimpleCoroutine(_store->ctx()), | |
368 | async_rados(_async_rados), | |
369 | store(_store), | |
370 | lock_name(_lock_name), | |
371 | cookie(_cookie), | |
372 | duration(_duration), | |
373 | obj(_obj), | |
374 | req(NULL) | |
375 | { | |
376 | set_description() << "rados lock dest=" << obj << " lock=" << lock_name << " cookie=" << cookie << " duration=" << duration; | |
377 | } | |
378 | ||
379 | void RGWSimpleRadosLockCR::request_cleanup() | |
380 | { | |
381 | if (req) { | |
382 | req->finish(); | |
383 | req = NULL; | |
384 | } | |
385 | } | |
386 | ||
387 | int RGWSimpleRadosLockCR::send_request() | |
388 | { | |
389 | set_status() << "sending request"; | |
390 | req = new RGWAsyncLockSystemObj(this, stack->create_completion_notifier(), | |
391 | store, NULL, obj, lock_name, cookie, duration); | |
392 | async_rados->queue(req); | |
393 | return 0; | |
394 | } | |
395 | ||
396 | int RGWSimpleRadosLockCR::request_complete() | |
397 | { | |
398 | set_status() << "request complete; ret=" << req->get_ret_status(); | |
399 | return req->get_ret_status(); | |
400 | } | |
401 | ||
402 | RGWSimpleRadosUnlockCR::RGWSimpleRadosUnlockCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, | |
403 | const rgw_raw_obj& _obj, | |
404 | const string& _lock_name, | |
405 | const string& _cookie) : RGWSimpleCoroutine(_store->ctx()), | |
406 | async_rados(_async_rados), | |
407 | store(_store), | |
408 | lock_name(_lock_name), | |
409 | cookie(_cookie), | |
410 | obj(_obj), | |
411 | req(NULL) | |
412 | { | |
413 | set_description() << "rados unlock dest=" << obj << " lock=" << lock_name << " cookie=" << cookie; | |
414 | } | |
415 | ||
416 | void RGWSimpleRadosUnlockCR::request_cleanup() | |
417 | { | |
418 | if (req) { | |
419 | req->finish(); | |
420 | req = NULL; | |
421 | } | |
422 | } | |
423 | ||
424 | int RGWSimpleRadosUnlockCR::send_request() | |
425 | { | |
426 | set_status() << "sending request"; | |
427 | ||
428 | req = new RGWAsyncUnlockSystemObj(this, stack->create_completion_notifier(), | |
429 | store, NULL, obj, lock_name, cookie); | |
430 | async_rados->queue(req); | |
431 | return 0; | |
432 | } | |
433 | ||
434 | int RGWSimpleRadosUnlockCR::request_complete() | |
435 | { | |
436 | set_status() << "request complete; ret=" << req->get_ret_status(); | |
437 | return req->get_ret_status(); | |
438 | } | |
439 | ||
7c673cae FG |
440 | int RGWOmapAppend::operate() { |
441 | reenter(this) { | |
442 | for (;;) { | |
443 | if (!has_product() && going_down) { | |
444 | set_status() << "going down"; | |
445 | break; | |
446 | } | |
447 | set_status() << "waiting for product"; | |
448 | yield wait_for_product(); | |
449 | yield { | |
450 | string entry; | |
451 | while (consume(&entry)) { | |
452 | set_status() << "adding entry: " << entry; | |
453 | entries[entry] = bufferlist(); | |
454 | if (entries.size() >= window_size) { | |
455 | break; | |
456 | } | |
457 | } | |
458 | if (entries.size() >= window_size || going_down) { | |
459 | set_status() << "flushing to omap"; | |
460 | call(new RGWRadosSetOmapKeysCR(store, obj, entries)); | |
461 | entries.clear(); | |
462 | } | |
463 | } | |
464 | if (get_ret_status() < 0) { | |
465 | ldout(cct, 0) << "ERROR: failed to store entries in omap" << dendl; | |
466 | return set_state(RGWCoroutine_Error); | |
467 | } | |
468 | } | |
469 | /* done with coroutine */ | |
470 | return set_state(RGWCoroutine_Done); | |
471 | } | |
472 | return 0; | |
473 | } | |
474 | ||
475 | void RGWOmapAppend::flush_pending() { | |
476 | receive(pending_entries); | |
477 | num_pending_entries = 0; | |
478 | } | |
479 | ||
480 | bool RGWOmapAppend::append(const string& s) { | |
481 | if (is_done()) { | |
482 | return false; | |
483 | } | |
484 | ++total_entries; | |
485 | pending_entries.push_back(s); | |
486 | if (++num_pending_entries >= (int)window_size) { | |
487 | flush_pending(); | |
488 | } | |
489 | return true; | |
490 | } | |
491 | ||
492 | bool RGWOmapAppend::finish() { | |
493 | going_down = true; | |
494 | flush_pending(); | |
495 | set_sleeping(false); | |
496 | return (!is_done()); | |
497 | } | |
498 | ||
499 | int RGWAsyncGetBucketInstanceInfo::_send_request() | |
500 | { | |
501 | RGWObjectCtx obj_ctx(store); | |
91327a77 | 502 | int r = store->get_bucket_instance_from_oid(obj_ctx, oid, bucket_info, NULL, NULL); |
7c673cae FG |
503 | if (r < 0) { |
504 | ldout(store->ctx(), 0) << "ERROR: failed to get bucket instance info for " | |
b32b8144 | 505 | << oid << dendl; |
7c673cae FG |
506 | return r; |
507 | } | |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
b32b8144 FG |
512 | RGWRadosBILogTrimCR::RGWRadosBILogTrimCR(RGWRados *store, |
513 | const RGWBucketInfo& bucket_info, | |
514 | int shard_id, | |
515 | const std::string& start_marker, | |
516 | const std::string& end_marker) | |
517 | : RGWSimpleCoroutine(store->ctx()), bs(store), | |
518 | start_marker(BucketIndexShardsManager::get_shard_marker(start_marker)), | |
519 | end_marker(BucketIndexShardsManager::get_shard_marker(end_marker)) | |
520 | { | |
521 | bs.init(bucket_info, shard_id); | |
522 | } | |
523 | ||
524 | int RGWRadosBILogTrimCR::send_request() | |
525 | { | |
526 | bufferlist in; | |
527 | cls_rgw_bi_log_trim_op call; | |
528 | call.start_marker = std::move(start_marker); | |
529 | call.end_marker = std::move(end_marker); | |
530 | ::encode(call, in); | |
531 | ||
532 | librados::ObjectWriteOperation op; | |
533 | op.exec(RGW_CLASS, RGW_BI_LOG_TRIM, in); | |
534 | ||
535 | cn = stack->create_completion_notifier(); | |
536 | return bs.index_ctx.aio_operate(bs.bucket_obj, cn->completion(), &op); | |
537 | } | |
538 | ||
539 | int RGWRadosBILogTrimCR::request_complete() | |
540 | { | |
541 | int r = cn->completion()->get_return_value(); | |
542 | set_status() << "request complete; ret=" << r; | |
543 | return r; | |
544 | } | |
545 | ||
7c673cae FG |
546 | int RGWAsyncFetchRemoteObj::_send_request() |
547 | { | |
548 | RGWObjectCtx obj_ctx(store); | |
549 | ||
550 | string user_id; | |
551 | char buf[16]; | |
552 | snprintf(buf, sizeof(buf), ".%lld", (long long)store->instance_id()); | |
553 | string client_id = store->zone_id() + buf; | |
554 | string op_id = store->unique_id(store->get_new_req_id()); | |
555 | map<string, bufferlist> attrs; | |
556 | ||
557 | rgw_obj src_obj(bucket_info.bucket, key); | |
558 | ||
559 | rgw_obj dest_obj(src_obj); | |
560 | ||
561 | int r = store->fetch_remote_obj(obj_ctx, | |
562 | user_id, | |
563 | client_id, | |
564 | op_id, | |
565 | false, /* don't record op state in ops log */ | |
566 | NULL, /* req_info */ | |
567 | source_zone, | |
568 | dest_obj, | |
569 | src_obj, | |
570 | bucket_info, /* dest */ | |
571 | bucket_info, /* source */ | |
572 | NULL, /* real_time* src_mtime, */ | |
573 | NULL, /* real_time* mtime, */ | |
574 | NULL, /* const real_time* mod_ptr, */ | |
575 | NULL, /* const real_time* unmod_ptr, */ | |
576 | false, /* high precision time */ | |
577 | NULL, /* const char *if_match, */ | |
578 | NULL, /* const char *if_nomatch, */ | |
579 | RGWRados::ATTRSMOD_NONE, | |
580 | copy_if_newer, | |
581 | attrs, | |
582 | RGW_OBJ_CATEGORY_MAIN, | |
583 | versioned_epoch, | |
584 | real_time(), /* delete_at */ | |
585 | &key.instance, /* string *version_id, */ | |
586 | NULL, /* string *ptag, */ | |
587 | NULL, /* string *petag, */ | |
7c673cae | 588 | NULL, /* void (*progress_cb)(off_t, void *), */ |
31f18b77 | 589 | NULL, /* void *progress_data*); */ |
91327a77 | 590 | &zones_trace); |
7c673cae FG |
591 | |
592 | if (r < 0) { | |
593 | ldout(store->ctx(), 0) << "store->fetch_remote_obj() returned r=" << r << dendl; | |
594 | } | |
595 | return r; | |
596 | } | |
597 | ||
598 | int RGWAsyncStatRemoteObj::_send_request() | |
599 | { | |
600 | RGWObjectCtx obj_ctx(store); | |
601 | ||
602 | string user_id; | |
603 | char buf[16]; | |
604 | snprintf(buf, sizeof(buf), ".%lld", (long long)store->instance_id()); | |
605 | string client_id = store->zone_id() + buf; | |
606 | string op_id = store->unique_id(store->get_new_req_id()); | |
607 | ||
608 | rgw_obj src_obj(bucket_info.bucket, key); | |
609 | ||
610 | rgw_obj dest_obj(src_obj); | |
611 | ||
612 | int r = store->stat_remote_obj(obj_ctx, | |
613 | user_id, | |
614 | client_id, | |
615 | nullptr, /* req_info */ | |
616 | source_zone, | |
617 | src_obj, | |
618 | bucket_info, /* source */ | |
619 | pmtime, /* real_time* src_mtime, */ | |
620 | psize, /* uint64_t * */ | |
621 | nullptr, /* const real_time* mod_ptr, */ | |
622 | nullptr, /* const real_time* unmod_ptr, */ | |
623 | true, /* high precision time */ | |
624 | nullptr, /* const char *if_match, */ | |
625 | nullptr, /* const char *if_nomatch, */ | |
626 | pattrs, | |
627 | nullptr, | |
628 | nullptr, /* string *ptag, */ | |
629 | nullptr); /* string *petag, */ | |
630 | ||
631 | if (r < 0) { | |
632 | ldout(store->ctx(), 0) << "store->fetch_remote_obj() returned r=" << r << dendl; | |
633 | } | |
634 | return r; | |
635 | } | |
636 | ||
637 | ||
638 | int RGWAsyncRemoveObj::_send_request() | |
639 | { | |
640 | RGWObjectCtx obj_ctx(store); | |
641 | ||
642 | rgw_obj obj(bucket_info.bucket, key); | |
643 | ||
644 | ldout(store->ctx(), 0) << __func__ << "(): deleting obj=" << obj << dendl; | |
645 | ||
646 | obj_ctx.obj.set_atomic(obj); | |
647 | ||
648 | RGWObjState *state; | |
649 | ||
650 | int ret = store->get_obj_state(&obj_ctx, bucket_info, obj, &state); | |
651 | if (ret < 0) { | |
652 | ldout(store->ctx(), 20) << __func__ << "(): get_obj_state() obj=" << obj << " returned ret=" << ret << dendl; | |
653 | return ret; | |
654 | } | |
655 | ||
656 | /* has there been any racing object write? */ | |
657 | if (del_if_older && (state->mtime > timestamp)) { | |
658 | ldout(store->ctx(), 20) << __func__ << "(): skipping object removal obj=" << obj << " (obj mtime=" << state->mtime << ", request timestamp=" << timestamp << ")" << dendl; | |
659 | return 0; | |
660 | } | |
661 | ||
662 | RGWAccessControlPolicy policy; | |
663 | ||
664 | /* decode policy */ | |
665 | map<string, bufferlist>::iterator iter = state->attrset.find(RGW_ATTR_ACL); | |
666 | if (iter != state->attrset.end()) { | |
667 | bufferlist::iterator bliter = iter->second.begin(); | |
668 | try { | |
669 | policy.decode(bliter); | |
670 | } catch (buffer::error& err) { | |
671 | ldout(store->ctx(), 0) << "ERROR: could not decode policy, caught buffer::error" << dendl; | |
672 | return -EIO; | |
673 | } | |
674 | } | |
675 | ||
676 | RGWRados::Object del_target(store, bucket_info, obj_ctx, obj); | |
677 | RGWRados::Object::Delete del_op(&del_target); | |
678 | ||
679 | del_op.params.bucket_owner = bucket_info.owner; | |
680 | del_op.params.obj_owner = policy.get_owner(); | |
681 | if (del_if_older) { | |
682 | del_op.params.unmod_since = timestamp; | |
683 | } | |
684 | if (versioned) { | |
685 | del_op.params.versioning_status = BUCKET_VERSIONED; | |
686 | } | |
687 | del_op.params.olh_epoch = versioned_epoch; | |
688 | del_op.params.marker_version_id = marker_version_id; | |
689 | del_op.params.obj_owner.set_id(owner); | |
690 | del_op.params.obj_owner.set_name(owner_display_name); | |
691 | del_op.params.mtime = timestamp; | |
692 | del_op.params.high_precision_time = true; | |
91327a77 | 693 | del_op.params.zones_trace = &zones_trace; |
7c673cae FG |
694 | |
695 | ret = del_op.delete_obj(); | |
696 | if (ret < 0) { | |
697 | ldout(store->ctx(), 20) << __func__ << "(): delete_obj() obj=" << obj << " returned ret=" << ret << dendl; | |
698 | } | |
699 | return ret; | |
700 | } | |
701 | ||
702 | int RGWContinuousLeaseCR::operate() | |
703 | { | |
704 | if (aborted) { | |
705 | caller->set_sleeping(false); | |
706 | return set_cr_done(); | |
707 | } | |
708 | reenter(this) { | |
709 | while (!going_down) { | |
710 | yield call(new RGWSimpleRadosLockCR(async_rados, store, obj, lock_name, cookie, interval)); | |
711 | ||
712 | caller->set_sleeping(false); /* will only be relevant when we return, that's why we can do it early */ | |
713 | if (retcode < 0) { | |
714 | set_locked(false); | |
715 | ldout(store->ctx(), 20) << *this << ": couldn't lock " << obj << ":" << lock_name << ": retcode=" << retcode << dendl; | |
716 | return set_state(RGWCoroutine_Error, retcode); | |
717 | } | |
718 | set_locked(true); | |
719 | yield wait(utime_t(interval / 2, 0)); | |
720 | } | |
721 | set_locked(false); /* moot at this point anyway */ | |
722 | yield call(new RGWSimpleRadosUnlockCR(async_rados, store, obj, lock_name, cookie)); | |
723 | return set_state(RGWCoroutine_Done); | |
724 | } | |
725 | return 0; | |
726 | } | |
727 | ||
728 | RGWRadosTimelogAddCR::RGWRadosTimelogAddCR(RGWRados *_store, const string& _oid, | |
729 | const cls_log_entry& entry) : RGWSimpleCoroutine(_store->ctx()), | |
730 | store(_store), | |
731 | oid(_oid), cn(NULL) | |
732 | { | |
733 | stringstream& s = set_description(); | |
734 | s << "timelog add entry oid=" << oid << "entry={id=" << entry.id << ", section=" << entry.section << ", name=" << entry.name << "}"; | |
735 | entries.push_back(entry); | |
736 | } | |
737 | ||
7c673cae FG |
738 | int RGWRadosTimelogAddCR::send_request() |
739 | { | |
740 | set_status() << "sending request"; | |
741 | ||
742 | cn = stack->create_completion_notifier(); | |
7c673cae FG |
743 | return store->time_log_add(oid, entries, cn->completion(), true); |
744 | } | |
745 | ||
746 | int RGWRadosTimelogAddCR::request_complete() | |
747 | { | |
748 | int r = cn->completion()->get_return_value(); | |
749 | ||
750 | set_status() << "request complete; ret=" << r; | |
751 | ||
752 | return r; | |
753 | } | |
754 | ||
755 | RGWRadosTimelogTrimCR::RGWRadosTimelogTrimCR(RGWRados *store, | |
756 | const std::string& oid, | |
757 | const real_time& start_time, | |
758 | const real_time& end_time, | |
759 | const std::string& from_marker, | |
760 | const std::string& to_marker) | |
761 | : RGWSimpleCoroutine(store->ctx()), store(store), oid(oid), | |
762 | start_time(start_time), end_time(end_time), | |
763 | from_marker(from_marker), to_marker(to_marker) | |
764 | { | |
765 | set_description() << "timelog trim oid=" << oid | |
766 | << " start_time=" << start_time << " end_time=" << end_time | |
767 | << " from_marker=" << from_marker << " to_marker=" << to_marker; | |
768 | } | |
769 | ||
7c673cae FG |
770 | int RGWRadosTimelogTrimCR::send_request() |
771 | { | |
772 | set_status() << "sending request"; | |
773 | ||
774 | cn = stack->create_completion_notifier(); | |
7c673cae FG |
775 | return store->time_log_trim(oid, start_time, end_time, from_marker, |
776 | to_marker, cn->completion()); | |
777 | } | |
778 | ||
779 | int RGWRadosTimelogTrimCR::request_complete() | |
780 | { | |
781 | int r = cn->completion()->get_return_value(); | |
782 | ||
783 | set_status() << "request complete; ret=" << r; | |
784 | ||
785 | return r; | |
786 | } | |
787 | ||
788 | ||
789 | RGWSyncLogTrimCR::RGWSyncLogTrimCR(RGWRados *store, const std::string& oid, | |
790 | const std::string& to_marker, | |
791 | std::string *last_trim_marker) | |
792 | : RGWRadosTimelogTrimCR(store, oid, real_time{}, real_time{}, | |
793 | std::string{}, to_marker), | |
794 | cct(store->ctx()), last_trim_marker(last_trim_marker) | |
795 | { | |
796 | } | |
797 | ||
798 | int RGWSyncLogTrimCR::request_complete() | |
799 | { | |
800 | int r = RGWRadosTimelogTrimCR::request_complete(); | |
a8e16298 | 801 | if (r != -ENODATA) { |
7c673cae FG |
802 | return r; |
803 | } | |
a8e16298 | 804 | // nothing left to trim, update last_trim_marker |
7c673cae FG |
805 | if (*last_trim_marker < to_marker) { |
806 | *last_trim_marker = to_marker; | |
807 | } | |
808 | return 0; | |
809 | } | |
810 | ||
811 | ||
812 | int RGWAsyncStatObj::_send_request() | |
813 | { | |
814 | rgw_raw_obj raw_obj; | |
815 | store->obj_to_raw(bucket_info.placement_rule, obj, &raw_obj); | |
816 | return store->raw_obj_stat(raw_obj, psize, pmtime, pepoch, | |
817 | nullptr, nullptr, objv_tracker); | |
818 | } | |
819 | ||
820 | RGWStatObjCR::RGWStatObjCR(RGWAsyncRadosProcessor *async_rados, RGWRados *store, | |
821 | const RGWBucketInfo& _bucket_info, const rgw_obj& obj, uint64_t *psize, | |
822 | real_time* pmtime, uint64_t *pepoch, | |
823 | RGWObjVersionTracker *objv_tracker) | |
824 | : RGWSimpleCoroutine(store->ctx()), store(store), async_rados(async_rados), | |
825 | bucket_info(_bucket_info), obj(obj), psize(psize), pmtime(pmtime), pepoch(pepoch), | |
826 | objv_tracker(objv_tracker) | |
827 | { | |
828 | } | |
829 | ||
830 | void RGWStatObjCR::request_cleanup() | |
831 | { | |
832 | if (req) { | |
833 | req->finish(); | |
834 | req = NULL; | |
835 | } | |
836 | } | |
837 | ||
838 | int RGWStatObjCR::send_request() | |
839 | { | |
840 | req = new RGWAsyncStatObj(this, stack->create_completion_notifier(), | |
841 | store, bucket_info, obj, psize, pmtime, pepoch, objv_tracker); | |
842 | async_rados->queue(req); | |
843 | return 0; | |
844 | } | |
845 | ||
846 | int RGWStatObjCR::request_complete() | |
847 | { | |
848 | return req->get_ret_status(); | |
849 | } | |
b32b8144 FG |
850 | |
851 | RGWRadosNotifyCR::RGWRadosNotifyCR(RGWRados *store, const rgw_raw_obj& obj, | |
852 | bufferlist& request, uint64_t timeout_ms, | |
853 | bufferlist *response) | |
854 | : RGWSimpleCoroutine(store->ctx()), store(store), obj(obj), | |
855 | request(request), timeout_ms(timeout_ms), response(response) | |
856 | { | |
857 | set_description() << "notify dest=" << obj; | |
858 | } | |
859 | ||
860 | int RGWRadosNotifyCR::send_request() | |
861 | { | |
862 | int r = store->get_raw_obj_ref(obj, &ref); | |
863 | if (r < 0) { | |
864 | lderr(store->ctx()) << "ERROR: failed to get ref for (" << obj << ") ret=" << r << dendl; | |
865 | return r; | |
866 | } | |
867 | ||
868 | set_status() << "sending request"; | |
869 | ||
870 | cn = stack->create_completion_notifier(); | |
871 | return ref.ioctx.aio_notify(ref.oid, cn->completion(), request, | |
872 | timeout_ms, response); | |
873 | } | |
874 | ||
875 | int RGWRadosNotifyCR::request_complete() | |
876 | { | |
877 | int r = cn->completion()->get_return_value(); | |
878 | ||
879 | set_status() << "request complete; ret=" << r; | |
880 | ||
881 | return r; | |
882 | } |