Repository navigation
librados/asio: support 'deferred' and 'use_awaitable' completions - #60576
Conversation
i generally only consider const_cast as a last resort, but the only alternatives seemed to be:
|
789c628 to
addfd2f
Compare
|
with deferred initiation, the |
2372fec to
24f553e
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
24f553e to
bcc8a6f
Compare
|
rebased after merge of #60379 |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
all these functions required of the ExecutionContext was a get_executor() member function. just pass the executor instead c++20 coroutines in asio have easy access to their executor through `co_await asio::this_coro::executor`, but nothing provides that as a member function Signed-off-by: Casey Bodley <[email protected]>
when called with 'use_awaitable' for c++20 coroutines, these functions
fail to compile because async_initiate() tries to pass the IoCtx
argument by rvalue reference, but our lambda expects lvalue reference:
> src/librados/librados_asio.h:196:7: note: template argument deduction/substitution failed:
> boost/asio/impl/use_awaitable.hpp:276:26: note: cannot convert ‘std::move<librados::v14_2_0::IoCtx&>((* & args#1))’ (type ‘std::remove_reference<librados::v14_2_0::IoCtx&>::type’ {aka ‘librados::v14_2_0::IoCtx’}) to type ‘librados::v14_2_0::IoCtx&’
> 276 | std::move(initiation)(std::move(handler), std::move(args)...);
> | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async_initiate() for 'deferred' shows the same issue:
> src/librados/librados_asio.h:196:7: note: template argument deduction/substitution failed:
> boost/asio/async_result.hpp:322:9: note: cannot convert ‘args#1’ (type ‘const librados::v14_2_0::IoCtx’) to type ‘librados::v14_2_0::IoCtx&’
> 322 | static_cast<Args&&>(args)...);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
in both cases, async_initiate() has to copy the arguments for
deferred/lazy initiation, then move them into our lambda when invoked
because our lambdas take mutable references, they won't accept these
rvalue references. taking them as const references instead allows the
caller to pass either lvalue- or rvalue references
this requires internal const_casts to convert them back to mutable
references. while casting away const risks undefined behavior, these
casts are safe because:
- in the deferred/lazy case, the arguments were decay-copied (const
removed) into temporary storage
- in the normal case, the initial arguments were passed as mutable refs
Signed-off-by: Casey Bodley <[email protected]>
for these async_operate() overloads, deferred initiation makes it possible for the ObjectOperations arguments, passed by pointer, to go out of scope before use because ObjectOperation is move-only, we can't pass it by reference like IoCtx& and expect the initiation functions to make a copy when necessary. so our only option is to use move operations instead, requiring that the caller pass an rvalue in the first place Signed-off-by: Casey Bodley <[email protected]>
Signed-off-by: Casey Bodley <[email protected]>
Signed-off-by: Casey Bodley <[email protected]>
Signed-off-by: Casey Bodley <[email protected]>
bcc8a6f to
9331694
Compare
|
rebased over conflicts from #60330 |
when called with boost::asio::use_awaitable for c++20 coroutines, these functions fail to compile because async_initiate() tries to pass the IoCtx argument by rvalue reference, but our lambda expects lvalue reference:
async_initiate() for boost::asio::deferred shows the same issue:
in both cases, async_initiate() has to copy the arguments for deferred/lazy initiation, then move them into our lambda when invoked. asio documentation doesn't really cover how this works, but i did find this release note from boost 1.70:
because our lambdas take mutable references, they won't accept these rvalue references. taking them as const references instead allows the caller to pass either lvalue- or rvalue references
this requires internal const_casts to convert them back to mutable references. while casting away const risks undefined behavior, these casts are safe because:
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e