Skip to content

Commit

Permalink
mgr: initialize PyModuleRegistry sooner
Browse files Browse the repository at this point in the history
This was waiting on MgrMap to init, so that it would know whether
modules should be enabled.  However, you don't really need to know
that until someone calls standby_start or active_start, so we
can initialize during MgrStandby::init, and fill out the enabled
flags later.

This prevents the mgr from prematurely emitting a MMgrBeacon
that claims no modules are found.

http://tracker.ceph.com/issues/22918
Signed-off-by: John Spray <john.spray@redhat.com>
  • Loading branch information
John Spray committed Feb 5, 2018
1 parent 2747362 commit 5cd8eff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/mgr/MgrStandby.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ int MgrStandby::init()
client.init();
timer.init();

py_module_registry.init();

tick();

dout(4) << "Complete." << dendl;
Expand Down Expand Up @@ -327,6 +329,8 @@ void MgrStandby::handle_mgr_map(MMgrMap* mmap)
dout(4) << "active in map: " << active_in_map
<< " active is " << map.active_gid << dendl;

// We initialize py_module_registry on the first MgrMap, because earlier
// we did not know which modules should be enabled.
if (!py_module_registry.is_initialized()) {
int r = py_module_registry.init(map);

Expand Down
8 changes: 7 additions & 1 deletion src/mgr/PyModuleRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::string PyModuleRegistry::config_prefix;



int PyModuleRegistry::init(const MgrMap &map)
int PyModuleRegistry::init()
{
Mutex::Locker locker(lock);

Expand Down Expand Up @@ -79,6 +79,8 @@ int PyModuleRegistry::init(const MgrMap &map)

bool enabled = (mgr_map.modules.count(module_name) > 0);

// Everything starts disabled, set enabled flag on module
// when we see first MgrMap
auto mod = std::make_shared<PyModule>(module_name, enabled);
int r = mod->load(pMainThreadState);
if (r != 0) {
Expand Down Expand Up @@ -109,6 +111,10 @@ void PyModuleRegistry::standby_start(MonClient *monc)
assert(standby_modules == nullptr);
assert(is_initialized());

// Must have seen a MgrMap by this point, in order to know
// which modules should be enabled
assert(mgr_map.epoch > 0);

dout(4) << "Starting modules in standby mode" << dendl;

standby_modules.reset(new StandbyPyModules(monc, mgr_map, clog));
Expand Down
7 changes: 6 additions & 1 deletion src/mgr/PyModuleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class PyModuleRegistry
{
Mutex::Locker l(lock);

if (mgr_map.epoch == 0) {
// First time we see MgrMap, set the enabled flags on modules
xyz todo
}

bool modules_changed = mgr_map_.modules != mgr_map.modules;
mgr_map = mgr_map_;

Expand All @@ -100,7 +105,7 @@ class PyModuleRegistry
return mgr_map.epoch > 0;
}

int init(const MgrMap &map);
int init();

void active_start(
PyModuleConfig &config_,
Expand Down

0 comments on commit 5cd8eff

Please sign in to comment.