MXS-1661 Introduce 'users_refresh_time'

It is now possible to explicitly specify how frequently MaxScale
may refresh the users of a service.
This commit is contained in:
Johan Wikman
2018-02-09 11:40:17 +02:00
parent ae160f3ff2
commit b4760c5bbe
6 changed files with 80 additions and 6 deletions

View File

@ -1405,6 +1405,44 @@ handle_global_item(const char *name, const char *value)
{
gateway.local_address = MXS_STRDUP_A(value);
}
else if (strcmp(name, "users_refresh_time") == 0)
{
char* endptr;
long users_refresh_time = strtol(value, &endptr, 0);
if (*endptr == '\0')
{
if (users_refresh_time < 0)
{
MXS_NOTICE("Value of 'users_refresh_time' is less than 0, users will "
"not be automatically refreshed.");
// Strictly speaking they will be refreshed once every 68 years,
// but I just don't beleave the uptime will be that long.
users_refresh_time = INT32_MAX;
}
else if (users_refresh_time < USERS_REFRESH_TIME_MIN)
{
MXS_WARNING("%s is less than the allowed minimum value of %d for the "
"configuration option 'users_refresh_time', using the minimum value.",
value, USERS_REFRESH_TIME_MIN);
users_refresh_time = USERS_REFRESH_TIME_MIN;
}
if (users_refresh_time > INT32_MAX)
{
// To ensure that there will be no overflows when
// we later do arithmetic.
users_refresh_time = INT32_MAX;
}
gateway.users_refresh_time = users_refresh_time;
}
else
{
MXS_ERROR("%s is an invalid value for 'users_refresh_time', "
"using default %d instead.", value, USERS_REFRESH_TIME_DEFAULT);
gateway.users_refresh_time = USERS_REFRESH_TIME_DEFAULT;
}
}
else
{
for (i = 0; lognames[i].name; i++)

View File

@ -337,10 +337,19 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
/**
* At service start last update is set to USERS_REFRESH_TIME seconds earlier. This way MaxScale
* could try reloading users just after startup.
* could try reloading users just after startup. But only if user refreshing has not been turned off.
*/
service->rate_limit.last = time(NULL) - USERS_REFRESH_TIME;
service->rate_limit.warned = false;
MXS_CONFIG* config = config_get_global_options();
if (config->users_refresh_time == INT32_MAX)
{
service->rate_limit.last = time(NULL);
service->rate_limit.warned = true; // So that there will not be a refresh rate warning.
}
else
{
service->rate_limit.last = time(NULL) - config->users_refresh_time;
service->rate_limit.warned = false;
}
if (port->listener->func.listen(port->listener, config_bind))
{
@ -1612,13 +1621,16 @@ int service_refresh_users(SERVICE *service)
if (spinlock_acquire_nowait(&service->spin))
{
time_t now = time(NULL);
MXS_CONFIG* config = config_get_global_options();
/* Check if refresh rate limit has been exceeded */
if (now < service->rate_limit.last + USERS_REFRESH_TIME)
if (now < service->rate_limit.last + config->users_refresh_time)
{
if (!service->rate_limit.warned)
{
MXS_WARNING("[%s] Refresh rate limit exceeded for load of users' table.", service->name);
MXS_WARNING("[%s] Refresh rate limit (once every %ld seconds) exceeded for "
"load of users' table.",
service->name, config->users_refresh_time);
service->rate_limit.warned = true;
}
}