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);
|
||||
|
||||
if (updateVersion)
|
||||
SetVersion(GetVersion() + 1);
|
||||
SetVersion(Utility::GetTime());
|
||||
|
||||
if (updated_original_attributes)
|
||||
NotifyOriginalAttributes();
|
||||
|
@ -341,11 +341,7 @@ void ConfigObject::RestoreAttribute(const String& attr)
|
|||
original_attributes->Remove(attr);
|
||||
SetField(fid, newValue);
|
||||
|
||||
/* increment the version. although restoring would mean
|
||||
* decrementing the version, but we cannot notify other
|
||||
* cluster nodes without increment.
|
||||
*/
|
||||
SetVersion(GetVersion() + 1);
|
||||
SetVersion(Utility::GetTime());
|
||||
}
|
||||
|
||||
bool ConfigObject::IsAttributeModified(const String& attr) const
|
||||
|
@ -638,7 +634,6 @@ void ConfigObject::DumpModifiedAttributes(const boost::function<void(const Confi
|
|||
ObjectLock olock(originalAttributes);
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, originalAttributes) {
|
||||
String key = kv.first;
|
||||
// TODO-MA: vars.os
|
||||
|
||||
Type::Ptr type = object->GetReflectionType();
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class ConfigObject : ConfigObjectBase
|
|||
[protected] bool state_loaded;
|
||||
Dictionary::Ptr original_attributes;
|
||||
[state] int version {
|
||||
default {{{ return 1; }}}
|
||||
default {{{ return 0; }}}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -392,6 +392,15 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
|
|||
if (objZone.IsEmpty())
|
||||
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 */
|
||||
if (!azone->IsChildOf(lzone) && azone != lzone) {
|
||||
Log(LogDebug, "ApiListener")
|
||||
|
|
|
@ -74,6 +74,9 @@ String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const Stri
|
|||
|
||||
allAttrs->Remove("name");
|
||||
|
||||
/* update the version for config sync */
|
||||
allAttrs->Set("version", Utility::GetTime());
|
||||
|
||||
std::ostringstream config;
|
||||
ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, templates, allAttrs);
|
||||
ConfigWriter::EmitRaw(config, "\n");
|
||||
|
|
Loading…
Reference in New Issue