From b313c6d0e750c556676147bc35b357350ea42422 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 7 May 2019 16:04:34 +0300 Subject: [PATCH] MXS-2474 Ignore attempts to re-register a housekeeper task It is an error to register the same task multiple times, but for a maintenance release it is simpler and less risky to simply ignore an attempt (that BLR does) to do that. Allowing a task to be registered anew causes behaviour akin to a leak. --- server/core/housekeeper.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/server/core/housekeeper.cc b/server/core/housekeeper.cc index 665a51ceb..aeb544825 100644 --- a/server/core/housekeeper.cc +++ b/server/core/housekeeper.cc @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -205,7 +206,29 @@ void Housekeeper::stop() void Housekeeper::add(const Task& task) { std::lock_guard guard(m_lock); - m_tasks.push_back(task); + + auto i = std::find_if(m_tasks.begin(), m_tasks.end(), Task::NameMatch(task.name)); + if (i == m_tasks.end()) + { + m_tasks.push_back(task); + } + else + { + const Task& existing = *i; + + bool identical = false; + if (task.func == existing.func + && task.data == existing.data + && task.frequency == existing.frequency) + { + identical = true; + } + + MXS_INFO("Housekeeper task `%s` added anew, all settings %s identical. " + "Second attempt to add is ignored.", + identical ? "ARE" : "are NOT", + task.name.c_str()); + } } void Housekeeper::remove(std::string name)