[icinga-checkins] icinga.org: icinga2/master: Avoid duplicate IDO config updates at startup

git at icinga.org git at icinga.org
Sat Aug 13 23:31:25 CEST 2016


Module: icinga2
Branch: master
Commit: ed53366490cfb85a97ad6879951cc578e1a9263c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=ed53366490cfb85a97ad6879951cc578e1a9263c

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Aug 13 22:54:22 2016 +0200

Avoid duplicate IDO config updates at startup

fixes #12417

---

 lib/base/serializer.cpp                 |    2 +-
 lib/db_ido/dbconnection.cpp             |   18 ++++++++++++++----
 lib/db_ido/dbconnection.hpp             |    3 +++
 lib/db_ido_mysql/idomysqlconnection.cpp |   18 +++++++++---------
 lib/db_ido_pgsql/idopgsqlconnection.cpp |   18 +++++++++---------
 5 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp
index 92aaba9..770726a 100644
--- a/lib/base/serializer.cpp
+++ b/lib/base/serializer.cpp
@@ -138,7 +138,7 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
 			continue;
 
 		try {
-			instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes));
+			instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes), true);
 		} catch (const std::exception&) {
 			instance->SetField(fid, Empty);
 		}
diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp
index e9f5ca0..6f4af2d 100644
--- a/lib/db_ido/dbconnection.cpp
+++ b/lib/db_ido/dbconnection.cpp
@@ -39,7 +39,8 @@ Timer::Ptr DbConnection::m_ProgramStatusTimer;
 boost::once_flag DbConnection::m_OnceFlag = BOOST_ONCE_INIT;
 
 DbConnection::DbConnection(void)
-	: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0), m_IDCacheValid(false)
+	: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0),
+	  m_IDCacheValid(false), m_ActiveChangedHandler(false)
 { }
 
 void DbConnection::OnConfigLoaded(void)
@@ -74,7 +75,14 @@ void DbConnection::Start(bool runtimeCreated)
 
 	DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
 	DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
-	ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
+}
+
+void DbConnection::EnableActiveChangedHandler(void)
+{
+	if (!m_ActiveChangedHandler) {
+		ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
+		m_ActiveChangedHandler = true;
+	}
 }
 
 void DbConnection::StatsLoggerTimerHandler(void)
@@ -394,8 +402,10 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
 		bool dbActive = GetObjectActive(dbobj);
 		bool active = object->IsActive();
 
-		if (active && !dbActive) {
-			ActivateObject(dbobj);
+		if (active) {
+			if (!dbActive)
+				ActivateObject(dbobj);
+
 			dbobj->SendConfigUpdate();
 			dbobj->SendStatusUpdate();
 		} else if (!active) {
diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp
index 8423719..74cc6b3 100644
--- a/lib/db_ido/dbconnection.hpp
+++ b/lib/db_ido/dbconnection.hpp
@@ -98,6 +98,8 @@ protected:
 	bool IsIDCacheValid(void) const;
 	void SetIDCacheValid(bool valid);
 
+	void EnableActiveChangedHandler(void);
+
 	static void UpdateProgramStatus(void);
 
 	static int GetSessionToken(void);
@@ -127,6 +129,7 @@ private:
 	RingBuffer m_QueryStats;
 	int m_PendingQueries;
 	double m_PendingQueriesTimestamp;
+	bool m_ActiveChangedHandler;
 };
 
 struct database_error : virtual std::exception, virtual boost::exception { };
diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp
index 0c7165a..3bc8e89 100644
--- a/lib/db_ido_mysql/idomysqlconnection.cpp
+++ b/lib/db_ido_mysql/idomysqlconnection.cpp
@@ -399,16 +399,16 @@ void IdoMysqlConnection::Reconnect(void)
 
 	SetIDCacheValid(true);
 
+	EnableActiveChangedHandler();
+
 	BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
-		if (dbobj->GetObject() == NULL) {
-			Log(LogNotice, "IdoMysqlConnection")
-			    << "Deactivate deleted object name1: '" << dbobj->GetName1()
-			    << "' name2: '" << dbobj->GetName2() + "'.";
-			DeactivateObject(dbobj);
-		} else {
-			dbobj->SendConfigUpdate();
-			dbobj->SendStatusUpdate();
-		}
+		if (dbobj->GetObject())
+			continue;
+
+		Log(LogNotice, "IdoMysqlConnection")
+		    << "Deactivate deleted object name1: '" << dbobj->GetName1()
+		    << "' name2: '" << dbobj->GetName2() + "'.";
+		DeactivateObject(dbobj);
 	}
 
 	UpdateAllObjects();
diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp
index 55e2b98..9cc1242 100644
--- a/lib/db_ido_pgsql/idopgsqlconnection.cpp
+++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp
@@ -372,16 +372,16 @@ void IdoPgsqlConnection::Reconnect(void)
 
 	SetIDCacheValid(true);
 
+	EnableActiveChangedHandler();
+
 	BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
-		if (dbobj->GetObject() == NULL) {
-			Log(LogNotice, "IdoPgsqlConnection")
-			    << "Deactivate deleted object name1: '" << dbobj->GetName1()
-			    << "' name2: '" << dbobj->GetName2() + "'.";
-			DeactivateObject(dbobj);
-		} else {
-			dbobj->SendConfigUpdate();
-			dbobj->SendStatusUpdate();
-		}
+		if (dbobj->GetObject())
+			continue;
+
+		Log(LogNotice, "IdoPgsqlConnection")
+		    << "Deactivate deleted object name1: '" << dbobj->GetName1()
+		    << "' name2: '" << dbobj->GetName2() + "'.";
+		DeactivateObject(dbobj);
 	}
 
 	UpdateAllObjects();



More information about the icinga-checkins mailing list