Skip to content

Commit

Permalink
Merge pull request #8809 from Icinga/bugfix/mysql-one-transaction-for…
Browse files Browse the repository at this point in the history
…-programstatus-2.12

IDO: Use own transaction for program status and make sure InternalNewTransaction() gets executed
  • Loading branch information
Al2Klimov authored May 26, 2021
2 parents f2cd24b + 24cbd06 commit b7ff749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
38 changes: 21 additions & 17 deletions lib/db_ido/dbconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ void DbConnection::UpdateProgramStatus()
std::vector<DbQuery> 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()) },
Expand All @@ -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<Service>()->GetObjectCount());
InsertRuntimeVariable("total_scheduled_services", ConfigType::Get<Service>()->GetObjectCount());
Expand Down
5 changes: 3 additions & 2 deletions lib/db_ido_mysql/idomysqlconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -180,6 +179,8 @@ void IdoMysqlConnection::InternalNewTransaction()

AsyncQuery("COMMIT");
AsyncQuery("BEGIN");

FinishAsyncQueries();
}

void IdoMysqlConnection::ReconnectTimerHandler()
Expand Down

0 comments on commit b7ff749

Please sign in to comment.