MXS-1929: Load global configuration as soon as possible

There exists a dependency on the configuration for the workers: the total
number of worker thread is defined by the `threads` parameter. This means
that the global configuration section must be read before workers are
started.

Commit 411b70e25656317909e54f748f8012593120041f broke MaxScale and turned
it into a single threaded application as the default configuration value
of one worker was used.
This commit is contained in:
Markus Mäkelä
2018-07-26 08:34:56 +03:00
parent 7e857e36eb
commit a833f39196
3 changed files with 49 additions and 24 deletions

View File

@ -570,6 +570,11 @@ static bool is_maxscale_section(const char* section)
static bool is_root_config_file = true; static bool is_root_config_file = true;
static int ini_global_handler(void *userdata, const char *section, const char *name, const char *value)
{
return is_maxscale_section(section) ? handle_global_item(name, value) : 1;
}
/** /**
* Config item handler for the ini file reader * Config item handler for the ini file reader
* *
@ -673,11 +678,7 @@ static int ini_handler(void *userdata, const char *section, const char *name, co
if (is_maxscale_section(section)) if (is_maxscale_section(section))
{ {
if (is_root_config_file || is_persisted_config) if (!is_root_config_file && !is_persisted_config)
{
return handle_global_item(name, value);
}
else
{ {
MXS_ERROR("The [maxscale] section must only be defined in the root configuration file."); MXS_ERROR("The [maxscale] section must only be defined in the root configuration file.");
return 0; return 0;
@ -687,6 +688,29 @@ static int ini_handler(void *userdata, const char *section, const char *name, co
return 1; return 1;
} }
static void log_config_error(const char* file, int rval)
{
char errorbuffer[1024 + 1];
if (rval > 0)
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Error on line %d.", file, rval);
}
else if (rval == -1)
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Could not open file.", file);
}
else
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Memory allocation failed.", file);
}
MXS_ERROR("%s", errorbuffer);
}
/** /**
* Load single configuration file. * Load single configuration file.
* *
@ -710,25 +734,7 @@ static bool config_load_single_file(const char* file,
{ {
if ((rval = ini_parse(file, ini_handler, ccontext)) != 0) if ((rval = ini_parse(file, ini_handler, ccontext)) != 0)
{ {
char errorbuffer[1024 + 1]; log_config_error(file, rval);
if (rval > 0)
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Error on line %d.", file, rval);
}
else if (rval == -1)
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Could not open file.", file);
}
else
{
snprintf(errorbuffer, sizeof(errorbuffer),
"Failed to parse configuration file %s. Memory allocation failed.", file);
}
MXS_ERROR("%s", errorbuffer);
} }
} }
@ -1075,6 +1081,18 @@ config_load_and_process(const char* filename, bool (*process_config)(CONFIG_CONT
return rval; return rval;
} }
bool config_load_global(const char *filename)
{
int rval;
if ((rval = ini_parse(filename, ini_global_handler, NULL)) != 0)
{
log_config_error(filename, rval);
}
return rval == 0;
}
/** /**
* @brief Load the configuration file for the MaxScale * @brief Load the configuration file for the MaxScale
* *

View File

@ -1890,6 +1890,12 @@ int main(int argc, char **argv)
} }
} }
if (!config_load_global(cnf_file_path))
{
rc = MAXSCALE_BADCONFIG;
goto return_main;
}
if (daemon_mode) if (daemon_mode)
{ {
if (!change_cwd()) if (!change_cwd())

View File

@ -75,6 +75,7 @@ void config_add_defaults(CONFIG_CONTEXT *ctx, const MXS_MODULE_PARAM *params);
char* config_clean_string_list(const char* str); char* config_clean_string_list(const char* str);
MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param); MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param);
bool config_load(const char *); bool config_load(const char *);
bool config_load_global(const char *filename);
void config_parameter_free(MXS_CONFIG_PARAMETER* p1); void config_parameter_free(MXS_CONFIG_PARAMETER* p1);
/** /**