From a25e48c0cfd7b7f5e9cd6a4426172f44827bc00f Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 30 Nov 2017 13:10:20 -0500 Subject: [PATCH] rgw: add is_asio_thread to warn on blocking librados calls Signed-off-by: Casey Bodley --- src/rgw/rgw_asio_frontend.cc | 2 ++ src/rgw/rgw_tools.cc | 9 +++++++++ src/rgw/rgw_tools.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index c77ac4a6f815f..3e08aa62ac57b 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -558,6 +558,8 @@ int AsioFrontend::run() for (int i = 0; i < thread_count; i++) { threads.emplace_back([=] { + // request warnings on synchronous librados calls in this thread + is_asio_thread = true; boost::system::error_code ec; context.run(ec); }); diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index 66829d98fc97d..0d64cf19fdc5a 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -119,6 +119,8 @@ int rgw_delete_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string .remove(); } +thread_local bool is_asio_thread = false; + int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, librados::ObjectReadOperation *op, bufferlist* pbl, optional_yield y) @@ -136,6 +138,10 @@ int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, } return -ec.value(); } + // work on asio threads should be asynchronous, so warn when they block + if (is_asio_thread) { + dout(20) << "WARNING: blocking librados call" << dendl; + } #endif return ioctx.operate(oid, op, nullptr); } @@ -151,6 +157,9 @@ int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, librados::async_operate(context, ioctx, oid, op, 0, yield[ec]); return -ec.value(); } + if (is_asio_thread) { + dout(20) << "WARNING: blocking librados call" << dendl; + } #endif return ioctx.operate(oid, op); } diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index be37634205f8e..a932084cd781f 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -31,6 +31,10 @@ const char *rgw_find_mime_by_ext(string& ext); void rgw_filter_attrset(map& unfiltered_attrset, const string& check_prefix, map *attrset); +/// indicates whether the current thread is in boost::asio::io_context::run(), +/// used to log warnings if synchronous librados calls are made +extern thread_local bool is_asio_thread; + /// 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, -- 2.39.5