Speed up config compiler.

Fixes #5255
This commit is contained in:
Gunnar Beutner 2013-12-03 09:59:21 +01:00
parent 08dc3398a9
commit 6625346922
5 changed files with 30 additions and 36 deletions

View File

@ -167,11 +167,13 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
if ((field.Attributes & attributeTypes) == 0) if ((field.Attributes & attributeTypes) == 0)
continue; continue;
if (!input->Contains(field.Name)) Value value = input->Get(field.Name);
if (value.IsEmpty())
continue; continue;
try { try {
instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes)); instance->SetField(i, Deserialize(value, attributeTypes));
} catch (const std::exception&) { } catch (const std::exception&) {
instance->SetField(i, Empty); instance->SetField(i, Empty);
} }

View File

@ -32,10 +32,10 @@ namespace icinga
struct Field struct Field
{ {
int ID; int ID;
String Name; const char *Name;
int Attributes; int Attributes;
Field(int id, const String& name, int attributes) Field(int id, const char *name, int attributes)
: ID(id), Name(name), Attributes(attributes) : ID(id), Name(name), Attributes(attributes)
{ } { }
}; };

View File

@ -105,6 +105,9 @@ void ConfigItem::Link(void)
{ {
ObjectLock olock(this); ObjectLock olock(this);
if (m_LinkedExpressionList)
return;
m_LinkedExpressionList = make_shared<ExpressionList>(); m_LinkedExpressionList = make_shared<ExpressionList>();
BOOST_FOREACH(const String& name, m_ParentNames) { BOOST_FOREACH(const String& name, m_ParentNames) {
@ -118,7 +121,7 @@ void ConfigItem::Link(void)
} else { } else {
parent->Link(); parent->Link();
ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList(); ExpressionList::Ptr pexprl = parent->m_LinkedExpressionList;
m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo)); m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo));
} }
} }
@ -126,15 +129,26 @@ void ConfigItem::Link(void)
m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo)); m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo));
} }
ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void) const ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void)
{ {
ObjectLock olock(this); if (!m_LinkedExpressionList)
Link();
return m_LinkedExpressionList; return m_LinkedExpressionList;
} }
Dictionary::Ptr ConfigItem::GetProperties(void)
{
if (!m_Properties) {
m_Properties = make_shared<Dictionary>();
GetLinkedExpressionList()->Execute(m_Properties);
}
return m_Properties;
}
/** /**
* Commits the configuration item by creating or updating a DynamicObject * Commits the configuration item by creating a DynamicObject
* object. * object.
* *
* @returns The DynamicObject that was created/updated. * @returns The DynamicObject that was created/updated.
@ -157,24 +171,9 @@ DynamicObject::Ptr ConfigItem::Commit(void)
if (IsAbstract()) if (IsAbstract())
return DynamicObject::Ptr(); return DynamicObject::Ptr();
/* Create a fake update in the format that Dictionary::Ptr properties = GetProperties();
* DynamicObject::Deserialize expects. */
Dictionary::Ptr attrs = make_shared<Dictionary>();
Link(); DynamicObject::Ptr dobj = dtype->CreateObject(properties);
Dictionary::Ptr properties = make_shared<Dictionary>();
GetLinkedExpressionList()->Execute(properties);
{
ObjectLock olock(properties);
BOOST_FOREACH(const Dictionary::Pair& kv, properties) {
attrs->Set(kv.first, kv.second);
}
}
DynamicObject::Ptr dobj = dtype->CreateObject(attrs);
dobj->Register(); dobj->Register();
return dobj; return dobj;
@ -238,12 +237,6 @@ bool ConfigItem::ActivateItems(bool validateOnly)
if (ConfigCompilerContext::GetInstance()->HasErrors()) if (ConfigCompilerContext::GetInstance()->HasErrors())
return false; return false;
Log(LogInformation, "config", "Linking config items...");
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
kv.second->Link();
}
if (ConfigCompilerContext::GetInstance()->HasErrors()) if (ConfigCompilerContext::GetInstance()->HasErrors())
return false; return false;

View File

@ -48,9 +48,8 @@ public:
std::vector<ConfigItem::Ptr> GetParents(void) const; std::vector<ConfigItem::Ptr> GetParents(void) const;
void Link(void); void Link(void);
ExpressionList::Ptr GetLinkedExpressionList(void) const; ExpressionList::Ptr GetLinkedExpressionList(void);
Dictionary::Ptr GetProperties(void);
void GetProperties(void);
DynamicObject::Ptr Commit(void); DynamicObject::Ptr Commit(void);
void Register(void); void Register(void);
@ -79,6 +78,7 @@ private:
DebugInfo m_DebugInfo; /**< Debug information. */ DebugInfo m_DebugInfo; /**< Debug information. */
ExpressionList::Ptr m_LinkedExpressionList; ExpressionList::Ptr m_LinkedExpressionList;
Dictionary::Ptr m_Properties;
static boost::mutex m_Mutex; static boost::mutex m_Mutex;

View File

@ -79,8 +79,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item)
if (item->IsAbstract()) if (item->IsAbstract())
return; return;
Dictionary::Ptr attrs = make_shared<Dictionary>(); Dictionary::Ptr attrs = item->GetProperties();
item->GetLinkedExpressionList()->Execute(attrs);
std::vector<String> locations; std::vector<String> locations;
DebugInfo debugInfo = item->GetDebugInfo(); DebugInfo debugInfo = item->GetDebugInfo();