From 7d8be5ee69682993cbf3f5ce5c9710a8a140d1ef Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 10 Mar 2021 09:10:14 +0100 Subject: [PATCH 1/2] IDO: Use own transaction for programstatus --- lib/db_ido/dbconnection.cpp | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 4afe825836c..00df4046ede 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -150,12 +150,17 @@ void DbConnection::UpdateProgramStatus() std::vector queries; DbQuery query1; - query1.Table = "programstatus"; - query1.IdColumn = "programstatus_id"; - query1.Type = DbQueryInsert | DbQueryDelete; - query1.Category = DbCatProgramStatus; + query1.Type = DbQueryNewTransaction; + query1.Priority = PriorityImmediate; + queries.emplace_back(std::move(query1)); - query1.Fields = new Dictionary({ + DbQuery query2; + query2.Table = "programstatus"; + query2.IdColumn = "programstatus_id"; + query2.Type = DbQueryInsert | DbQueryDelete; + query2.Category = DbCatProgramStatus; + + query2.Fields = new Dictionary({ { "instance_id", 0 }, /* DbConnection class fills in real ID */ { "program_version", Application::GetAppVersion() }, { "status_update_time", DbValue::FromTimestamp(Utility::GetTime()) }, @@ -175,27 +180,26 @@ void DbConnection::UpdateProgramStatus() { "process_performance_data", (icingaApplication->GetEnablePerfdata() ? 1 : 0) } }); - query1.WhereCriteria = new Dictionary({ + query2.WhereCriteria = new Dictionary({ { "instance_id", 0 } /* DbConnection class fills in real ID */ }); - query1.Priority = PriorityImmediate; - queries.emplace_back(std::move(query1)); - - DbQuery query2; - query2.Type = DbQueryNewTransaction; queries.emplace_back(std::move(query2)); + DbQuery query3; + query3.Type = DbQueryNewTransaction; + queries.emplace_back(std::move(query3)); + DbObject::OnMultipleQueries(queries); - DbQuery query3; - query3.Table = "runtimevariables"; - query3.Type = DbQueryDelete; - query3.Category = DbCatProgramStatus; - query3.WhereCriteria = new Dictionary({ + DbQuery query4; + query4.Table = "runtimevariables"; + query4.Type = DbQueryDelete; + query4.Category = DbCatProgramStatus; + query4.WhereCriteria = new Dictionary({ { "instance_id", 0 } /* DbConnection class fills in real ID */ }); - DbObject::OnQuery(query3); + DbObject::OnQuery(query4); InsertRuntimeVariable("total_services", ConfigType::Get()->GetObjectCount()); InsertRuntimeVariable("total_scheduled_services", ConfigType::Get()->GetObjectCount()); From 24cbd0685bbe120b355855695549e4d5ce5354c2 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 10 Mar 2021 09:29:08 +0100 Subject: [PATCH 2/2] IDO-MySQL: Make sure InternalNewTransaction() and FinishAsyncQueries() get executed during high load --- lib/db_ido_mysql/idomysqlconnection.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 83919a3300d..55074a1d8e5 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -165,8 +165,7 @@ void IdoMysqlConnection::NewTransaction() << "Scheduling new transaction and finishing async queries."; #endif /* I2_DEBUG */ - m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalNewTransaction, this), PriorityNormal); - m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::FinishAsyncQueries, this), PriorityNormal); + m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalNewTransaction, this), PriorityHigh); } void IdoMysqlConnection::InternalNewTransaction() @@ -180,6 +179,8 @@ void IdoMysqlConnection::InternalNewTransaction() AsyncQuery("COMMIT"); AsyncQuery("BEGIN"); + + FinishAsyncQueries(); } void IdoMysqlConnection::ReconnectTimerHandler()