Skip to content

Commit

Permalink
mgr: make pgmap_ready atomic to avoid taking lock
Browse files Browse the repository at this point in the history
Signed-off-by: John Spray <john.spray@redhat.com>
  • Loading branch information
John Spray committed Sep 18, 2017
1 parent e905389 commit 4942fc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
49 changes: 27 additions & 22 deletions src/mgr/DaemonServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,31 +276,36 @@ bool DaemonServer::ms_dispatch(Message *m)

void DaemonServer::maybe_ready(int32_t osd_id)
{
Mutex::Locker l(lock);
if (pgmap_ready.load()) {
// Fast path: we don't need to take lock because pgmap_ready
// is already set
} else {
Mutex::Locker l(lock);

if (!pgmap_ready && reported_osds.find(osd_id) == reported_osds.end()) {
dout(4) << "initial report from osd " << osd_id << dendl;
reported_osds.insert(osd_id);
std::set<int32_t> up_osds;
if (reported_osds.find(osd_id) == reported_osds.end()) {
dout(4) << "initial report from osd " << osd_id << dendl;
reported_osds.insert(osd_id);
std::set<int32_t> up_osds;

cluster_state.with_osdmap([&](const OSDMap& osdmap) {
osdmap.get_up_osds(up_osds);
});

std::set<int32_t> unreported_osds;
std::set_difference(up_osds.begin(), up_osds.end(),
reported_osds.begin(), reported_osds.end(),
std::inserter(unreported_osds, unreported_osds.begin()));
cluster_state.with_osdmap([&](const OSDMap& osdmap) {
osdmap.get_up_osds(up_osds);
});

if (unreported_osds.size() == 0) {
dout(4) << "all osds have reported, sending PG state to mon" << dendl;
pgmap_ready = true;
reported_osds.clear();
// Avoid waiting for next tick
send_report();
} else {
dout(4) << "still waiting for " << unreported_osds.size() << " osds"
" to report in before PGMap is ready" << dendl;
std::set<int32_t> unreported_osds;
std::set_difference(up_osds.begin(), up_osds.end(),
reported_osds.begin(), reported_osds.end(),
std::inserter(unreported_osds, unreported_osds.begin()));

if (unreported_osds.size() == 0) {
dout(4) << "all osds have reported, sending PG state to mon" << dendl;
pgmap_ready = true;
reported_osds.clear();
// Avoid waiting for next tick
send_report();
} else {
dout(4) << "still waiting for " << unreported_osds.size() << " osds"
" to report in before PGMap is ready" << dendl;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mgr/DaemonServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DaemonServer : public Dispatcher, public md_config_obs_t
void _prune_pending_service_map();

utime_t started_at;
bool pgmap_ready = false;
std::atomic<bool> pgmap_ready = false;
std::set<int32_t> reported_osds;
void maybe_ready(int32_t osd_id);

Expand Down

0 comments on commit 4942fc2

Please sign in to comment.