diff --git a/server/core/config.c b/server/core/config.c index d1c123476..0d991d241 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -2584,19 +2584,31 @@ int create_new_monitor(CONFIG_CONTEXT *context, CONFIG_CONTEXT *obj, HASHTABLE* char *connect_timeout = config_get_value(obj->parameters, "backend_connect_timeout"); if (connect_timeout) { - monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, atoi(connect_timeout)); + if (!monitorSetNetworkTimeout(obj->element, MONITOR_CONNECT_TIMEOUT, atoi(connect_timeout))) + { + MXS_ERROR("Failed to set backend_connect_timeout"); + error_count++; + } } char *read_timeout = config_get_value(obj->parameters, "backend_read_timeout"); if (read_timeout) { - monitorSetNetworkTimeout(obj->element, MONITOR_READ_TIMEOUT, atoi(read_timeout)); + if (!monitorSetNetworkTimeout(obj->element, MONITOR_READ_TIMEOUT, atoi(read_timeout))) + { + MXS_ERROR("Failed to set backend_read_timeout"); + error_count++; + } } char *write_timeout = config_get_value(obj->parameters, "backend_write_timeout"); if (write_timeout) { - monitorSetNetworkTimeout(obj->element, MONITOR_WRITE_TIMEOUT, atoi(write_timeout)); + if (!monitorSetNetworkTimeout(obj->element, MONITOR_WRITE_TIMEOUT, atoi(write_timeout))) + { + MXS_ERROR("Failed to set backend_write_timeout"); + error_count++; + } } /* get the servers to monitor */ diff --git a/server/core/monitor.c b/server/core/monitor.c index 60590149d..46f10b821 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -411,60 +411,39 @@ monitorSetInterval(MONITOR *mon, unsigned long interval) * @param type The timeout handling type * @param value The timeout to set */ -void -monitorSetNetworkTimeout(MONITOR *mon, int type, int value) { +bool +monitorSetNetworkTimeout(MONITOR *mon, int type, int value) +{ + bool rval = true; - int max_timeout = (int)(mon->interval/1000); - int new_timeout = max_timeout -1; - - if (new_timeout <= 0) + if (value > 0) { - new_timeout = DEFAULT_CONNECT_TIMEOUT; + switch (type) + { + case MONITOR_CONNECT_TIMEOUT: + mon->connect_timeout = value; + break; + + case MONITOR_READ_TIMEOUT: + mon->read_timeout = value; + break; + + case MONITOR_WRITE_TIMEOUT: + mon->write_timeout = value; + break; + + default: + MXS_ERROR("Monitor setNetworkTimeout received an unsupported action type %i", type); + rval = false; + break; + } } - - switch(type) { - case MONITOR_CONNECT_TIMEOUT: - if (value < max_timeout) - { - memcpy(&mon->connect_timeout, &value, sizeof(int)); - } - else - { - memcpy(&mon->connect_timeout, &new_timeout, sizeof(int)); - MXS_WARNING("Monitor Connect Timeout %i is greater than monitor interval ~%i seconds" - ", lowering to %i seconds", value, max_timeout, new_timeout); - } - break; - - case MONITOR_READ_TIMEOUT: - if (value < max_timeout) - { - memcpy(&mon->read_timeout, &value, sizeof(int)); - } - else - { - memcpy(&mon->read_timeout, &new_timeout, sizeof(int)); - MXS_WARNING("Monitor Read Timeout %i is greater than monitor interval ~%i seconds" - ", lowering to %i seconds", value, max_timeout, new_timeout); - } - break; - - case MONITOR_WRITE_TIMEOUT: - if (value < max_timeout) - { - memcpy(&mon->write_timeout, &value, sizeof(int)); - } - else - { - memcpy(&mon->write_timeout, &new_timeout, sizeof(int)); - MXS_WARNING("Monitor Write Timeout %i is greater than monitor interval ~%i seconds" - ", lowering to %i seconds", value, max_timeout, new_timeout); - } - break; - default: - MXS_ERROR("Monitor setNetworkTimeout received an unsupported action type %i", type); - break; + else + { + MXS_ERROR("Negative value for monitor timeout."); + rval = false; } + return rval; } /** diff --git a/server/include/monitor.h b/server/include/monitor.h index 9df937086..d97d0f06c 100644 --- a/server/include/monitor.h +++ b/server/include/monitor.h @@ -211,7 +211,7 @@ extern void monitorShowAll(DCB *); extern void monitorShow(DCB *, MONITOR *); extern void monitorList(DCB *); extern void monitorSetInterval (MONITOR *, unsigned long); -extern void monitorSetNetworkTimeout(MONITOR *, int, int); +extern bool monitorSetNetworkTimeout(MONITOR *, int, int); extern RESULTSET *monitorGetList(); bool check_monitor_permissions(MONITOR* monitor);