From 3055e49f5ad647b29bf554f971bc9a0267ae914e Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 26 Apr 2019 17:00:45 +0300 Subject: [PATCH] MXS-2329 Use durations with query_retry_timeout Also change auth_[connect|read|write]_timeout to be time_t. --- .../Getting-Started/Configuration-Guide.md | 6 ++++ include/maxscale/config.hh | 6 ++-- server/core/config.cc | 19 ++++-------- server/core/config_runtime.cc | 30 +++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 73e1bcbcf..29b3e0575 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -401,6 +401,12 @@ seconds. An interrupted query is retried for either the configured amount of attempts or until the configured timeout is reached. +The value is specified as documented [here](#durations). If no explicit unit +is provided, the value is interpreted as seconds in MaxScale 2.4. In subsequent +versions a value without a unit may be rejected. Note that since the granularity +of the timeout is seconds, a timeout specified in milliseconds will be rejected, +even if the duration is longer than a second. + #### `passive` Controls whether MaxScale is a passive node in a cluster of multiple MaxScale diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index 0d9b9f60d..4f5b7e06b 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -477,10 +477,10 @@ struct MXS_CONFIG unsigned int pollsleep; /**< Wait time in blocking polls */ int syslog; /**< Log to syslog */ int maxlog; /**< Log to MaxScale's own logs */ - unsigned int auth_conn_timeout; /**< Connection timeout for the user + time_t auth_conn_timeout; /**< Connection timeout for the user * authentication */ - unsigned int auth_read_timeout; /**< Read timeout for the user authentication */ - unsigned int auth_write_timeout; /**< Write timeout for the user authentication */ + time_t auth_read_timeout; /**< Read timeout for the user authentication */ + time_t auth_write_timeout; /**< Write timeout for the user authentication */ bool skip_permission_checks; /**< Skip service and monitor permission checks */ int32_t passive; /**< True if MaxScale is in passive mode */ int64_t promoted_at; /**< Time when this Maxscale instance was diff --git a/server/core/config.cc b/server/core/config.cc index fe8e21d09..6a69eb4da 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -238,7 +238,7 @@ static pcre2_code* compile_regex_string(const char* regex_string, uint32_t* output_ovector_size); static bool duration_is_valid(const char* zValue, mxs::config::DurationUnit* pUnit); static bool get_seconds(const char* zName, const char* zValue, std::chrono::seconds* pSeconds); -static bool get_seconds(const char* zName, const char* zValue, unsigned int* pSeconds); +static bool get_seconds(const char* zName, const char* zValue, time_t* pSeconds); int config_get_ifaddr(unsigned char* output); @@ -2487,15 +2487,8 @@ static int handle_global_item(const char* name, const char* value) } else if (strcmp(name, CN_QUERY_RETRY_TIMEOUT) == 0) { - char* endptr; - int intval = strtol(value, &endptr, 0); - if (*endptr == '\0' && intval > 0) + if (!get_seconds(name, value, &gateway.query_retry_timeout)) { - gateway.query_retry_timeout = intval; - } - else - { - MXS_ERROR("Invalid timeout value for '%s': %s", CN_QUERY_RETRY_TIMEOUT, value); return 0; } } @@ -4723,9 +4716,9 @@ static bool create_global_config(const char* filename) } dprintf(file, "[maxscale]\n"); - dprintf(file, "%s=%u\n", CN_AUTH_CONNECT_TIMEOUT, gateway.auth_conn_timeout); - dprintf(file, "%s=%u\n", CN_AUTH_READ_TIMEOUT, gateway.auth_read_timeout); - dprintf(file, "%s=%u\n", CN_AUTH_WRITE_TIMEOUT, gateway.auth_write_timeout); + dprintf(file, "%s=%ld\n", CN_AUTH_CONNECT_TIMEOUT, gateway.auth_conn_timeout); + dprintf(file, "%s=%ld\n", CN_AUTH_READ_TIMEOUT, gateway.auth_read_timeout); + dprintf(file, "%s=%ld\n", CN_AUTH_WRITE_TIMEOUT, gateway.auth_write_timeout); dprintf(file, "%s=%s\n", CN_ADMIN_AUTH, gateway.admin_auth ? "true" : "false"); dprintf(file, "%s=%u\n", CN_PASSIVE, gateway.passive); @@ -5128,7 +5121,7 @@ static bool get_seconds(const char* zName, const char* zValue, std::chrono::seco return valid; } -static bool get_seconds(const char* zName, const char* zValue, unsigned int* pSeconds) +static bool get_seconds(const char* zName, const char* zValue, time_t* pSeconds) { std::chrono::seconds seconds; diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 95167aa8e..3755b10f8 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -838,14 +838,14 @@ bool runtime_alter_maxscale(const char* name, const char* value) if (key == CN_AUTH_CONNECT_TIMEOUT) { - int intval = get_positive_int(value); - if (intval) + time_t timeout = get_positive_int(value); + if (timeout) { - MXS_NOTICE("Updated '%s' from %d to %d", + MXS_NOTICE("Updated '%s' from %ld to %ld", CN_AUTH_CONNECT_TIMEOUT, cnf.auth_conn_timeout, - intval); - cnf.auth_conn_timeout = intval; + timeout); + cnf.auth_conn_timeout = timeout; rval = true; } else @@ -855,14 +855,14 @@ bool runtime_alter_maxscale(const char* name, const char* value) } else if (key == CN_AUTH_READ_TIMEOUT) { - int intval = get_positive_int(value); - if (intval) + time_t timeout = get_positive_int(value); + if (timeout) { - MXS_NOTICE("Updated '%s' from %d to %d", + MXS_NOTICE("Updated '%s' from %ld to %ld", CN_AUTH_READ_TIMEOUT, cnf.auth_read_timeout, - intval); - cnf.auth_read_timeout = intval; + timeout); + cnf.auth_read_timeout = timeout; rval = true; } else @@ -872,14 +872,14 @@ bool runtime_alter_maxscale(const char* name, const char* value) } else if (key == CN_AUTH_WRITE_TIMEOUT) { - int intval = get_positive_int(value); - if (intval) + time_t timeout = get_positive_int(value); + if (timeout) { - MXS_NOTICE("Updated '%s' from %d to %d", + MXS_NOTICE("Updated '%s' from %ld to %ld", CN_AUTH_WRITE_TIMEOUT, cnf.auth_write_timeout, - intval); - cnf.auth_write_timeout = intval; + timeout); + cnf.auth_write_timeout = timeout; rval = true; } else