Add monitor reconfiguration helper
The MonitorManager function reconfigured a monitor and rolls back to the old configuration if the new one doesn't work.
This commit is contained in:
@ -745,23 +745,16 @@ bool do_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backup monitor parameters in case configure fails.
|
|
||||||
MXS_CONFIG_PARAMETER originals = monitor->parameters;
|
|
||||||
MXS_CONFIG_PARAMETER modified = monitor->parameters;
|
MXS_CONFIG_PARAMETER modified = monitor->parameters;
|
||||||
|
|
||||||
modified.set(key, value);
|
modified.set(key, value);
|
||||||
bool success = monitor->configure(&modified);
|
|
||||||
|
bool success = MonitorManager::reconfigure_monitor(monitor, modified);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
MXS_NOTICE("Updated monitor '%s': %s=%s", monitor->m_name, key, value);
|
MXS_NOTICE("Updated monitor '%s': %s=%s", monitor->m_name, key, value);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Configure failed, restore original configs. This should not fail.
|
|
||||||
// TODO: add a flag to monitor which prevents startup if config is wrong.
|
|
||||||
MXB_AT_DEBUG(bool check = ) monitor->configure(&originals);
|
|
||||||
mxb_assert(check);
|
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2535,17 +2528,11 @@ bool runtime_alter_monitor_from_json(Monitor* monitor, json_t* new_json)
|
|||||||
MonitorManager::stop_monitor(monitor);
|
MonitorManager::stop_monitor(monitor);
|
||||||
auto old_params = monitor->parameters;
|
auto old_params = monitor->parameters;
|
||||||
|
|
||||||
if (monitor->configure(¶ms))
|
if (MonitorManager::reconfigure_monitor(monitor, params))
|
||||||
{
|
{
|
||||||
MonitorManager::monitor_serialize(monitor);
|
MonitorManager::monitor_serialize(monitor);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Something went wrong, restore the old parameters
|
|
||||||
MXB_AT_DEBUG(bool check = ) monitor->configure(&old_params);
|
|
||||||
mxb_assert(check);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (restart)
|
if (restart)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -149,6 +149,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool monitor_serialize(const mxs::Monitor* monitor);
|
static bool monitor_serialize(const mxs::Monitor* monitor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to reconfigure a monitor
|
||||||
|
*
|
||||||
|
* If the configuration fails, the old parameters are restored.
|
||||||
|
*
|
||||||
|
* @param monitor Monitor to reconfigure
|
||||||
|
* @param parameters New parameters to apply
|
||||||
|
*
|
||||||
|
* @return True if reconfiguration was successful
|
||||||
|
*/
|
||||||
|
static bool reconfigure_monitor(mxs::Monitor* monitor, const MXS_CONFIG_PARAMETER& parameters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert monitor to JSON
|
* @brief Convert monitor to JSON
|
||||||
*
|
*
|
||||||
|
|||||||
@ -792,6 +792,24 @@ bool MonitorManager::monitor_serialize(const Monitor* monitor)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool MonitorManager::reconfigure_monitor(mxs::Monitor* monitor, const MXS_CONFIG_PARAMETER& parameters)
|
||||||
|
{
|
||||||
|
// Backup monitor parameters in case configure fails.
|
||||||
|
auto orig = monitor->parameters;
|
||||||
|
monitor->parameters.clear();
|
||||||
|
|
||||||
|
bool success = monitor->configure(¶meters);
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
MXB_AT_DEBUG(bool check = ) monitor->configure(&orig);
|
||||||
|
mxb_assert(check);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
json_t* MonitorManager::monitor_to_json(const Monitor* monitor, const char* host)
|
json_t* MonitorManager::monitor_to_json(const Monitor* monitor, const char* host)
|
||||||
{
|
{
|
||||||
string self = MXS_JSON_API_MONITORS;
|
string self = MXS_JSON_API_MONITORS;
|
||||||
|
|||||||
Reference in New Issue
Block a user