Skip to content

Commit

Permalink
Disable async IDO queries for custom var updates
Browse files Browse the repository at this point in the history
refs #10190
  • Loading branch information
Michael Friedrich committed Sep 25, 2015
1 parent 717118f commit f1567f3
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 73 deletions.
12 changes: 6 additions & 6 deletions lib/db_ido/dbconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 60,7 @@ void DbConnection::Start(void)
{
ObjectImpl<DbConnection>::Start();

DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1, _2));
ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
}

Expand Down Expand Up @@ -120,7 120,7 @@ void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query.Fields->Set("varname", key);
query.Fields->Set("varvalue", value);
DbObject::OnQuery(query);
DbObject::OnQuery(query, true);
}

void DbConnection::ProgramStatusHandler(void)
Expand All @@ -131,7 131,7 @@ void DbConnection::ProgramStatusHandler(void)
query1.Category = DbCatProgramStatus;
query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);

DbQuery query2;
query2.Table = "programstatus";
Expand All @@ -157,15 157,15 @@ void DbConnection::ProgramStatusHandler(void)
query2.Fields->Set("event_handlers_enabled", (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0));
query2.Fields->Set("flap_detection_enabled", (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0));
query2.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0));
DbObject::OnQuery(query2);
DbObject::OnQuery(query2, true);

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);
DbObject::OnQuery(query3, true);

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));
Expand Down Expand Up @@ -343,7 343,7 @@ 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&, bool)
{
/* Default handler does nothing. */
}
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido/dbconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 82,7 @@ class I2_DB_IDO_API DbConnection : public ObjectImpl<DbConnection>
virtual void Resume(void) override;
virtual void Pause(void) override;

virtual void ExecuteQuery(const DbQuery& query) = 0;
virtual void ExecuteQuery(const DbQuery& query, bool async = true) = 0;
virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0;
virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0;

Expand Down
56 changes: 28 additions & 28 deletions lib/db_ido/dbevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 119,7 @@ void DbEvents::NextCheckChangedHandler(const Checkable::Ptr& checkable)

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable)
Expand Down Expand Up @@ -153,7 153,7 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable)

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable)
Expand Down Expand Up @@ -192,7 192,7 @@ void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notificat

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, std::set<Checkable::Ptr> children)
Expand Down Expand Up @@ -237,7 237,7 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}
}

Expand Down Expand Up @@ -296,7 296,7 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}


Expand Down Expand Up @@ -387,7 387,7 @@ void DbEvents::AddCommentByType(const ConfigObject::Ptr& object, const Comment::
query1.Type = DbQueryInsert;
query1.Category = DbCatComment;
query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::RemoveComments(const Checkable::Ptr& checkable)
Expand All @@ -401,7 401,7 @@ void DbEvents::RemoveComments(const Checkable::Ptr& checkable)
query1.Category = DbCatComment;
query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("object_id", checkable);
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment)
Expand All @@ -422,7 422,7 @@ void DbEvents::RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr
query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("object_id", checkable);
query1.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId());
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);

/* History - update deletion time for service/host */
unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
Expand All @@ -445,7 445,7 @@ void DbEvents::RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr
query2.WhereCriteria->Set("comment_time", DbValue::FromTimestamp(entry_time));
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query2);
DbObject::OnQuery(query2, true);
}

/* downtimes */
Expand Down Expand Up @@ -539,7 539,7 @@ void DbEvents::AddDowntimeByType(const Checkable::Ptr& checkable, const Downtime
query1.Type = DbQueryInsert;
query1.Category = DbCatDowntime;
query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::RemoveDowntimes(const Checkable::Ptr& checkable)
Expand All @@ -553,7 553,7 @@ void DbEvents::RemoveDowntimes(const Checkable::Ptr& checkable)
query1.Category = DbCatDowntime;
query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("object_id", checkable);
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
Expand All @@ -574,7 574,7 @@ void DbEvents::RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::P
query1.WhereCriteria = new Dictionary();
query1.WhereCriteria->Set("object_id", checkable);
query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);

/* History - update actual_end_time, was_cancelled for service (and host in case) */
double now = Utility::GetTime();
Expand All @@ -598,7 598,7 @@ void DbEvents::RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::P
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query3);
DbObject::OnQuery(query3, true);

/* host/service status */
Host::Ptr host;
Expand Down Expand Up @@ -629,7 629,7 @@ void DbEvents::RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::P

query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query4);
DbObject::OnQuery(query4, true);
}

void DbEvents::TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
Expand Down Expand Up @@ -664,7 664,7 @@ void DbEvents::TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::
query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);

