From 8e9b7fb26a307018063fbf261e5ee0ea9f2d3897 Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Tue, 22 Oct 2013 10:30:16 +0200 Subject: [PATCH] Added new entry point in router: errorReply The routine if called from backend will ido: 1 reply error messages to client closing or not the session 2 open a new backend connection An action flag is passed to the routine. --- server/include/router.h | 4 ++ server/modules/routing/debugcli.c | 1 + server/modules/routing/readconnroute.c | 39 ++++++++++++++++++- .../routing/readwritesplit/readwritesplit.c | 3 +- server/modules/routing/testroute.c | 1 + 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/server/include/router.h b/server/include/router.h index 208b2f5df..9c93f3271 100644 --- a/server/include/router.h +++ b/server/include/router.h @@ -29,6 +29,7 @@ * and the diagnostic entry point * 15/07/2013 Massimiliano Pinto Added clientReply entry point * 16/07/2013 Massimiliano Pinto Added router commands values + * 22/10/2013 Massimiliano Pinto Added router errorReply entry point * */ #include @@ -57,6 +58,8 @@ typedef void *ROUTER; * diagnostics Called to force the router to print * diagnostic output * clientReply Called to reply to client the data from one or all backends + * errorReply Called to reply to client errors with optional closeSession or + * make a request for a new backend connection * * @endverbatim * @@ -70,6 +73,7 @@ typedef struct router_object { int (*routeQuery)(ROUTER *instance, void *router_session, GWBUF *queue); void (*diagnostics)(ROUTER *instance, DCB *dcb); void (*clientReply)(ROUTER* instance, void* router_session, GWBUF* queue, DCB *backend_dcb); + void (*errorReply)(ROUTER* instance, void* router_session, char* message, DCB *backend_dcb, int action); } ROUTER_OBJECT; /* Router commands */ diff --git a/server/modules/routing/debugcli.c b/server/modules/routing/debugcli.c index 2b407b45c..c4dccb47d 100644 --- a/server/modules/routing/debugcli.c +++ b/server/modules/routing/debugcli.c @@ -61,6 +61,7 @@ static ROUTER_OBJECT MyObject = { freeSession, execute, diagnostics, + NULL, NULL }; diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index 2c262f2d4..137c8d50a 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -61,6 +61,8 @@ * 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return * 12/08/2013 Mark Riddoch Log unsupported router options * 04/09/2013 Massimiliano Pinto Added client NULL check in clientReply + * 22/10/2013 Massimiliano Pinto errorReply called from backend, for client error replyi + * or take different actions such as open a new backend connection * * @endverbatim */ @@ -96,6 +98,12 @@ static void clientReply( void *router_session, GWBUF *queue, DCB *backend_dcb); +static void errorReply( + ROUTER *instance, + void *router_session, + char *message, + DCB *backend_dcb, + int action); /** The module object definition */ static ROUTER_OBJECT MyObject = { @@ -105,7 +113,8 @@ static ROUTER_OBJECT MyObject = { freeSession, routeQuery, diagnostics, - clientReply + clientReply, + errorReply }; static SPINLOCK instlock; @@ -584,3 +593,31 @@ clientReply( client->func.write(client, queue); } +/** + * Error Reply routine + * + * The routine will reply to client errors and/or closing the session + * or try to open a new backend connection. + * + * @param instance The router instance + * @param router_session The router session + * @param message The error message to reply + * @param backend_dcb The backend DCB + * @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION + * + */ +static void +errorReply( + ROUTER *instance, + void *router_session, + char *message, + DCB *backend_dcb, + int action) +{ + DCB *client = NULL; + ROUTER_OBJECT *router = NULL; + SESSION *session = backend_dcb->session; + client = backend_dcb->session->client; + + ss_dassert(client != NULL); +} diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 53f398214..ee5993bac 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -77,7 +77,8 @@ static ROUTER_OBJECT MyObject = { freeSession, routeQuery, diagnostic, - clientReply + clientReply, + NULL }; static SPINLOCK instlock; diff --git a/server/modules/routing/testroute.c b/server/modules/routing/testroute.c index d31ccac92..2e1615f25 100644 --- a/server/modules/routing/testroute.c +++ b/server/modules/routing/testroute.c @@ -35,6 +35,7 @@ static ROUTER_OBJECT MyObject = { freeSession, routeQuery, diagnostic, + NULL, NULL };