mirror of https://github.com/Icinga/icinga2.git
Change object version to timestamps for diff updates on config sync
fixes #10257
This commit is contained in:
parent
359fb3f82b
commit
9dcb33e8f4
|
@ -223,7 +223,7 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
|
||||||
SetField(fid, newValue);
|
SetField(fid, newValue);
|
||||||
|
|
||||||
if (updateVersion)
|
if (updateVersion)
|
||||||
SetVersion(GetVersion() + 1);
|
SetVersion(Utility::GetTime());
|
||||||
|
|
||||||
if (updated_original_attributes)
|
if (updated_original_attributes)
|
||||||
NotifyOriginalAttributes();
|
NotifyOriginalAttributes();
|
||||||
|
@ -341,11 +341,7 @@ void ConfigObject::RestoreAttribute(const String& attr)
|
||||||
original_attributes->Remove(attr);
|
original_attributes->Remove(attr);
|
||||||
SetField(fid, newValue);
|
SetField(fid, newValue);
|
||||||
|
|
||||||
/* increment the version. although restoring would mean
|
SetVersion(Utility::GetTime());
|
||||||
* decrementing the version, but we cannot notify other
|
|
||||||
* cluster nodes without increment.
|
|
||||||
*/
|
|
||||||
SetVersion(GetVersion() + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigObject::IsAttributeModified(const String& attr) const
|
bool ConfigObject::IsAttributeModified(const String& attr) const
|
||||||
|
@ -638,7 +634,6 @@ void ConfigObject::DumpModifiedAttributes(const boost::function<void(const Confi
|
||||||
ObjectLock olock(originalAttributes);
|
ObjectLock olock(originalAttributes);
|
||||||
BOOST_FOREACH(const Dictionary::Pair& kv, originalAttributes) {
|
BOOST_FOREACH(const Dictionary::Pair& kv, originalAttributes) {
|
||||||
String key = kv.first;
|
String key = kv.first;
|
||||||
// TODO-MA: vars.os
|
|
||||||
|
|
||||||
Type::Ptr type = object->GetReflectionType();
|
Type::Ptr type = object->GetReflectionType();
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ abstract class ConfigObject : ConfigObjectBase
|
||||||
[protected] bool state_loaded;
|
[protected] bool state_loaded;
|
||||||
Dictionary::Ptr original_attributes;
|
Dictionary::Ptr original_attributes;
|
||||||
[state] int version {
|
[state] int version {
|
||||||
default {{{ return 1; }}}
|
default {{{ return 0; }}}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -392,6 +392,15 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
|
||||||
if (objZone.IsEmpty())
|
if (objZone.IsEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* don't sync objects with an older version time than the endpoint's log position */
|
||||||
|
if (object->GetVersion() < endpoint->GetLocalLogPosition()) {
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "Skipping sync: object '" << object->GetName() << "'"
|
||||||
|
<< " is older than local log position of endpoint '"
|
||||||
|
<< endpoint->GetName() << "'.";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* don't sync objects for non-matching parent-child zones */
|
/* don't sync objects for non-matching parent-child zones */
|
||||||
if (!azone->IsChildOf(lzone) && azone != lzone) {
|
if (!azone->IsChildOf(lzone) && azone != lzone) {
|
||||||
Log(LogDebug, "ApiListener")
|
Log(LogDebug, "ApiListener")
|
||||||
|
|
|
@ -74,6 +74,9 @@ String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const Stri
|
||||||
|
|
||||||
allAttrs->Remove("name");
|
allAttrs->Remove("name");
|
||||||
|
|
||||||
|
/* update the version for config sync */
|
||||||
|
allAttrs->Set("version", Utility::GetTime());
|
||||||
|
|
||||||
std::ostringstream config;
|
std::ostringstream config;
|
||||||
ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, templates, allAttrs);
|
ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, templates, allAttrs);
|
||||||
ConfigWriter::EmitRaw(config, "\n");
|
ConfigWriter::EmitRaw(config, "\n");
|
||||||
|
|
Loading…
Reference in New Issue