Repository navigation
Conversation
7f122df to
b45df66
Compare
3614785 to
57cdefa
Compare
once_flag probably deserves a specialization for |
|
|
jenkins test make check arm64 |
|
test cases both passing under asan, tsan, and valgrind ex
|
adamemerson
left a comment
There was a problem hiding this comment.
I like this quite a bit, perhaps call it call_cached or cache_single_call if you wanted to be very specific..
|
windows build failed: |
what do you think about keeping the name |
Sounds good to me. |
chardan
left a comment
There was a problem hiding this comment.
I'll have to read through this again after a few things have settled more, but overall this looks like a very high-quality implementation and it's a pleasure to see! (My understanding of Asio presently leaves much to be desired, so it's hard for me to comment too meaningfully on some of this, and the potential interactions are difficult anyways.) I don't have any big quibbles, but I would like to see some consideration maybe toward the names that conflict with the standard library's, and to make sure I'm following some of this, especially with a better understanding of the context. But overall this was a pleasure to read and appears very useful, thanks for all of the work on it!
| /* | ||
| * Ceph - scalable distributed file system | ||
| * | ||
| * Copyright contributors to the Ceph project |
| /// The cached Result type must be semiregular (copyable and default- | ||
| /// constructible). | ||
| template <std::semiregular Result> | ||
| class once_flag final : public service_list_base_hook { |
There was a problem hiding this comment.
I would prefer that we try to avoid names that conflict with standard library names (especially when we know they are). There are two main reasons:
- if someone has imported it into the namespace they may not be aware that this isn't the standard library component, and be surprised by differing behavior; this is a big one. Even though "that's what namespaces are for", my experience has been that this can still cause very real confusion.
- it makes it a bit harder to search for, or to search for meaningfully
I know it's a bit of a pain, but please consider a different name.
once_base_hook_flag (I'm not sure what base_hook does, but...)
once_hook_flag (sounds catchy!)
once_result_flag
...
It might also be good to capture in comments the reason for not using a regular once_flag-- from the type requirements, I gather that it's because a std::once_flag is neither copyable nor movable, and this type is?
There was a problem hiding this comment.
thanks, agreed on the name conflict especially because important semantics differ with the std version. will call this once_result<T> and probably omit the void-returning version
It might also be good to capture in comments the reason for not using a regular once_flag-- from the type requirements, I gather that it's because a std::once_flag is neither copyable nor movable, and this type is?
this class isn't copyable/movable either, but unlike std::once_flag it a) stores a return value and b) has a call_once() that takes optional_yield for coroutine support
| /// completion and return its result. Otherwise, call f() and return its | ||
| /// result. f() must return Result when called with no arguments. If it | ||
| /// throws, that exception is rethrown by all calls. | ||
| template <typename Callable> |
There was a problem hiding this comment.
Same of course applies here.
There was a problem hiding this comment.
Just to clarify, this is a kind of memoizer that works for concurrent requests? So the first request blocks until a result is obtained, and the cached result is returned to all future callers; if the call is already cached, the result is returned OR the exception is thrown?
There was a problem hiding this comment.
I'm trying to get my head around the queuing part still. Is this part of ASIO internals?
There was a problem hiding this comment.
Same of course applies here.
this refers to the naming conflict with std::call_once()? i think it's less of an issue here because, with ADL, call_once(foo...) is going to call the right version either way. and this call_once() also takes an extra optional_yield argument so there's no abiguity
Just to clarify ...
all accurate
I'm trying to get my head around the queuing part still. Is this part of ASIO internals?
the queueing part is handled by the Wait state and its list of Waiters. the asio stuff is only involved for the AsyncWaiters who passed in a non-empty optional_yield
There was a problem hiding this comment.
I agree that ADL will find it. I'm less concerned about the compiler than the human reader. That said, this feels /comparatively/ ok, but if we think of a nicer name I wouldn't object to it being changed. The extra argument does make a difference also, but I hope we don't do this too often, it can get really confusing (like in the case of "list").
| void operator()(Wait& wait) { | ||
| while (!wait.waiters.empty()) { | ||
| auto& waiter = wait.waiters.front(); | ||
| wait.waiters.pop_front(); |
There was a problem hiding this comment.
Do we need to lock during this? Or is that handled by the other code?
There was a problem hiding this comment.
this service_shutdown() stuff is triggered by the asio::io_context destructor: https://www.boost.org/doc/libs/1_87_0/doc/html/boost_asio/reference/io_context/_io_context.html
if we're in the destructor, we can safely assume that any threads calling io_context::run() have returned, so are no longer running anything that could race with this cleanup
There was a problem hiding this comment.
thinking more on this, the mix of sync/async waiters makes this tricky. i pushed one more commit with message:
service_shutdown() is really just for async waiters that we know won't complete. synchronous callers in other threads may still complete, so we shouldn't mess with their waiters
split sync/async waiters into separate lists so can leave the sync ones
| [this, &lock] (handler_type h) { | ||
| auto slot = get_associated_cancellation_slot(h); | ||
| if (slot.is_connected()) { | ||
| slot.template emplace<op_cancellation>(this); |
There was a problem hiding this comment.
Right, "slot::emplace()" is a dependent name, get_associated_cancellation_slot() has a pretty magical return type.
| namespace boost::asio { | ||
|
|
||
| // forward the handler's associated executor, allocator, cancellation slot, etc | ||
| template <template <typename, typename> class Associator, |
There was a problem hiding this comment.
Template-templates on the move! Here, we look to be playing some CRTP games and are very, very happy that auto is a thing. I need to read about Associator, but it is pleasant compared to The Old Way(TM)!
There was a problem hiding this comment.
I need to read about Associator
https://www.boost.org/doc/libs/1_87_0/doc/html/boost_asio/overview/model/associators.html might be a good place to start. in asio, it's a common pattern for handlers to wrap other handlers. this template is a convenient way to preserve properties of the wrapped handler
| #include <boost/intrusive/list.hpp> | ||
|
|
||
| #include "common/async/yield_context.h" | ||
| #include "common/async/yield_waiter.h" |
There was a problem hiding this comment.
I'll have to learn more about this gadget, looks handy!
|
|
||
| template <typename Callable> | ||
| struct CallVisitor { | ||
| once_flag& self; |
There was a problem hiding this comment.
I'm guessing this is "our" once_flag!
| requires std::convertible_to<std::invoke_result_t<Callable>, Result> | ||
| { | ||
| auto lock = std::unique_lock{self.mutex}; | ||
| return std::visit(CallVisitor{self, lock, y, std::forward<Callable>(f)}, |
There was a problem hiding this comment.
I'm going to have to skip ahead and read about the adventures of CallVisitor first! Looks good.
| std::latch call_latch{1}; | ||
| std::latch wait_latch{2}; | ||
|
|
||
| call_future = std::async(std::launch::async, [&] { |
There was a problem hiding this comment.
It's lambdas all the way down...
There was a problem hiding this comment.
yo dawg, i heard you like lambdas
|
updates:
|
|
With the caveat that my Asio-fu is currently pretty basic and this heads into deeper water than I've been in, LGTM! Thank you for doing this. |
if async_wait() can race with complete() across threads, the yield_waiter's handler_state needs to be protected by a mutex. add an async_wait() overload for unique_lock that behaves like condition_variable::wait(): the lock is released immediately before suspending, and reacquired immediately before calling its completion handler Signed-off-by: Casey Bodley <[email protected]>
also adds an empty() function so it's easier to specify its precondition Signed-off-by: Casey Bodley <[email protected]>
modeled after std::call_once() to guarantee that racing callers wait for the initial caller to finish. the main differences here are * support for coroutine callers to suspend instead of blocking while waiting for the initial caller, and * the wrapped function must return a value, which is cached and returned to all callers Signed-off-by: Casey Bodley <[email protected]>
abbf916 to
6e9c07f
Compare
|
This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days. |
|
jenkins test this please |
|
@cbodley this PR was approved pls merge at will when all checks passed |
|
thanks @yuriw. i think #61256 is probably close enough to merging, so i'm not in a hurry to merge this separately
@adamemerson if we want to validate/merge this, it just needs the rgw suite |
|
FYI, pr testing is in progress... |
Pr testing completed. Tacker approved by @ivancich. More details : https://tracker.ceph.com/issues/75779 |
|
jenkins test make check arm64 |
|
jenkins test make check |
|
jenkins test make check arm64 |
|
jenkins test docs |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
merged in #61256 |
modeled after
std::call_once()to guarantee that racing callers wait for the initial caller to finish. the main differences here are:Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition