]> granicus.if.org Git - icinga2/commitdiff
Ignore remote object updates when local object is newer.
authorGunnar Beutner <gunnar@beutner.name>
Mon, 2 Jul 2012 17:25:33 +0000 (19:25 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 2 Jul 2012 17:25:33 +0000 (19:25 +0200)
base/configobject.cpp
base/configobject.h
components/cibsync/cibsynccomponent.cpp

index 57a062f9626a037a5dd0d22da72c70a4d5dce50e..245da3710390df0e49e297cdac7888807f8c0ce7 100644 (file)
@@ -99,12 +99,28 @@ string ConfigObject::GetSource(void) const
        return value;
 }
 
+void ConfigObject::SetCommitTimestamp(time_t ts)
+{
+       GetProperties()->SetProperty("__tx", ts);
+}
+
+time_t ConfigObject::GetCommitTimestamp(void) const
+{
+       long value = false;
+       GetProperties()->GetProperty("__tx", &value);
+       return value;
+}
+
 void ConfigObject::Commit(void)
 {
        ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
        ConfigObject::Ptr self = GetSelf();
        assert(!dobj || dobj == self);
        m_Container->CheckObject(self);
+
+       time_t now;
+       time(&now);
+       SetCommitTimestamp(now);
 }
 
 void ConfigObject::Unregister(void)
index 84b7b6db4d6d23bf414ee3c955e071845b9659af..82cb13136c7b755959e55bbe63f4290c6cd1f80c 100644 (file)
@@ -82,6 +82,8 @@ public:
        void SetSource(const string& value);
        string GetSource(void) const;
 
+       time_t GetCommitTimestamp(void) const;
+
        void Commit(void);
        void Unregister(void);
 
@@ -101,6 +103,8 @@ private:
        Dictionary::Ptr m_Properties;
        Dictionary::Ptr m_Tags;
 
+       void SetCommitTimestamp(time_t ts);
+
        static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key);
        static bool TypePredicate(const ConfigObject::Ptr& object, string type);
 
index 99a23bc7908c8103fc8fb792541c079a8d4460b5..893aa92a02590f5097d9e2aa49c936610cfb22bf 100644 (file)
@@ -240,7 +240,10 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender,
                        return;
                }
        } else {
-               /* TODO: compare transaction timestamps and reject the update if our local object is newer */
+               ConfigObject::Ptr remoteObject = boost::make_shared<ConfigObject>(properties.GetDictionary());
+
+               if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp())
+                       return;
 
                object->SetProperties(properties.GetDictionary());
        }