Merge pull request #9479 from Icinga/9478

IcingaDB::SendCustomVarsChanged(): don't delete custom vars of not synced types
This commit is contained in:
Alexander Aleksandrovič Klimov 2022-08-10 22:22:14 +02:00 committed by GitHub
commit c3074753aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -44,6 +44,8 @@ using namespace icinga;
using Prio = RedisConnection::QueryPriority;
std::unordered_set<Type*> IcingaDB::m_IndexedTypes;
INITIALIZE_ONCE(&IcingaDB::ConfigStaticInitialize);
std::vector<Type::Ptr> IcingaDB::GetTypes()
@ -74,6 +76,10 @@ std::vector<Type::Ptr> IcingaDB::GetTypes()
void IcingaDB::ConfigStaticInitialize()
{
for (auto& type : GetTypes()) {
m_IndexedTypes.emplace(type.get());
}
/* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */
Checkable::OnStateChange.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr&) {
IcingaDB::StateChangeHandler(checkable, cr, type);
@ -2511,6 +2517,10 @@ void IcingaDB::SendCommandArgumentsChanged(const ConfigObject::Ptr& command, con
}
void IcingaDB::SendCustomVarsChanged(const ConfigObject::Ptr& object, const Dictionary::Ptr& oldValues, const Dictionary::Ptr& newValues) {
if (m_IndexedTypes.find(object->GetReflectionType().get()) == m_IndexedTypes.end()) {
return;
}
if (!m_Rcon || !m_Rcon->IsConnected() || oldValues == newValues) {
return;
}
@ -2715,6 +2725,10 @@ void IcingaDB::VersionChangedHandler(const ConfigObject::Ptr& object)
{
Type::Ptr type = object->GetReflectionType();
if (m_IndexedTypes.find(type.get()) == m_IndexedTypes.end()) {
return;
}
if (object->IsActive()) {
// Create or update the object config
for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType<IcingaDB>()) {

View File

@ -21,6 +21,7 @@
#include <mutex>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
namespace icinga
@ -232,6 +233,8 @@ private:
// initialization, the value is read-only and can be accessed without further synchronization.
static String m_EnvironmentId;
static std::mutex m_EnvironmentIdInitMutex;
static std::unordered_set<Type*> m_IndexedTypes;
};
}