Skip to content
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

Merged
merged 3 commits into from Sep 22, 2017
Merged

mgr: locking fixes #17309

merged 3 commits into from Sep 22, 2017

Conversation

jcsp
Copy link
Contributor

@jcsp jcsp commented Aug 28, 2017


if (svc_type == "") {
states = daemon_state.get_all();
daemons = daemon_state.get_all();
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else if (svc_id.empty()) {
states = daemon_state.get_by_service(svc_type);
daemons = daemon_state.get_by_service(svc_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

auto key = statepair.first;
auto state = statepair.second;

Mutex::Locker(state->lock);
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@jcsp
Copy link
Contributor Author

jcsp commented Sep 14, 2017

Updated

@@ -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()) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@liewegas liewegas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@tchaikov
Copy link
Contributor

@jcsp need rebase

John Spray added 3 commits September 18, 2017 05:44
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>
@jcsp
Copy link
Contributor Author

jcsp commented Sep 18, 2017

Rebased

@tchaikov tchaikov merged commit fff6f2e into ceph:master Sep 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants