RedisWriter: fix disappeared config objects not being deleted

This commit is contained in:
Alexander A. Klimov 2018-06-22 17:57:36 +02:00 committed by Michael Friedrich
parent e7411ea158
commit d15769fa34
1 changed files with 8 additions and 7 deletions

View File

@ -58,6 +58,11 @@ void RedisWriter::UpdateAllConfigObjects(void)
const String keyPrefix = "icinga:config:";
std::map<String, String> lcTypes;
for (const Type::Ptr& type : Type::GetAllTypes()) {
lcTypes.emplace(type->GetName().ToLower(), type->GetName());
}
do {
std::shared_ptr<redisReply> reply = ExecuteQuery({ "SCAN", Convert::ToString(cursor), "MATCH", keyPrefix + "*", "COUNT", "1000" });
@ -84,16 +89,12 @@ void RedisWriter::UpdateAllConfigObjects(void)
String type = namePair.SubStr(0, pos);
String name = namePair.SubStr(pos + 1);
Type::Ptr ptype = Type::GetByName(type);
auto actualTypeName = lcTypes.find(type);
if (!ptype)
continue;
ConfigType *ctype = dynamic_cast<ConfigType *>(ptype.get());
if (!ctype)
if (actualTypeName == lcTypes.end())
continue;
Type::Ptr ptype = Type::GetByName(actualTypeName->second);
auto& deleteQuery = deleteQueries[ptype.get()];
if (deleteQuery.empty())