]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add rgw_rados_operate() to wrap optionally-async operate
authorCasey Bodley <cbodley@redhat.com>
Thu, 30 Nov 2017 23:40:06 +0000 (18:40 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 27 Nov 2018 17:30:25 +0000 (12:30 -0500)
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>
src/rgw/rgw_tools.cc
src/rgw/rgw_tools.h

index b3e89532870981ab812498cb3fd42980cb0e3a59..66829d98fc97d28365410da0bc772250c66ce2f7 100644 (file)
@@ -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];
index 38e85f651b95a6b97ba24eb8410ea02f9cfefbd1..be37634205f8e4a70d65a6ae6cb240e6052e85ae 100644 (file)
@@ -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();