From 19e7524b3110d92b8f902435c511b15d6c3200c4 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 30 Sep 2015 10:04:37 +0200 Subject: [PATCH] Fix problem with non-existing objects in config sync updates refs #9851 refs #9927 refs #9081 --- lib/remote/apilistener-configsync.cpp | 48 +++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index 9f904df5f..ec6467346 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -138,36 +138,40 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin object->SetVersion(objVersion, false, origin); } + if (!object) + return Empty; + /* update object attributes if version was changed */ - if (object && objVersion > object->GetVersion()) { - Log(LogInformation, "ApiListener") - << "Processing config update for object '" << object->GetName() - << "': Object version " << object->GetVersion() - << " is older than the received version " << objVersion << "."; - - Dictionary::Ptr modified_attributes = params->Get("modified_attributes"); - - if (modified_attributes) { - ObjectLock olock(modified_attributes); - BOOST_FOREACH(const Dictionary::Pair& kv, modified_attributes) { - /* update all modified attributes - * but do not update the object version yet. - * This triggers cluster events otherwise. - */ - object->ModifyAttribute(kv.first, kv.second, false); - } - } - - /* keep the object version in sync with the sender */ - object->SetVersion(objVersion, false, origin); - } else { + if (objVersion <= object->GetVersion()) { Log(LogNotice, "ApiListener") << "Discarding config update for object '" << object->GetName() << "': Object version " << object->GetVersion() << " is more recent than the received version " << objVersion << "."; + return Empty; } + Log(LogNotice, "ApiListener") + << "Processing config update for object '" << object->GetName() + << "': Object version " << object->GetVersion() + << " is older than the received version " << objVersion << "."; + + Dictionary::Ptr modified_attributes = params->Get("modified_attributes"); + + if (modified_attributes) { + ObjectLock olock(modified_attributes); + BOOST_FOREACH(const Dictionary::Pair& kv, modified_attributes) { + /* update all modified attributes + * but do not update the object version yet. + * This triggers cluster events otherwise. + */ + object->ModifyAttribute(kv.first, kv.second, false); + } + } + + /* keep the object version in sync with the sender */ + object->SetVersion(objVersion, false, origin); + return Empty; }