From be968cfad2befc1324579d205bb6044d1438d33f Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 31 Mar 2015 12:54:52 +0300 Subject: [PATCH] Fixed missing subservices parameter in config. --- server/core/config.c | 11 +++++++ .../routing/schemarouter/shardrouter.c | 30 +++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/server/core/config.c b/server/core/config.c index cc50e1b99..58f5d92b3 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -312,6 +312,7 @@ int error_count = 0; char *strip_db_esc; char *weightby; char *version_string; + char *subservices; bool is_rwsplit = false; bool is_schemarouter = false; char *allow_localhost_match_wildcard_host; @@ -319,6 +320,7 @@ int error_count = 0; obj->element = service_alloc(obj->object, router); user = config_get_value(obj->parameters, "user"); auth = config_get_value(obj->parameters, "passwd"); + subservices = config_get_value(obj->parameters, "subservices"); enable_root_user = config_get_value( obj->parameters, "enable_root_user"); @@ -346,6 +348,15 @@ int error_count = 0; version_string = config_get_value(obj->parameters, "version_string"); + + if(subservices) + { + service_set_param_value(obj->element, + obj->parameters, + subservices, + 1,STRING_TYPE); + } + /** flag for rwsplit-specific parameters */ if (strncmp(router, "readwritesplit", strlen("readwritesplit")+1) == 0) { diff --git a/server/modules/routing/schemarouter/shardrouter.c b/server/modules/routing/schemarouter/shardrouter.c index 5d76ca9ad..03aa02a57 100644 --- a/server/modules/routing/schemarouter/shardrouter.c +++ b/server/modules/routing/schemarouter/shardrouter.c @@ -942,7 +942,7 @@ static ROUTER * createInstance(SERVICE *service, char **options) { ROUTER_INSTANCE* router; - char *services, *tok; + char *services, *tok, *saveptr; SERVICE **res_svc, **temp; CONFIG_PARAMETER* conf; int i = 0, sz; @@ -957,7 +957,6 @@ createInstance(SERVICE *service, char **options) spinlock_init(&router->lock); conf = config_get_param(service->svc_config_param, "subservices"); -/* if(conf == NULL) { @@ -968,22 +967,20 @@ createInstance(SERVICE *service, char **options) } services = strdup(conf->value); -*/ sz = 2; - res_svc = calloc(sz, sizeof(SERVICE*)); -/* - tok = strtok(services, ","); -*/ - if(options == NULL) + if((res_svc = calloc(sz, sizeof(SERVICE*))) == NULL) { free(router); - skygw_log_write(LOGFILE_ERROR, "Error : No 'subservice' router option found. Shardrouter requires at least %d " - "configured services listed in the 'subservices' router option to work.", min_nsvc); + skygw_log_write(LOGFILE_ERROR,"Error: Memory allocation failed."); return NULL; } - while(options[i]) + tok = strtok_r(services, ",",&saveptr); + + + + while(tok) { if(sz <= i) { @@ -991,9 +988,9 @@ createInstance(SERVICE *service, char **options) if(temp == NULL) { 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]", - sz, sizeof(SERVICE*)*(sz), sizeof(SERVICE*)*(sz * 2)); + sz, sizeof(SERVICE*)*(sz), sizeof(SERVICE*)*(sz * 2)))); free(res_svc); free(router); return NULL; @@ -1002,7 +999,7 @@ createInstance(SERVICE *service, char **options) res_svc = temp; } - res_svc[i] = service_find(options[i]); + res_svc[i] = service_find(tok); if(res_svc[i] == NULL) { free(res_svc); @@ -1011,10 +1008,11 @@ createInstance(SERVICE *service, char **options) return NULL; } i++; + tok = strtok_r(NULL,",",&saveptr); } -/* + free(services); -*/ + router->services = res_svc; router->n_services = i;