Fixed missing subservices parameter in config.

This commit is contained in:
Markus Makela
2015-03-31 12:54:52 +03:00
parent 7c89f49f82
commit be968cfad2
2 changed files with 25 additions and 16 deletions

View File

@ -312,6 +312,7 @@ int error_count = 0;
char *strip_db_esc; char *strip_db_esc;
char *weightby; char *weightby;
char *version_string; char *version_string;
char *subservices;
bool is_rwsplit = false; bool is_rwsplit = false;
bool is_schemarouter = false; bool is_schemarouter = false;
char *allow_localhost_match_wildcard_host; char *allow_localhost_match_wildcard_host;
@ -319,6 +320,7 @@ int error_count = 0;
obj->element = service_alloc(obj->object, router); obj->element = service_alloc(obj->object, router);
user = config_get_value(obj->parameters, "user"); user = config_get_value(obj->parameters, "user");
auth = config_get_value(obj->parameters, "passwd"); auth = config_get_value(obj->parameters, "passwd");
subservices = config_get_value(obj->parameters, "subservices");
enable_root_user = config_get_value( enable_root_user = config_get_value(
obj->parameters, obj->parameters,
"enable_root_user"); "enable_root_user");
@ -346,6 +348,15 @@ int error_count = 0;
version_string = config_get_value(obj->parameters, version_string = config_get_value(obj->parameters,
"version_string"); "version_string");
if(subservices)
{
service_set_param_value(obj->element,
obj->parameters,
subservices,
1,STRING_TYPE);
}
/** flag for rwsplit-specific parameters */ /** flag for rwsplit-specific parameters */
if (strncmp(router, "readwritesplit", strlen("readwritesplit")+1) == 0) if (strncmp(router, "readwritesplit", strlen("readwritesplit")+1) == 0)
{ {

View File

@ -942,7 +942,7 @@ static ROUTER *
createInstance(SERVICE *service, char **options) createInstance(SERVICE *service, char **options)
{ {
ROUTER_INSTANCE* router; ROUTER_INSTANCE* router;
char *services, *tok; char *services, *tok, *saveptr;
SERVICE **res_svc, **temp; SERVICE **res_svc, **temp;
CONFIG_PARAMETER* conf; CONFIG_PARAMETER* conf;
int i = 0, sz; int i = 0, sz;
@ -957,7 +957,6 @@ createInstance(SERVICE *service, char **options)
spinlock_init(&router->lock); spinlock_init(&router->lock);
conf = config_get_param(service->svc_config_param, "subservices"); conf = config_get_param(service->svc_config_param, "subservices");
/*
if(conf == NULL) if(conf == NULL)
{ {
@ -968,22 +967,20 @@ createInstance(SERVICE *service, char **options)
} }
services = strdup(conf->value); services = strdup(conf->value);
*/
sz = 2; sz = 2;
res_svc = calloc(sz, sizeof(SERVICE*));
/*
tok = strtok(services, ",");
*/
if(options == NULL) if((res_svc = calloc(sz, sizeof(SERVICE*))) == NULL)
{ {
free(router); free(router);
skygw_log_write(LOGFILE_ERROR, "Error : No 'subservice' router option found. Shardrouter requires at least %d " skygw_log_write(LOGFILE_ERROR,"Error: Memory allocation failed.");
"configured services listed in the 'subservices' router option to work.", min_nsvc);
return NULL; return NULL;
} }
while(options[i]) tok = strtok_r(services, ",",&saveptr);
while(tok)
{ {
if(sz <= i) if(sz <= i)
{ {
@ -991,9 +988,9 @@ createInstance(SERVICE *service, char **options)
if(temp == NULL) if(temp == NULL)
{ {
skygw_log_write(LOGFILE_ERROR, "Error : Memory reallocation failed."); skygw_log_write(LOGFILE_ERROR, "Error : Memory reallocation failed.");
skygw_log_write(LOGFILE_DEBUG, "shardrouter.c: realloc returned NULL. " LOGIF(LD,(skygw_log_write(LOGFILE_DEBUG, "shardrouter.c: realloc returned NULL. "
"service count[%d] buffer size [%u] tried to allocate [%u]", "service count[%d] buffer size [%u] tried to allocate [%u]",
sz, sizeof(SERVICE*)*(sz), sizeof(SERVICE*)*(sz * 2)); sz, sizeof(SERVICE*)*(sz), sizeof(SERVICE*)*(sz * 2))));
free(res_svc); free(res_svc);
free(router); free(router);
return NULL; return NULL;
@ -1002,7 +999,7 @@ createInstance(SERVICE *service, char **options)
res_svc = temp; res_svc = temp;
} }
res_svc[i] = service_find(options[i]); res_svc[i] = service_find(tok);
if(res_svc[i] == NULL) if(res_svc[i] == NULL)
{ {
free(res_svc); free(res_svc);
@ -1011,10 +1008,11 @@ createInstance(SERVICE *service, char **options)
return NULL; return NULL;
} }
i++; i++;
tok = strtok_r(NULL,",",&saveptr);
} }
/*
free(services); free(services);
*/
router->services = res_svc; router->services = res_svc;
router->n_services = i; router->n_services = i;