[icinga-checkins] icinga.org: icinga2/support/2.4: Ensure that program status updates are immediately updated in DB IDO

git at icinga.org git at icinga.org
Thu May 12 11:50:28 CEST 2016


Module: icinga2
Branch: support/2.4
Commit: 40b4040880c3fd50c8ad993021f9af3c4fa2fcab
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=40b4040880c3fd50c8ad993021f9af3c4fa2fcab

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed May 11 14:03:40 2016 +0200

Ensure that program status updates are immediately updated in DB IDO

fixes #11767

---

 lib/db_ido/dbconnection.cpp             |   22 +++++++++++++---------
 lib/db_ido/dbconnection.hpp             |    3 ++-
 lib/db_ido/dbquery.hpp                  |    3 ++-
 lib/db_ido_mysql/idomysqlconnection.cpp |   14 +++++++++++---
 lib/db_ido_pgsql/idopgsqlconnection.cpp |   14 +++++++++++---
 5 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp
index 694b9e3..c7995c8 100644
--- a/lib/db_ido/dbconnection.cpp
+++ b/lib/db_ido/dbconnection.cpp
@@ -146,7 +146,7 @@ void DbConnection::InitializeDbTimer(void)
 {
 	m_ProgramStatusTimer = new Timer();
 	m_ProgramStatusTimer->SetInterval(10);
-	m_ProgramStatusTimer->OnTimerExpired.connect(boost::bind(&DbConnection::ProgramStatusHandler));
+	m_ProgramStatusTimer->OnTimerExpired.connect(boost::bind(&DbConnection::UpdateProgramStatus));
 	m_ProgramStatusTimer->Start();
 }
 
@@ -163,7 +163,7 @@ void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
 	DbObject::OnQuery(query);
 }
 
