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
mgr: locking fixes #17309
mgr: locking fixes #17309
Conversation
0e46dcd
to
9aa680a
Compare
src/mgr/PyModules.cc
Outdated
|
||
if (svc_type == "") { | ||
states = daemon_state.get_all(); | ||
daemons = daemon_state.get_all(); |
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.
could also:
daemons = std::move(daemon_state.get_all());
to save a copy ctor call.
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.
Done
src/mgr/PyModules.cc
Outdated
} else if (svc_id.empty()) { | ||
states = daemon_state.get_by_service(svc_type); | ||
daemons = daemon_state.get_by_service(svc_type); |
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.
ditto.
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.
Done
src/mgr/PyModules.cc
Outdated
auto key = statepair.first; | ||
auto state = statepair.second; | ||
|
||
Mutex::Locker(state->lock); |
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.
this is not necessary to create a temporary Locker
object to lock and then unlock immediately.
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.
Oops, typo. Fixed.
@@ -385,6 +390,7 @@ bool DaemonServer::handle_report(MMgrReport *m) | |||
return true; | |||
} | |||
|
|||
// Look up the DaemonState |
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.
shall we guard the access to daemon_state
with lock
here also?
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.
It's not necessary until we are doing some updates (in the "Update the DaemonState" block below).
In the "constructing new DaemonState" path we are making updates before inserting it into the index, so nobody else can see it yet.
9aa680a
to
2f8d191
Compare
Updated |
src/mgr/DaemonServer.cc
Outdated
@@ -267,6 +268,8 @@ bool DaemonServer::ms_dispatch(Message *m) | |||
|
|||
void DaemonServer::maybe_ready(int32_t osd_id) | |||
{ | |||
Mutex::Locker l(lock); | |||
|
|||
if (!pgmap_ready && reported_osds.find(osd_id) == reported_osds.end()) { |
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.
It seems worth making pgmap_ready an atomic so that you can avoid taking the lock each time here? It's only false during mgr startup, right?
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.
Done!
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.
lgtm!
@jcsp need rebase |
2f8d191
to
e905389
Compare
Various things here were dangerously operating outside locks. Additionally switch to a RWLock because this lock will be relatively read-hot when it's taken every time a MMgrReport is handled, to look up the DaemonState for the sender. Fixes: http://tracker.ceph.com/issues/21158 Signed-off-by: John Spray <john.spray@redhat.com>
The DaemonStateIndex locking is sufficient to make all the report processing safe: holding DaemonServer::lock through all ms_dispatch was unnecessarily serializing dispatch. Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
4942fc2
to
d209157
Compare
Rebased |
Fixes: http://tracker.ceph.com/issues/21158