mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 15:44:11 +02:00
Fix: Separately keep track of whether we've completed config and status updates.
This commit is contained in:
parent
5977bdee2d
commit
0af6393033
@ -281,6 +281,9 @@ void MysqlDbConnection::DeactivateObject(const DbObject::Ptr& dbobj)
|
|||||||
std::ostringstream qbuf;
|
std::ostringstream qbuf;
|
||||||
qbuf << "UPDATE " + GetTablePrefix() + "objects SET is_active = 0 WHERE object_id = " << static_cast<long>(dbref);
|
qbuf << "UPDATE " + GetTablePrefix() + "objects SET is_active = 0 WHERE object_id = " << static_cast<long>(dbref);
|
||||||
Query(qbuf.str());
|
Query(qbuf.str());
|
||||||
|
|
||||||
|
/* Note that we're _NOT_ clearing the db refs via SetReference/SetConfigUpdate/SetStatusUpdate
|
||||||
|
* because the object is still in the database. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* caller must hold m_ConnectionMutex */
|
/* caller must hold m_ConnectionMutex */
|
||||||
@ -368,9 +371,18 @@ void MysqlDbConnection::ExecuteQuery(const DbQuery& query)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((query.Type & DbQueryInsert) && (query.Type & DbQueryUpdate)) {
|
if ((query.Type & DbQueryInsert) && (query.Type & DbQueryUpdate)) {
|
||||||
|
bool hasid;
|
||||||
|
|
||||||
ASSERT(query.Object);
|
ASSERT(query.Object);
|
||||||
|
|
||||||
if (GetInsertID(query.Object).IsValid())
|
if (query.ConfigUpdate)
|
||||||
|
hasid = GetConfigUpdate(query.Object);
|
||||||
|
else if (query.StatusUpdate)
|
||||||
|
hasid = GetStatusUpdate(query.Object);
|
||||||
|
else
|
||||||
|
ASSERT(!"Invalid query flags.");
|
||||||
|
|
||||||
|
if (hasid)
|
||||||
type = DbQueryUpdate;
|
type = DbQueryUpdate;
|
||||||
else {
|
else {
|
||||||
if (query.WhereCriteria)
|
if (query.WhereCriteria)
|
||||||
@ -436,6 +448,13 @@ void MysqlDbConnection::ExecuteQuery(const DbQuery& query)
|
|||||||
|
|
||||||
Query(qbuf.str());
|
Query(qbuf.str());
|
||||||
|
|
||||||
if (type == DbQueryInsert && query.Object && query.UpdateObjectID)
|
if (query.Object) {
|
||||||
|
if (query.ConfigUpdate)
|
||||||
|
SetConfigUpdate(query.Object, true);
|
||||||
|
else if (query.StatusUpdate)
|
||||||
|
SetStatusUpdate(query.Object, true);
|
||||||
|
|
||||||
|
if (type == DbQueryInsert && query.ConfigUpdate)
|
||||||
SetInsertID(query.Object, GetLastInsertID());
|
SetInsertID(query.Object, GetLastInsertID());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -131,6 +131,31 @@ DbReference DbConnection::GetInsertID(const DbObject::Ptr& dbobj) const
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DbConnection::SetConfigUpdate(const DbObject::Ptr& dbobj, bool hasupdate)
|
||||||
|
{
|
||||||
|
if (hasupdate)
|
||||||
|
m_ConfigUpdates.insert(dbobj);
|
||||||
|
else
|
||||||
|
m_ConfigUpdates.erase(dbobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DbConnection::GetConfigUpdate(const DbObject::Ptr& dbobj) const
|
||||||
|
{
|
||||||
|
return (m_ConfigUpdates.find(dbobj) != m_ConfigUpdates.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DbConnection::SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate)
|
||||||
|
{
|
||||||
|
if (hasupdate)
|
||||||
|
m_StatusUpdates.insert(dbobj);
|
||||||
|
else
|
||||||
|
m_StatusUpdates.erase(dbobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DbConnection::GetStatusUpdate(const DbObject::Ptr& dbobj) const
|
||||||
|
{
|
||||||
|
return (m_StatusUpdates.find(dbobj) != m_StatusUpdates.end());
|
||||||
|
}
|
||||||
|
|
||||||
void DbConnection::ExecuteQuery(const DbQuery&)
|
void DbConnection::ExecuteQuery(const DbQuery&)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,12 @@ public:
|
|||||||
void SetInsertID(const DbObject::Ptr& dbobj, const DbReference& dbref);
|
void SetInsertID(const DbObject::Ptr& dbobj, const DbReference& dbref);
|
||||||
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
|
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
|
||||||
|
|
||||||
|
void SetConfigUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
|
||||||
|
bool GetConfigUpdate(const DbObject::Ptr& dbobj) const;
|
||||||
|
|
||||||
|
void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
|
||||||
|
bool GetStatusUpdate(const DbObject::Ptr& dbobj) const;
|
||||||
|
|
||||||
String GetTablePrefix(void) const;
|
String GetTablePrefix(void) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -64,6 +70,8 @@ private:
|
|||||||
|
|
||||||
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
|
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
|
||||||
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
|
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
|
||||||
|
std::set<DbObject::Ptr> m_ConfigUpdates;
|
||||||
|
std::set<DbObject::Ptr> m_StatusUpdates;
|
||||||
static Timer::Ptr m_ProgramStatusTimer;
|
static Timer::Ptr m_ProgramStatusTimer;
|
||||||
|
|
||||||
static void ProgramStatusHandler(void);
|
static void ProgramStatusHandler(void);
|
||||||
|
@ -89,7 +89,7 @@ void DbObject::SendConfigUpdate(void)
|
|||||||
query.WhereCriteria = boost::make_shared<Dictionary>();
|
query.WhereCriteria = boost::make_shared<Dictionary>();
|
||||||
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
|
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
|
||||||
query.Object = GetSelf();
|
query.Object = GetSelf();
|
||||||
query.UpdateObjectID = true;
|
query.ConfigUpdate = true;
|
||||||
OnQuery(query);
|
OnQuery(query);
|
||||||
|
|
||||||
m_LastConfigUpdate = Utility::GetTime();
|
m_LastConfigUpdate = Utility::GetTime();
|
||||||
@ -114,7 +114,7 @@ void DbObject::SendStatusUpdate(void)
|
|||||||
query.WhereCriteria = boost::make_shared<Dictionary>();
|
query.WhereCriteria = boost::make_shared<Dictionary>();
|
||||||
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
|
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
|
||||||
query.Object = GetSelf();
|
query.Object = GetSelf();
|
||||||
query.UpdateObjectID = false;
|
query.StatusUpdate = true;
|
||||||
OnQuery(query);
|
OnQuery(query);
|
||||||
|
|
||||||
m_LastStatusUpdate = Utility::GetTime();
|
m_LastStatusUpdate = Utility::GetTime();
|
||||||
|
@ -41,7 +41,12 @@ struct DbQuery
|
|||||||
Dictionary::Ptr Fields;
|
Dictionary::Ptr Fields;
|
||||||
Dictionary::Ptr WhereCriteria;
|
Dictionary::Ptr WhereCriteria;
|
||||||
boost::shared_ptr<DbObject> Object;
|
boost::shared_ptr<DbObject> Object;
|
||||||
bool UpdateObjectID;
|
bool ConfigUpdate;
|
||||||
|
bool StatusUpdate;
|
||||||
|
|
||||||
|
DbQuery(void)
|
||||||
|
: Type(0), ConfigUpdate(false), StatusUpdate(false)
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user