Add RAII class for stopping monitors
This way the state is encapsulated in the object and the required changes are done in one place. This makes the code reusable across all functions making it easier to implement better monitor alteration code.
This commit is contained in:
@ -760,21 +760,14 @@ bool do_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
|||||||
|
|
||||||
bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
||||||
{
|
{
|
||||||
// If the monitor is already stopped, don't stop/start it.
|
MonitorStop stop(monitor);
|
||||||
bool was_running = (monitor->state() == MONITOR_STATE_RUNNING);
|
|
||||||
if (was_running)
|
|
||||||
{
|
|
||||||
MonitorManager::stop_monitor(monitor);
|
|
||||||
}
|
|
||||||
bool success = do_alter_monitor(monitor, key, value);
|
bool success = do_alter_monitor(monitor, key, value);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
MonitorManager::monitor_serialize(monitor);
|
MonitorManager::monitor_serialize(monitor);
|
||||||
}
|
}
|
||||||
if (was_running)
|
|
||||||
{
|
|
||||||
MonitorManager::start_monitor(monitor);
|
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -178,3 +178,28 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void debug_wait_one_tick();
|
static void debug_wait_one_tick();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// RAII helper class for temprarily stopping monitors
|
||||||
|
class MonitorStop
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MonitorStop(mxs::Monitor* monitor)
|
||||||
|
: m_monitor(monitor->state() == MONITOR_STATE_RUNNING ? monitor : nullptr)
|
||||||
|
{
|
||||||
|
if (m_monitor)
|
||||||
|
{
|
||||||
|
MonitorManager::stop_monitor(m_monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~MonitorStop()
|
||||||
|
{
|
||||||
|
if (m_monitor)
|
||||||
|
{
|
||||||
|
MonitorManager::start_monitor(m_monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mxs::Monitor* m_monitor;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user