Ignore remote object updates when local object is newer.

This commit is contained in:
Gunnar Beutner 2012-07-02 19:25:33 +02:00
parent 512f46907e
commit a7be3a40c9
3 changed files with 24 additions and 1 deletions

View 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)

View 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);

View 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());
}