MXS-2271 Move journal_max_age inside settings container

This commit is contained in:
Esa Korhonen 2019-01-28 18:24:04 +02:00
parent ce9b49d8d5
commit 03411e825d
7 changed files with 27 additions and 23 deletions

View File

@ -288,6 +288,8 @@ public:
void set_script_timeout(int value);
void monitor_set_journal_max_age(time_t value);
/**
* Create a list of running servers
*
@ -317,8 +319,6 @@ public:
MXS_CONFIG_PARAMETER* parameters = nullptr; /**< Configuration parameters */
std::vector<MXS_MONITORED_SERVER*> m_servers; /**< Monitored servers */
time_t journal_max_age; /**< Maximum age of journal file */
protected:
/**
@ -350,6 +350,8 @@ protected:
int script_timeout {0}; /**< Timeout in seconds for the monitor scripts */
uint64_t events {0}; /**< Bitfield of events which trigger the script */
time_t journal_max_age {0}; /**< Maximum age of journal file */
SERVER::DiskSpaceLimits disk_space_limits; /**< Disk space thresholds */
/**
* How often should a disk space check be made at most, in milliseconds. Negative values imply
@ -391,6 +393,8 @@ private:
* @return Return value of the executed script or -1 on error.
*/
int launch_command(MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd);
bool journal_is_stale();
};
/**

View File

@ -633,7 +633,7 @@ bool do_alter_monitor(Monitor* monitor, const char* key, const char* value)
{
if (auto ival = get_positive_int(value))
{
monitor_set_journal_max_age(monitor, ival);
monitor->monitor_set_journal_max_age(ival);
}
}
else if (strcmp(key, CN_SCRIPT_TIMEOUT) == 0)
@ -675,7 +675,7 @@ bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
}
if (was_running)
{
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
}
return success;
}
@ -2245,7 +2245,7 @@ Monitor* runtime_create_monitor_from_json(json_t* json)
}
else
{
monitor_start(rval, rval->parameters);
MonitorManager::monitor_start(rval, rval->parameters);
}
}
}
@ -2431,7 +2431,7 @@ bool runtime_alter_monitor_from_json(Monitor* monitor, json_t* new_json)
if (restart)
{
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
}
}
}

View File

@ -105,10 +105,12 @@ public:
* @attn Must only be called in single-thread context at system shutdown.
*/
static void destroy_all_monitors();
static void monitor_start(Monitor*, const MXS_CONFIG_PARAMETER*);
};
void monitor_start(Monitor*, const MXS_CONFIG_PARAMETER*);
void monitor_stop(Monitor*);
/**

View File

@ -139,7 +139,6 @@ ThisUnit this_unit;
static void monitor_server_free_all(std::vector<MXS_MONITORED_SERVER*>& servers);
static void remove_server_journal(Monitor* monitor);
static bool journal_is_stale(Monitor* monitor, time_t max_age);
static const char* monitor_state_to_string(monitor_state_t state);
/** Server type specific bits */
@ -193,7 +192,7 @@ bool Monitor::configure_base(const MXS_CONFIG_PARAMETER* params)
m_settings.conn_settings.connect_timeout = config_get_integer(params, CN_BACKEND_CONNECT_TIMEOUT);
m_settings.conn_settings.connect_attempts = config_get_integer(params, CN_BACKEND_CONNECT_ATTEMPTS);
m_settings.interval = config_get_integer(params, CN_MONITOR_INTERVAL);
journal_max_age = config_get_integer(params, CN_JOURNAL_MAX_AGE);
m_settings.journal_max_age = config_get_integer(params, CN_JOURNAL_MAX_AGE);
m_settings.script_timeout = config_get_integer(params, CN_SCRIPT_TIMEOUT);
m_settings.script = config_get_string(params, CN_SCRIPT);
m_settings.events = config_get_enum(params, CN_EVENTS, mxs_monitor_event_enum_values);
@ -250,7 +249,7 @@ void MonitorManager::destroy_all_monitors()
*
* @param monitor The Monitor that should be started
*/
void monitor_start(Monitor* monitor, const MXS_CONFIG_PARAMETER* params)
void MonitorManager::monitor_start(Monitor* monitor, const MXS_CONFIG_PARAMETER* params)
{
if (monitor)
{
@ -259,7 +258,7 @@ void monitor_start(Monitor* monitor, const MXS_CONFIG_PARAMETER* params)
// Only start the monitor if it's stopped.
if (monitor->m_state == MONITOR_STATE_STOPPED)
{
if (journal_is_stale(monitor, monitor->journal_max_age))
if (monitor->journal_is_stale())
{
MXS_WARNING("Removing stale journal file for monitor '%s'.", monitor->m_name);
remove_server_journal(monitor);
@ -285,7 +284,7 @@ void monitor_start_all()
this_unit.foreach_monitor([](Monitor* monitor) {
if (monitor->m_active)
{
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
}
return true;
});
@ -376,7 +375,7 @@ bool monitor_add_server(Monitor* mon, SERVER* server)
if (old_state == MONITOR_STATE_RUNNING)
{
monitor_start(mon, mon->parameters);
MonitorManager::monitor_start(mon, mon->parameters);
}
}
@ -444,7 +443,7 @@ void monitor_remove_server(Monitor* mon, SERVER* server)
if (old_state == MONITOR_STATE_RUNNING)
{
monitor_start(mon, mon->parameters);
MonitorManager::monitor_start(mon, mon->parameters);
}
}
@ -597,12 +596,11 @@ void Monitor::set_interval(int64_t interval)
/**
* Set the maximum age of the monitor journal
*
* @param mon The monitor instance
* @param interval The journal age in seconds
*/
void monitor_set_journal_max_age(Monitor* mon, time_t value)
void Monitor::monitor_set_journal_max_age(time_t value)
{
mon->journal_max_age = value;
m_settings.journal_max_age = value;
}
void Monitor::set_script_timeout(int value)
@ -2210,12 +2208,12 @@ static void remove_server_journal(Monitor* monitor)
}
}
static bool journal_is_stale(Monitor* monitor, time_t max_age)
bool Monitor::journal_is_stale()
{
bool is_stale = true;
char path[PATH_MAX];
if (get_data_file_path(monitor, path) < PATH_MAX)
auto max_age = m_settings.journal_max_age;
if (get_data_file_path(this, path) < PATH_MAX)
{
struct stat st;

View File

@ -267,7 +267,7 @@ HttpResponse cb_stop_monitor(const HttpRequest& request)
HttpResponse cb_start_monitor(const HttpRequest& request)
{
Monitor* monitor = monitor_find(request.uri_part(1).c_str());
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
return HttpResponse(MHD_HTTP_NO_CONTENT);
}

View File

@ -2727,7 +2727,7 @@ static void shutdown_monitor(DCB* dcb, Monitor* monitor)
*/
static void restart_monitor(DCB* dcb, Monitor* monitor)
{
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
}
/**

View File

@ -615,7 +615,7 @@ void exec_restart_monitor(DCB* dcb, MAXINFO_TREE* tree)
Monitor* monitor = monitor_find(tree->value);
if (monitor)
{
monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, monitor->parameters);
maxinfo_send_ok(dcb);
}
else