-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add seastar signal api #2384
Add seastar signal api #2384
Conversation
@tomershafir , please fix the commits sequence, it contains some "Merge branch 'master'" and a post-fixlet, both are not welcome |
f9bdcc2
to
1834cb5
Compare
doc/signal.md
Outdated
|
||
You need to construct a `signal_handler` instance that will register the provided signal handler for the specified signal based on the configuration params. | ||
|
||
At the moment, the signal handler will remain past object destruction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's extremely confusing. I would expect that desctruction of an object unregisters the handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill add unregister logic to this PR
include/seastar/core/reactor.hh
Outdated
void handle_signal(int signo, noncopyable_function<void ()>&& handler); | ||
void wakeup(); | ||
/// @private | ||
bool stopped() const noexcept { return _stopped; } | ||
|
||
private: | ||
class signals { | ||
struct _signal_handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leading underscore is for private members, class names shouldn't have it
include/seastar/core/reactor.hh
Outdated
friend class thread_pool; | ||
friend class thread_context; | ||
friend class internal::cpu_stall_detector; | ||
friend struct signal_handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New friends for reactor class are not welcome. It's large enough already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other ways would be:
- Add public
reactor::handle_signal_once
and undo deprecation ofreactor::handle_signal
. Users will be able to call them and I think it inverts the purpose of changing the api. Also, it adds more code to the reactor. - Refactor signal logic out of the reactor. It seems like the blast radius is big and it's not an easy task.
Thus I would prefer the friend struct
solution at the moment. Let me know wdyt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have nested class signal, public nested class signal_handler would be nice replacement for explicit friend. But as I wrote above, installing handler in constructor smells like RAII and implies unsetting it in destructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goal has been to add a clean seastar namespace level api, not through the reactor.
@xemul Regarding destructor logic, it seems to me like the RAII approach here may be less suitable. As the POSIX api doesn't fit RAII naturally, adapting it can introduce complexity and confusion. I assume that multiple objects can be constructed for a single For example: seastar::signal_handler signal_handler1(SIGINT, [this] { signaled(); });
...
seastar::signal_handler signal_handler2(SIGINT, [this] { signaled(); });
... What should happen if I think I should re-target this PR to introduce a clean seastar namespace level api, and do it via procedures rather than objects. Wdyt? |
Yes, this sounds good |
1834cb5
to
6156b3e
Compare
@xemul I force pushed the changes |
tests/unit/signal_test.cc
Outdated
@@ -20,6 +20,7 @@ | |||
*/ | |||
|
|||
#include <seastar/core/reactor.hh> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this header still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, will remove
include/seastar/core/reactor.hh
Outdated
signals _signals; | ||
std::unique_ptr<thread_pool> _thread_pool; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change
include/seastar/core/reactor.hh
Outdated
}; | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unwanted indentation
include/seastar/core/reactor.hh
Outdated
noncopyable_function<void ()> _handler; | ||
}; | ||
std::atomic<uint64_t> _pending_signals; | ||
std::unordered_map<int, signal_handler> _signal_handlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this block moved upwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove redundant private
in a class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill extract it into a different PR
src/core/signal.cc
Outdated
namespace seastar { | ||
|
||
static reactor& engine_or_throw() { | ||
if (!engine_is_ready()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's impossible. No tasks can be run until engine is ready
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its possible, if a user calls the procedure before app.run()
, like:
seastar::handle_signal(SIGINT, [] {});
return app.run(argc, argv, [&app] -> seastar::future<> {
...
I dont think its obvious that it must be called inside run()
, so I think the logic provides a more controlled and understandable error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the "reactor must be initialized" can be confusing message, because it's not obvious that "app.run()" initializes the reactor. I would just mention in the method doc, that it's only valid to use one from inside app.run() lambda, otherwise it's UB
795134e
to
01aa880
Compare
src/core/signal.cc
Outdated
@@ -31,15 +31,8 @@ module seastar; | |||
|
|||
namespace seastar { | |||
|
|||
static reactor& engine_or_throw() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, squash it with the previous commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, done
b5d1f22
to
9e16998
Compare
fixes: #261.
The PR adds an object based interface for signals on seastar namespace.
signal.hh
header implemented byreactor.cc
.doc/signal.md
.reactor::handle_signal
.Future possibilities:
once
(should require reactor changes to expose an indicator).