]> granicus.if.org Git - icinga2/commitdiff
Change object version to timestamps for diff updates on config sync
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 30 Sep 2015 14:58:18 +0000 (16:58 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 30 Sep 2015 14:58:18 +0000 (16:58 +0200)
fixes #10257

lib/base/configobject.cpp
lib/base/configobject.ti
lib/remote/apilistener-configsync.cpp
lib/remote/configobjectutility.cpp

index 6ce9dfcb121da7e7b212ddcdcd1c08f3ce226fca..2c3a4ea18eb043ac8ca07bc031f9dc434765c73e 100644 (file)
@@ -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();
 
index 1e4a3f83f7eec28f99976990b4c6d1e142451da9..168e7c7c51667d13a90513439ec4a8bb82cfd490 100644 (file)
@@ -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; }}}
        };
 };
 
index e4ebccc9f9fe0013c8b01783b49e0140e63b367f..aa671f655184b4641ba12885169162c41a58e2c8 100644 (file)
@@ -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")
index eb62f84051c36e35c7e72eb2bad7ff4936e05c78..cd83d87bdb29a723598ef1215a7321ade38532ad 100644 (file)
@@ -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");