From 9dcb33e8f417d6b631c1607d991f4339ad213e88 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 30 Sep 2015 16:58:18 +0200 Subject: [PATCH] Change object version to timestamps for diff updates on config sync fixes #10257 --- lib/base/configobject.cpp | 9 ++------- lib/base/configobject.ti | 2 +- lib/remote/apilistener-configsync.cpp | 9 +++++++++ lib/remote/configobjectutility.cpp | 3 +++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index 6ce9dfcb1..2c3a4ea18 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -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::functionGetReflectionType(); diff --git a/lib/base/configobject.ti b/lib/base/configobject.ti index 1e4a3f83f..168e7c7c5 100644 --- a/lib/base/configobject.ti +++ b/lib/base/configobject.ti @@ -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; }}} }; }; diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index e4ebccc9f..aa671f655 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -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") diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index eb62f8405..cd83d87bd 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -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");