Avoid duplicate IDO config updates at startup

fixes #12417
This commit is contained in:
Gunnar Beutner 2016-08-13 22:54:22 +02:00
parent 9f8cb8dd36
commit ed53366490
5 changed files with 36 additions and 23 deletions

View File

@ -138,7 +138,7 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
continue;
try {
instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes));
instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes), true);
} catch (const std::exception&) {
instance->SetField(fid, Empty);
}

View File

@ -39,7 +39,8 @@ Timer::Ptr DbConnection::m_ProgramStatusTimer;
boost::once_flag DbConnection::m_OnceFlag = BOOST_ONCE_INIT;
DbConnection::DbConnection(void)
: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0), m_IDCacheValid(false)
: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0),
m_IDCacheValid(false), m_ActiveChangedHandler(false)
{ }
void DbConnection::OnConfigLoaded(void)
@ -74,7 +75,14 @@ void DbConnection::Start(bool runtimeCreated)
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
}
void DbConnection::EnableActiveChangedHandler(void)
{
if (!m_ActiveChangedHandler) {
ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
m_ActiveChangedHandler = true;
}
}
void DbConnection::StatsLoggerTimerHandler(void)
@ -394,8 +402,10 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
bool dbActive = GetObjectActive(dbobj);
bool active = object->IsActive();
if (active && !dbActive) {
if (active) {
if (!dbActive)
ActivateObject(dbobj);
dbobj->SendConfigUpdate();
dbobj->SendStatusUpdate();
} else if (!active) {

View File

@ -98,6 +98,8 @@ protected:
bool IsIDCacheValid(void) const;
void SetIDCacheValid(bool valid);
void EnableActiveChangedHandler(void);
static void UpdateProgramStatus(void);
static int GetSessionToken(void);
@ -127,6 +129,7 @@ private:
RingBuffer m_QueryStats;
int m_PendingQueries;
double m_PendingQueriesTimestamp;
bool m_ActiveChangedHandler;
};
struct database_error : virtual std::exception, virtual boost::exception { };

View File

@ -399,16 +399,16 @@ void IdoMysqlConnection::Reconnect(void)
SetIDCacheValid(true);
EnableActiveChangedHandler();
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
if (dbobj->GetObject() == NULL) {
if (dbobj->GetObject())
continue;
Log(LogNotice, "IdoMysqlConnection")
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
<< "' name2: '" << dbobj->GetName2() + "'.";
DeactivateObject(dbobj);
} else {
dbobj->SendConfigUpdate();
dbobj->SendStatusUpdate();
}
}
UpdateAllObjects();

View File

@ -372,16 +372,16 @@ void IdoPgsqlConnection::Reconnect(void)
SetIDCacheValid(true);
EnableActiveChangedHandler();
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
if (dbobj->GetObject() == NULL) {
if (dbobj->GetObject())
continue;
Log(LogNotice, "IdoPgsqlConnection")
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
<< "' name2: '" << dbobj->GetName2() + "'.";
DeactivateObject(dbobj);
} else {
dbobj->SendConfigUpdate();
dbobj->SendStatusUpdate();
}
}
UpdateAllObjects();