mirror of
https://github.com/ceph/ceph
synced 2025-01-20 01:51:34 +00:00
rgw: add rgw_rados_operate() to wrap optionally-async operate
calls IoCtx::operate() when given an empty optional_yield, or librados::async_operate() when non-empty. calling async_operate() with a yield_context behaves just like a synchronous call to IoCtx::operate(), except that the stackful coroutine is suspended and resumed on completion instead of blocking the calling thread Signed-off-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
parent
20220e7087
commit
42921b98d1
@ -5,6 +5,8 @@
|
||||
|
||||
#include "common/errno.h"
|
||||
#include "common/safe_io.h"
|
||||
#include "librados/librados_asio.h"
|
||||
#include "common/async/yield_context.h"
|
||||
|
||||
#include "include/types.h"
|
||||
|
||||
@ -15,6 +17,7 @@
|
||||
#include "services/svc_sys_obj.h"
|
||||
|
||||
#define dout_subsys ceph_subsys_rgw
|
||||
#define dout_context g_ceph_context
|
||||
|
||||
#define READ_CHUNK_LEN (512 * 1024)
|
||||
|
||||
@ -116,6 +119,42 @@ int rgw_delete_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string
|
||||
.remove();
|
||||
}
|
||||
|
||||
int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
|
||||
librados::ObjectReadOperation *op, bufferlist* pbl,
|
||||
optional_yield y)
|
||||
{
|
||||
#ifdef HAVE_BOOST_CONTEXT
|
||||
// given a yield_context, call async_operate() to yield the coroutine instead
|
||||
// of blocking
|
||||
if (y) {
|
||||
auto& context = y.get_io_context();
|
||||
auto& yield = y.get_yield_context();
|
||||
boost::system::error_code ec;
|
||||
auto bl = librados::async_operate(context, ioctx, oid, op, 0, yield[ec]);
|
||||
if (pbl) {
|
||||
*pbl = std::move(bl);
|
||||
}
|
||||
return -ec.value();
|
||||
}
|
||||
#endif
|
||||
return ioctx.operate(oid, op, nullptr);
|
||||
}
|
||||
|
||||
int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
|
||||
librados::ObjectWriteOperation *op, optional_yield y)
|
||||
{
|
||||
#ifdef HAVE_BOOST_CONTEXT
|
||||
if (y) {
|
||||
auto& context = y.get_io_context();
|
||||
auto& yield = y.get_yield_context();
|
||||
boost::system::error_code ec;
|
||||
librados::async_operate(context, ioctx, oid, op, 0, yield[ec]);
|
||||
return -ec.value();
|
||||
}
|
||||
#endif
|
||||
return ioctx.operate(oid, op);
|
||||
}
|
||||
|
||||
void parse_mime_map_line(const char *start, const char *end)
|
||||
{
|
||||
char line[end - start + 1];
|
||||
|
@ -13,6 +13,7 @@
|
||||
class RGWRados;
|
||||
class RGWSysObjectCtx;
|
||||
struct RGWObjVersionTracker;
|
||||
class optional_yield;
|
||||
|
||||
struct obj_version;
|
||||
|
||||
@ -30,6 +31,13 @@ const char *rgw_find_mime_by_ext(string& ext);
|
||||
void rgw_filter_attrset(map<string, bufferlist>& unfiltered_attrset, const string& check_prefix,
|
||||
map<string, bufferlist> *attrset);
|
||||
|
||||
/// perform the rados operation, using the yield context when given
|
||||
int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
|
||||
librados::ObjectReadOperation *op, bufferlist* pbl,
|
||||
optional_yield y);
|
||||
int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
|
||||
librados::ObjectWriteOperation *op, optional_yield y);
|
||||
|
||||
int rgw_tools_init(CephContext *cct);
|
||||
void rgw_tools_cleanup();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user