Initialize router parameters in service_alloc

By moving the router parameter initialization into service_alloc, the
creation of a new service can be simplified to a single function call.
This commit is contained in:
Markus Mäkelä 2018-07-10 10:41:40 +03:00
parent 81527894ee
commit 71c736faec
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 23 additions and 23 deletions

View File

@ -3067,18 +3067,6 @@ int create_new_service(CONFIG_CONTEXT *obj)
}
service->session_track_trx_state = config_get_bool(obj->parameters, CN_SESSION_TRACK_TRX_STATE);
/** Store the configuration parameters for the service */
const MXS_MODULE *mod = get_module(router, MODULE_ROUTER);
if (mod)
{
config_add_defaults(obj, mod->parameters);
service_add_parameters(service, obj->parameters);
}
else
{
error_count++;
}
return error_count;
}

View File

@ -120,6 +120,17 @@ void service_update_weights();
*/
void service_add_parameters(SERVICE *service, const MXS_CONFIG_PARAMETER *param);
/**
* @brief Add parameters to a service
*
* A copy of @c param is added to @c service.
*
* @param service Service where the parameters are added
* @param key Parameter name
* @param value Parameter value
*/
void service_add_parameter(SERVICE *service, const char* key, const char* value);
/**
* @brief Remove service parameter
*

View File

@ -130,20 +130,21 @@ SERVICE* service_alloc(const char *name, const char *router)
service->log_auth_warnings = true;
service->strip_db_esc = true;
service->rate_limits = rate_limits;
if (service->name == NULL || service->routerModule == NULL)
{
if (service->name)
{
MXS_FREE(service->name);
}
MXS_FREE(service);
return NULL;
}
service->stats.started = time(0);
service->stats.n_failed_starts = 0;
service->state = SERVICE_STATE_ALLOC;
spinlock_init(&service->spin);
// Load router default parameters
for (int i = 0; module->parameters[i].name; i++)
{
if (module->parameters[i].default_value)
{
service_add_parameter(service, module->parameters[i].name,
module->parameters[i].default_value);
}
}
spinlock_acquire(&service_spin);
service->next = allServices;
allServices = service;
@ -1562,7 +1563,7 @@ void service_add_parameters(SERVICE *service, const MXS_CONFIG_PARAMETER *param)
}
}
void service_add_parameters(SERVICE *service, const char* key, const char* value)
void service_add_parameter(SERVICE *service, const char* key, const char* value)
{
MXS_CONFIG_PARAMETER p{const_cast<char*>(key), const_cast<char*>(value), nullptr};
service_add_parameters(service, &p);
@ -1615,7 +1616,7 @@ void service_replace_parameter(SERVICE *service, const char* key, const char* va
}
}
service_add_parameters(service, key, value);
service_add_parameter(service, key, value);
}
/**