-void DbConnection::ProgramStatusHandler(void)
+void DbConnection::UpdateProgramStatus(void)
 {
 	Log(LogNotice, "DbConnection")
 	     << "Updating programstatus table.";
@@ -206,15 +206,19 @@ void DbConnection::ProgramStatusHandler(void)
 	query2.Priority = PriorityHigh;
 	queries.push_back(query2);
 
+	DbQuery query3;
+	query3.Type = DbQueryNewTransaction;
+	queries.push_back(query3);
+
 	DbObject::OnMultipleQueries(queries);
 
-	DbQuery query3;
-	query3.Table = "runtimevariables";
-	query3.Type = DbQueryDelete;
-	query3.Category = DbCatProgramStatus;
-	query3.WhereCriteria = new Dictionary();
-	query3.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
-	DbObject::OnQuery(query3);
+	DbQuery query4;
+	query4.Table = "runtimevariables";
+	query4.Type = DbQueryDelete;
+	query4.Category = DbCatProgramStatus;
+	query4.WhereCriteria = new Dictionary();
+	query4.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
+	DbObject::OnQuery(query4);
 
 	InsertRuntimeVariable("total_services", std::distance(ConfigType::GetObjectsByType<Service>().first, ConfigType::GetObjectsByType<Service>().second));
 	InsertRuntimeVariable("total_scheduled_services", std::distance(ConfigType::GetObjectsByType<Service>().first, ConfigType::GetObjectsByType<Service>().second));
diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp
index 6f81178..94b1af4 100644
--- a/lib/db_ido/dbconnection.hpp
+++ b/lib/db_ido/dbconnection.hpp
@@ -95,6 +95,8 @@ protected:
 
 	void IncreaseQueryCount(void);
 
+	static void UpdateProgramStatus(void);
+
 private:
 	std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
 	std::map<std::pair<DbType::Ptr, DbReference>, DbReference> m_InsertIDs;
@@ -114,7 +116,6 @@ private:
 	void StatsLoggerTimerHandler(void);
 
 	static void InsertRuntimeVariable(const String& key, const Value& value);
-	static void ProgramStatusHandler(void);
 
 	mutable boost::mutex m_StatsMutex;
 	RingBuffer m_QueryStats;
diff --git a/lib/db_ido/dbquery.hpp b/lib/db_ido/dbquery.hpp
index 1dd2d43..3161d1c 100644
--- a/lib/db_ido/dbquery.hpp
+++ b/lib/db_ido/dbquery.hpp
@@ -33,7 +33,8 @@ enum DbQueryType
 {
 	DbQueryInsert = 1,
 	DbQueryUpdate = 2,
-	DbQueryDelete = 4
+	DbQueryDelete = 4,
+	DbQueryNewTransaction = 8
 };
 
 enum DbQueryCategory
diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp
index 56c2767..a71e7b3 100644
--- a/lib/db_ido_mysql/idomysqlconnection.cpp
+++ b/lib/db_ido_mysql/idomysqlconnection.cpp
@@ -337,6 +337,9 @@ void IdoMysqlConnection::Reconnect(void)
 	/* set session time zone to utc */
 	Query("SET SESSION TIME_ZONE='+00:00'");
 
+	/* update programstatus table */
+	UpdateProgramStatus();
+
 	/* record connection */
 	Query("INSERT INTO " + GetTablePrefix() + "conninfo " +
 	    "(instance_id, connect_time, last_checkin_time, agent_name, agent_version, connect_type, data_start_time) VALUES ("
@@ -818,7 +821,7 @@ void IdoMysqlConnection::InternalExecuteMultipleQueries(const std::vector<DbQuer
 		return;
 
 	BOOST_FOREACH(const DbQuery& query, queries) {
-		ASSERT(query.Category != DbCatInvalid);
+		ASSERT(query.Type == DbQueryNewTransaction || query.Category != DbCatInvalid);
 
 		if (!CanExecuteQuery(query)) {
 			m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalExecuteMultipleQueries, this, queries), query.Priority);
@@ -835,10 +838,15 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, DbQueryType
 {
 	AssertOnWorkQueue();
 
-	if ((query.Category & GetCategories()) == 0)
+	if (!GetConnected())
 		return;
 
-	if (!GetConnected())
+	if (query.Type == DbQueryNewTransaction) {
+		InternalNewTransaction();
+		return;
+	}
+
+	if ((query.Category & GetCategories()) == 0)
 		return;
 
 	if (query.Object && query.Object->GetObject()->GetExtension("agent_check").ToBool())
diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp
index a55f5fa..93f72f9 100644
--- a/lib/db_ido_pgsql/idopgsqlconnection.cpp
+++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp
@@ -324,6 +324,9 @@ void IdoPgsqlConnection::Reconnect(void)
 	Log(LogInformation, "IdoPgsqlConnection")
 	    << "pgSQL IDO instance id: " << static_cast<long>(m_InstanceID) << " (schema version: '" + version + "')";
 
+	/* update programstatus table */
+	UpdateProgramStatus();
+
 	/* record connection */
 	Query("INSERT INTO " + GetTablePrefix() + "conninfo " +
 	    "(instance_id, connect_time, last_checkin_time, agent_name, agent_version, connect_type, data_start_time) VALUES ("
@@ -697,7 +700,7 @@ void IdoPgsqlConnection::InternalExecuteMultipleQueries(const std::vector<DbQuer
 		return;
 
 	BOOST_FOREACH(const DbQuery& query, queries) {
-		ASSERT(query.Category != DbCatInvalid);
+		ASSERT(query.Type == DbQueryNewTransaction || query.Category != DbCatInvalid);
 
 		if (!CanExecuteQuery(query)) {
 			m_QueryQueue.Enqueue(boost::bind(&IdoPgsqlConnection::InternalExecuteMultipleQueries, this, queries), query.Priority);
@@ -714,10 +717,15 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, DbQueryType
 {
 	AssertOnWorkQueue();
 
-	if ((query.Category & GetCategories()) == 0)
+	if (!GetConnected())
 		return;
 
-	if (!GetConnected())
+	if (query.Type == DbQueryNewTransaction) {
+		InternalNewTransaction();
+		return;
+	}
+
+	if ((query.Category & GetCategories()) == 0)
 		return;
 
 	if (query.Object && query.Object->GetObject()->GetExtension("agent_check").ToBool())



More information about the icinga-checkins mailing list