Ensure that program status updates are immediately updated in DB IDO

fixes #11767
This commit is contained in:
Michael Friedrich 2016-05-11 14:03:40 +02:00 committed by Gunnar Beutner
parent 17fa327159
commit 40b4040880
5 changed files with 39 additions and 17 deletions

View File

@ -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));

View File

@ -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;

View File

@ -33,7 +33,8 @@ enum DbQueryType
{
DbQueryInsert = 1,
DbQueryUpdate = 2,
DbQueryDelete = 4
DbQueryDelete = 4,
DbQueryNewTransaction = 8
};
enum DbQueryCategory

View File

@ -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())

View File

@ -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())