mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Checkable: Delay dependency group global registration on startup
This commit is contained in:
parent
26f46fe021
commit
67a4889945
@ -3,7 +3,6 @@
|
|||||||
#include "icinga/service.hpp"
|
#include "icinga/service.hpp"
|
||||||
#include "icinga/dependency.hpp"
|
#include "icinga/dependency.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -15,9 +14,34 @@ using namespace icinga;
|
|||||||
*/
|
*/
|
||||||
static constexpr int l_MaxDependencyRecursionLevel(256);
|
static constexpr int l_MaxDependencyRecursionLevel(256);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register all the dependency groups of the current Checkable to the global dependency group registry.
|
||||||
|
*
|
||||||
|
* Initially, each Checkable object tracks locally its own dependency groups on Icinga 2 startup, and once the start
|
||||||
|
* signal of that Checkable is emitted, it pushes all the local tracked dependency groups to the global registry.
|
||||||
|
* Once the global registry is populated with all the local dependency groups, this Checkable may not necessarily
|
||||||
|
* contain the exact same dependency groups as it did before, as identical groups are merged together in the registry,
|
||||||
|
* but it's guaranteed to have the same *number* of dependency groups as before.
|
||||||
|
*/
|
||||||
|
void Checkable::PushDependencyGroupsToRegistry()
|
||||||
|
{
|
||||||
|
std::lock_guard lock(m_DependencyMutex);
|
||||||
|
if (!m_DependencyGroupsPushedToRegistry) {
|
||||||
|
m_DependencyGroupsPushedToRegistry = true;
|
||||||
|
|
||||||
|
decltype(m_DependencyGroups) dependencyGroups;
|
||||||
|
m_DependencyGroups.swap(dependencyGroups);
|
||||||
|
|
||||||
|
for (auto& [dependencyGroupKey, dependencyGroup] : dependencyGroups) {
|
||||||
|
m_DependencyGroups.emplace(dependencyGroupKey, DependencyGroup::Register(dependencyGroup));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<DependencyGroup::Ptr> Checkable::GetDependencyGroups() const
|
std::vector<DependencyGroup::Ptr> Checkable::GetDependencyGroups() const
|
||||||
{
|
{
|
||||||
std::lock_guard lock(m_DependencyMutex);
|
std::lock_guard lock(m_DependencyMutex);
|
||||||
|
|
||||||
std::vector<DependencyGroup::Ptr> dependencyGroups;
|
std::vector<DependencyGroup::Ptr> dependencyGroups;
|
||||||
for (const auto& [_, dependencyGroup] : m_DependencyGroups) {
|
for (const auto& [_, dependencyGroup] : m_DependencyGroups) {
|
||||||
dependencyGroups.emplace_back(dependencyGroup);
|
dependencyGroups.emplace_back(dependencyGroup);
|
||||||
@ -54,6 +78,15 @@ void Checkable::AddDependency(const Dependency::Ptr& dependency)
|
|||||||
std::lock_guard lock(m_DependencyMutex);
|
std::lock_guard lock(m_DependencyMutex);
|
||||||
|
|
||||||
auto dependencyGroupKey(GetDependencyGroupKey(dependency));
|
auto dependencyGroupKey(GetDependencyGroupKey(dependency));
|
||||||
|
if (!m_DependencyGroupsPushedToRegistry) {
|
||||||
|
auto& dependencyGroup = m_DependencyGroups[dependencyGroupKey];
|
||||||
|
if (!dependencyGroup) {
|
||||||
|
dependencyGroup = new DependencyGroup(dependency->GetRedundancyGroup());
|
||||||
|
}
|
||||||
|
dependencyGroup->AddDependency(dependency);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::set<Dependency::Ptr> dependencies;
|
std::set<Dependency::Ptr> dependencies;
|
||||||
if (auto it(m_DependencyGroups.find(dependencyGroupKey)); it != m_DependencyGroups.end()) {
|
if (auto it(m_DependencyGroups.find(dependencyGroupKey)); it != m_DependencyGroups.end()) {
|
||||||
dependencies = DependencyGroup::Unregister(it->second, this);
|
dependencies = DependencyGroup::Unregister(it->second, this);
|
||||||
|
@ -80,6 +80,8 @@ void Checkable::OnAllConfigLoaded()
|
|||||||
|
|
||||||
void Checkable::Start(bool runtimeCreated)
|
void Checkable::Start(bool runtimeCreated)
|
||||||
{
|
{
|
||||||
|
PushDependencyGroupsToRegistry();
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -186,6 +186,7 @@ public:
|
|||||||
bool IsFlapping() const;
|
bool IsFlapping() const;
|
||||||
|
|
||||||
/* Dependencies */
|
/* Dependencies */
|
||||||
|
void PushDependencyGroupsToRegistry();
|
||||||
std::vector<intrusive_ptr<DependencyGroup>> GetDependencyGroups() const;
|
std::vector<intrusive_ptr<DependencyGroup>> GetDependencyGroups() const;
|
||||||
void AddDependency(const intrusive_ptr<Dependency>& dependency);
|
void AddDependency(const intrusive_ptr<Dependency>& dependency);
|
||||||
void RemoveDependency(const intrusive_ptr<Dependency>& dependency);
|
void RemoveDependency(const intrusive_ptr<Dependency>& dependency);
|
||||||
@ -250,6 +251,7 @@ private:
|
|||||||
|
|
||||||
/* Dependencies */
|
/* Dependencies */
|
||||||
mutable std::mutex m_DependencyMutex;
|
mutable std::mutex m_DependencyMutex;
|
||||||
|
bool m_DependencyGroupsPushedToRegistry{false};
|
||||||
std::map<std::variant<Checkable*, String>, intrusive_ptr<DependencyGroup>> m_DependencyGroups;
|
std::map<std::variant<Checkable*, String>, intrusive_ptr<DependencyGroup>> m_DependencyGroups;
|
||||||
std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
|
std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
|
||||||
|
|
||||||
|
@ -152,6 +152,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
|
void AddDependency(const Dependency::Ptr& dependency);
|
||||||
|
void RemoveDependency(const Dependency::Ptr& dependency);
|
||||||
std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const;
|
std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const;
|
||||||
size_t GetDependenciesCount() const;
|
size_t GetDependenciesCount() const;
|
||||||
|
|
||||||
@ -169,9 +171,7 @@ public:
|
|||||||
|
|
||||||
State GetState(DependencyType dt = DependencyState, int rstack = 0) const;
|
State GetState(DependencyType dt = DependencyState, int rstack = 0) const;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
void AddDependency(const Dependency::Ptr& dependency);
|
|
||||||
void RemoveDependency(const Dependency::Ptr& dependency);
|
|
||||||
void CopyDependenciesTo(const DependencyGroup::Ptr& dest);
|
void CopyDependenciesTo(const DependencyGroup::Ptr& dest);
|
||||||
|
|
||||||
struct Hash
|
struct Hash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user