diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 497c969a1..7dac7287e 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -152,7 +152,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran String objectKey = CalculateCheckSumString(object->GetName()); //String objectKey = object->GetName(); - std::set propertiesBlacklist ({"name"}); + std::set propertiesBlacklist ({"name", "__name", "package", "source_location", "templates"}); Dictionary::Ptr checkSums = new Dictionary(); checkSums->Set("name_checksum", CalculateCheckSumString(object->GetName())); @@ -200,6 +200,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject)); } + checkSums->Set("metadata_checksum", CalculateCheckSumMetadata(object)); checkSums->Set("properties_checksum", CalculateCheckSumProperties(object, propertiesBlacklist)); String checkSumsBody = JsonEncode(checkSums); diff --git a/lib/redis/rediswriter-utility.cpp b/lib/redis/rediswriter-utility.cpp index 897938711..707fd69dd 100644 --- a/lib/redis/rediswriter-utility.cpp +++ b/lib/redis/rediswriter-utility.cpp @@ -58,6 +58,13 @@ String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, return HashValue(object, propertiesBlacklist); } +static const std::set metadataWhitelist ({"package", "source_location", "templates"}); + +String RedisWriter::CalculateCheckSumMetadata(const ConfigObject::Ptr& object) +{ + return HashValue(object, metadataWhitelist, true); +} + String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object) { Dictionary::Ptr vars = object->GetVars(); @@ -75,7 +82,7 @@ String RedisWriter::HashValue(const Value& value) return HashValue(value, propertiesBlacklistEmpty); } -String RedisWriter::HashValue(const Value& value, const std::set& propertiesBlacklist) +String RedisWriter::HashValue(const Value& value, const std::set& propertiesBlacklist, bool propertiesWhitelist) { Value temp; bool mutabl; @@ -98,8 +105,22 @@ String RedisWriter::HashValue(const Value& value, const std::set& proper dict = dict->ShallowClone(); ObjectLock olock(dict); - for (auto& property : propertiesBlacklist) - dict->Remove(property); + + if (propertiesWhitelist) { + auto current = dict->Begin(); + auto propertiesBlacklistEnd = propertiesBlacklist.end(); + + while (current != dict->End()) { + if (propertiesBlacklist.find(current->first) == propertiesBlacklistEnd) { + dict->Remove(current++); + } else { + ++current; + } + } + } else { + for (auto& property : propertiesBlacklist) + dict->Remove(property); + } if (!mutabl) temp = dict; diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index 98e0dbdb9..194dff8ab 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -77,10 +77,11 @@ private: static String CalculateCheckSumString(const String& str); static String CalculateCheckSumGroups(const Array::Ptr& groups); static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set& propertiesBlacklist); + static String CalculateCheckSumMetadata(const ConfigObject::Ptr& object); static String CalculateCheckSumVars(const CustomVarObject::Ptr& object); static String HashValue(const Value& value); - static String HashValue(const Value& value, const std::set& propertiesBlacklist); + static String HashValue(const Value& value, const std::set& propertiesBlacklist, bool propertiesWhitelist = false); static void StateChangedHandler(const ConfigObject::Ptr& object); static void VersionChangedHandler(const ConfigObject::Ptr& object);