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)
continue;
if (!input->Contains(field.Name))
Value value = input->Get(field.Name);
if (value.IsEmpty())
continue;
try {
instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes));
instance->SetField(i, Deserialize(value, attributeTypes));
} catch (const std::exception&) {
instance->SetField(i, Empty);
}

View File

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

View File

@ -105,6 +105,9 @@ void ConfigItem::Link(void)
{
ObjectLock olock(this);
if (m_LinkedExpressionList)
return;
m_LinkedExpressionList = make_shared<ExpressionList>();
BOOST_FOREACH(const String& name, m_ParentNames) {
@ -118,7 +121,7 @@ void ConfigItem::Link(void)
} else {
parent->Link();
ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList();
ExpressionList::Ptr pexprl = parent->m_LinkedExpressionList;
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));
}
ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void) const
ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void)
{
ObjectLock olock(this);
if (!m_LinkedExpressionList)
Link();
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.
*
* @returns The DynamicObject that was created/updated.
@ -157,24 +171,9 @@ DynamicObject::Ptr ConfigItem::Commit(void)
if (IsAbstract())
return DynamicObject::Ptr();
/* Create a fake update in the format that
* DynamicObject::Deserialize expects. */
Dictionary::Ptr attrs = make_shared<Dictionary>();
Dictionary::Ptr properties = GetProperties();
Link();
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);
DynamicObject::Ptr dobj = dtype->CreateObject(properties);
dobj->Register();
return dobj;
@ -238,12 +237,6 @@ bool ConfigItem::ActivateItems(bool validateOnly)
if (ConfigCompilerContext::GetInstance()->HasErrors())
return false;
Log(LogInformation, "config", "Linking config items...");
BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
kv.second->Link();
}
if (ConfigCompilerContext::GetInstance()->HasErrors())
return false;

View File

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

View File

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