| 554 | } |
| 555 | |
| 556 | void ActivePyModules::start_one(PyModuleRef py_module) |
| 557 | { |
| 558 | std::lock_guard l(lock); |
| 559 | |
| 560 | const auto name = py_module->get_name(); |
| 561 | auto active_module = std::make_shared<ActivePyModule>(py_module, clog, m_thread_monitor); |
| 562 | |
| 563 | pending_modules.insert(name); |
| 564 | // Send all python calls down a Finisher to avoid blocking |
| 565 | // C++ code, and avoid any potential lock cycles. |
| 566 | finisher.queue(new LambdaContext([this, active_module, name, py_module](int) { |
| 567 | // Delay loading in testing scenarios |
| 568 | auto delay = g_conf().get_val<std::chrono::milliseconds>("mgr_module_load_delay"); |
| 569 | std::string delayed_module = g_conf().get_val<std::string>("mgr_module_load_delay_name"); |
| 570 | if ((name == delayed_module) && (delay > std::chrono::milliseconds{0})) { |
| 571 | dout(4) << "Delaying load time for module '" << name |
| 572 | << "' by " << delay << "..." << dendl; |
| 573 | std::this_thread::sleep_for(delay); |
| 574 | } |
| 575 | int r = active_module->load(this); |
| 576 | std::lock_guard l(lock); |
| 577 | pending_modules.erase(name); |
| 578 | if (r != 0) { |
| 579 | derr << "Failed to run module in active mode ('" << name << "')" |
| 580 | << dendl; |
| 581 | } else { |
| 582 | auto em = modules.emplace(name, active_module); |
| 583 | ceph_assert(em.second); // actually inserted |
| 584 | active_module->thread.create(active_module->get_thread_name()); |
| 585 | py_module->perf_counter_build(g_ceph_context); |
| 586 | active_module->finisher.start(); |
| 587 | active_module->finisher.on_started().wait(); |
| 588 | active_module->set_native_tid(active_module->finisher.get_tid()); |
| 589 | if (m_thread_monitor) { |
| 590 | m_thread_monitor->register_thread(active_module->get_native_tid(), |
| 591 | active_module->thread.get_tid(), |
| 592 | name, py_module); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | // Signal when we're finally done starting up modules |
| 597 | if (pending_modules.empty() && recheck_modules_start) { |
| 598 | finisher.queue(recheck_modules_start); |
| 599 | recheck_modules_start = nullptr; |
| 600 | } |
| 601 | })); |
| 602 | } |
| 603 | |
| 604 | void ActivePyModules::notify_all(const std::string ¬ify_type, |
| 605 | const std::string ¬ify_id) |
no test coverage detected