From 561952e1ea429f41353809537c33c6c813d37f66 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 26 Feb 2015 15:49:43 +0200 Subject: [PATCH] Moved service definition to router_options for shardrouter. --- .../routers/schemarouter/SchemaRouter.md | 2 -- .../routing/schemarouter/shardrouter.c | 32 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Documentation/routers/schemarouter/SchemaRouter.md b/Documentation/routers/schemarouter/SchemaRouter.md index 3ab31e8b2..2c8239f3a 100644 --- a/Documentation/routers/schemarouter/SchemaRouter.md +++ b/Documentation/routers/schemarouter/SchemaRouter.md @@ -39,8 +39,6 @@ The schemarouter router currently has some limitations due to the nature of the - SELECT queries that modify session variables are not currently supported because uniform results can not be guaranteed. If such a query is executed, the behavior of the router is undefined. To work around this limitation the query must be executed in separate parts. -- Currently the schemarouter router does not support connecting directly to a sharded database. - - Queries targeting databases not mapped by the schemarouter router but still exist on the database server are not blocked but routed to the first available server. This possibly returns an error about database rights instead of a missing database. The behavior of the router is undefined in this case. ## Examples diff --git a/server/modules/routing/schemarouter/shardrouter.c b/server/modules/routing/schemarouter/shardrouter.c index d94e44121..3dbadcf0b 100644 --- a/server/modules/routing/schemarouter/shardrouter.c +++ b/server/modules/routing/schemarouter/shardrouter.c @@ -84,7 +84,7 @@ static FILTER_OBJECT dummyObject = { dummySetUpstream, NULL, filterReply, - dummyDiagnostic, + dummyDiagnostic }; static ROUTER* createInstance(SERVICE *service, char **options); @@ -119,7 +119,7 @@ static route_target_t get_shard_route_target( static uint8_t getCapabilities(ROUTER* inst, void* router_session); -bool parse_db_ignore_list(ROUTER_INSTANCE* router, char* param); +//bool parse_db_ignore_list(ROUTER_INSTANCE* router, char* param); static void subsvc_clear_state(SUBSERVICE* svc,subsvc_state_t state); static void subsvc_set_state(SUBSERVICE* svc,subsvc_state_t state); static bool get_shard_subsvc(SUBSERVICE** subsvc,ROUTER_CLIENT_SES* session,char* target); @@ -258,6 +258,14 @@ hashcmpfun( return strcmp(i1, i2); } +/** + * Handle the result returned from a SHOW DATABASES query. Parse the result set + * and associate these databases to the service that returned them. + * @param rses + * @param target + * @param buf + * @return + */ bool parse_mapping_response(ROUTER_CLIENT_SES* rses, char* target, GWBUF* buf) { @@ -289,6 +297,12 @@ parse_mapping_response(ROUTER_CLIENT_SES* rses, char* target, GWBUF* buf) return rval; } +/** + * Validate the status of the subservice. + * @param sub Subservice to validate + * @return True if the subservice is valid, false if the session or it's router + * are NULL or the session or the service is not in a valid state. + */ bool subsvc_is_valid(SUBSERVICE* sub) { @@ -760,6 +774,7 @@ createInstance(SERVICE *service, char **options) spinlock_init(&router->lock); conf = config_get_param(service->svc_config_param, "subservices"); +/* if(conf == NULL) { @@ -770,11 +785,14 @@ createInstance(SERVICE *service, char **options) } services = strdup(conf->value); +*/ sz = 2; res_svc = calloc(sz, sizeof(SERVICE*)); +/* tok = strtok(services, ","); +*/ - while(tok) + while(options[i]) { if(sz <= i) { @@ -793,12 +811,12 @@ createInstance(SERVICE *service, char **options) res_svc = temp; } - res_svc[i] = service_find(tok); - tok = strtok(NULL,","); + res_svc[i] = service_find(options[i]); i++; } - +/* free(services); +*/ router->services = res_svc; router->n_services = i; @@ -2740,6 +2758,8 @@ static SUBSERVICE* get_subsvc_from_ses(ROUTER_CLIENT_SES* rses, SESSION* ses) /** * Calls hang-up function for DCB if it is not both running and in * master/slave/joined/ndb role. Called by DCB's callback routine. + * + * TODO: See if there's a way to inject this into the subservices */ static int router_handle_state_switch(