/* History - downtime was started for service (and host in case) */
DbQuery query3;
Expand All @@ -687,7 687,7 @@ void DbEvents::TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query3);
DbObject::OnQuery(query3, true);

/* host/service status */
Host::Ptr host;
Expand Down Expand Up @@ -718,7 718,7 @@ void DbEvents::TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::

query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query4);
DbObject::OnQuery(query4, true);
}

/* acknowledgements */
Expand Down Expand Up @@ -763,7 763,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::AddAcknowledgement(const Checkable::Ptr& checkable, AcknowledgementType type)
Expand Down Expand Up @@ -812,7 812,7 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno

query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* notifications */
Expand Down Expand Up @@ -863,7 863,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);

DbQuery query2;
query2.Table = "contactnotifications";
Expand All @@ -886,7 886,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */

query2.Fields = fields2;
DbObject::OnQuery(query2);
DbObject::OnQuery(query2, true);
}
}

Expand Down Expand Up @@ -941,7 941,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* logentries */
Expand Down Expand Up @@ -1259,7 1259,7 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, String buffer, Log
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* flappinghistory */
Expand Down Expand Up @@ -1307,7 1307,7 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable)
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable)
Expand Down Expand Up @@ -1353,7 1353,7 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable)
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* servicechecks */
Expand Down Expand Up @@ -1421,7 1421,7 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* eventhandlers */
Expand Down Expand Up @@ -1464,7 1464,7 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable)
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}

/* externalcommands */
Expand Down Expand Up @@ -1493,5 1493,5 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con
fields1->Set("endpoint_object_id", endpoint);

query1.Fields = fields1;
DbObject::OnQuery(query1);
DbObject::OnQuery(query1, true);
}
15 changes: 6 additions & 9 deletions lib/db_ido/dbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 36,7 @@

using namespace icinga;

boost::signals2::signal<void (const DbQuery&)> DbObject::OnQuery;
boost::signals2::signal<void (const DbQuery&, bool async)> DbObject::OnQuery;

INITIALIZE_ONCE(&DbObject::StaticInitialize);

Expand All @@ -48,6 48,7 @@ void DbObject::StaticInitialize(void)
{
/* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */
ConfigObject::OnStateChanged.connect(boost::bind(&DbObject::StateChangedHandler, _1));

CustomVarObject::OnVarsChanged.connect(boost::bind(&DbObject::VarsChangedHandler, _1));

/* triggered on create, update and delete objects */
Expand Down Expand Up @@ -103,7 104,7 @@ void DbObject::SendConfigUpdate(void)
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
query.Object = this;
query.ConfigUpdate = true;
OnQuery(query);
OnQuery(query, true);

m_LastConfigUpdate = Utility::GetTime();

Expand Down Expand Up @@ -144,7 145,7 @@ void DbObject::SendStatusUpdate(void)
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
query.Object = this;
query.StatusUpdate = true;
OnQuery(query);
OnQuery(query, true);

m_LastStatusUpdate = Utility::GetTime();

Expand Down Expand Up @@ -183,10 184,6 @@ void DbObject::SendVarsConfigUpdate(void)

int overridden = custom_var_object->IsVarOverridden(kv.first) ? 1 : 0;

Log(LogDebug, "DbObject")
<< "object customvar key: '" << kv.first << "' value: '" << kv.second
<< "' overridden: " << overridden;

Dictionary::Ptr fields = new Dictionary();
fields->Set("varname", kv.first);
fields->Set("varvalue", value);
Expand All @@ -207,7 204,7 @@ void DbObject::SendVarsConfigUpdate(void)
query.WhereCriteria->Set("varname", kv.first);
query.Object = this;

OnQuery(query);
OnQuery(query, false);
}
}
}
Expand Down Expand Up @@ -268,7 265,7 @@ void DbObject::SendVarsStatusUpdate(void)
query.WhereCriteria->Set("varname", kv.first);
query.Object = this;

OnQuery(query);
OnQuery(query, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido/dbobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 78,7 @@ class I2_DB_IDO_API DbObject : public Object

static DbObject::Ptr GetOrCreateByObject(const ConfigObject::Ptr& object);

static boost::signals2::signal<void (const DbQuery&)> OnQuery;
static boost::signals2::signal<void (const DbQuery&, bool)> OnQuery;

void SendConfigUpdate(void);
void SendStatusUpdate(void);
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido/endpointdbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 95,7 @@ void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
query1.WhereCriteria->Set("endpoint_object_id", endpoint);
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */

OnQuery(query1);
OnQuery(query1, true);
}

int EndpointDbObject::EndpointIsConnected(const Endpoint::Ptr& endpoint)
Expand Down
Loading

0 comments on commit f1567f3

Please sign in to comment.