Formatted readconnroute
Formatted readconnroute files according to the style guide.
This commit is contained in:
@ -37,7 +37,8 @@
|
||||
* connections to. This provides the storage for routing module specific data
|
||||
* that is required for each of the backend servers.
|
||||
*/
|
||||
typedef struct backend {
|
||||
typedef struct backend
|
||||
{
|
||||
SERVER *server; /*< The server itself */
|
||||
int current_connection_count; /*< Number of connections to the server */
|
||||
int weight; /*< Desired routing weight */
|
||||
@ -46,7 +47,8 @@ typedef struct backend {
|
||||
/**
|
||||
* The client session structure used within this router.
|
||||
*/
|
||||
typedef struct router_client_session {
|
||||
typedef struct router_client_session
|
||||
{
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_chk_top;
|
||||
#endif
|
||||
@ -65,16 +67,17 @@ typedef struct router_client_session {
|
||||
/**
|
||||
* The statistics for this router instance
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int n_sessions; /*< Number sessions created */
|
||||
int n_queries; /*< Number of queries forwarded */
|
||||
} ROUTER_STATS;
|
||||
|
||||
|
||||
/**
|
||||
* The per instance data for the router.
|
||||
*/
|
||||
typedef struct router_instance {
|
||||
typedef struct router_instance
|
||||
{
|
||||
SERVICE *service; /*< Pointer to the service using this router */
|
||||
ROUTER_CLIENT_SES *connections; /*< Link list of all the client connections */
|
||||
SPINLOCK lock; /*< Spinlock for the instance data */
|
||||
|
||||
@ -96,7 +96,8 @@
|
||||
|
||||
#include "modutil.h"
|
||||
|
||||
MODULE_INFO info = {
|
||||
MODULE_INFO info =
|
||||
{
|
||||
MODULE_API_ROUTER,
|
||||
MODULE_GA,
|
||||
ROUTER_VERSION,
|
||||
@ -112,23 +113,16 @@ static void closeSession(ROUTER *instance, void *router_session);
|
||||
static void freeSession(ROUTER *instance, void *router_session);
|
||||
static int routeQuery(ROUTER *instance, void *router_session, GWBUF *queue);
|
||||
static void diagnostics(ROUTER *instance, DCB *dcb);
|
||||
static void clientReply(
|
||||
ROUTER *instance,
|
||||
void *router_session,
|
||||
GWBUF *queue,
|
||||
static void clientReply(ROUTER *instance, void *router_session, GWBUF *queue,
|
||||
DCB *backend_dcb);
|
||||
static void handleError(
|
||||
ROUTER *instance,
|
||||
void *router_session,
|
||||
GWBUF *errbuf,
|
||||
DCB *problem_dcb,
|
||||
error_action_t action,
|
||||
bool *succp);
|
||||
static void handleError(ROUTER *instance, void *router_session, GWBUF *errbuf,
|
||||
DCB *problem_dcb, error_action_t action, bool *succp);
|
||||
static int getCapabilities();
|
||||
|
||||
|
||||
/** The module object definition */
|
||||
static ROUTER_OBJECT MyObject = {
|
||||
static ROUTER_OBJECT MyObject =
|
||||
{
|
||||
createInstance,
|
||||
newSession,
|
||||
closeSession,
|
||||
@ -140,16 +134,12 @@ static ROUTER_OBJECT MyObject = {
|
||||
getCapabilities
|
||||
};
|
||||
|
||||
static bool rses_begin_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses);
|
||||
static bool rses_begin_locked_router_action(ROUTER_CLIENT_SES* rses);
|
||||
|
||||
static void rses_end_locked_router_action(
|
||||
ROUTER_CLIENT_SES* rses);
|
||||
static void rses_end_locked_router_action(ROUTER_CLIENT_SES* rses);
|
||||
|
||||
static BACKEND *get_root_master(
|
||||
BACKEND **servers);
|
||||
static int handle_state_switch(
|
||||
DCB* dcb,DCB_REASON reason, void * routersession);
|
||||
static BACKEND *get_root_master(BACKEND **servers);
|
||||
static int handle_state_switch(DCB* dcb, DCB_REASON reason, void * routersession);
|
||||
static SPINLOCK instlock;
|
||||
static ROUTER_INSTANCE *instances;
|
||||
|
||||
@ -209,7 +199,8 @@ int i, n;
|
||||
BACKEND *backend;
|
||||
char *weightby;
|
||||
|
||||
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
|
||||
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -236,7 +227,9 @@ char *weightby;
|
||||
if ((inst->servers[n] = malloc(sizeof(BACKEND))) == NULL)
|
||||
{
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
free(inst->servers[i]);
|
||||
}
|
||||
free(inst->servers);
|
||||
free(inst);
|
||||
return NULL;
|
||||
@ -402,7 +395,8 @@ BACKEND *master_host = NULL;
|
||||
|
||||
client_rses = (ROUTER_CLIENT_SES *) calloc(1, sizeof(ROUTER_CLIENT_SES));
|
||||
|
||||
if (client_rses == NULL) {
|
||||
if (client_rses == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -434,8 +428,10 @@ BACKEND *master_host = NULL;
|
||||
* become the new candidate. This has the effect of spreading the
|
||||
* connections over different servers during periods of very low load.
|
||||
*/
|
||||
for (i = 0; inst->servers[i]; i++) {
|
||||
if(inst->servers[i]) {
|
||||
for (i = 0; inst->servers[i]; i++)
|
||||
{
|
||||
if (inst->servers[i])
|
||||
{
|
||||
MXS_DEBUG("%lu [newSession] Examine server in port %d with "
|
||||
"%d connections. Status is %s, "
|
||||
"inst->bitvalue is %d",
|
||||
@ -447,18 +443,24 @@ BACKEND *master_host = NULL;
|
||||
}
|
||||
|
||||
if (SERVER_IN_MAINT(inst->servers[i]->server))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inst->servers[i]->weight == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check server status bits against bitvalue from router_options */
|
||||
if (inst->servers[i] &&
|
||||
SERVER_IS_RUNNING(inst->servers[i]->server) &&
|
||||
(inst->servers[i]->server->status & inst->bitmask & inst->bitvalue))
|
||||
{
|
||||
if (master_host) {
|
||||
if (inst->servers[i] == master_host && (inst->bitvalue & SERVER_SLAVE)) {
|
||||
if (master_host)
|
||||
{
|
||||
if (inst->servers[i] == master_host && (inst->bitvalue & SERVER_SLAVE))
|
||||
{
|
||||
/* skip root Master here, as it could also be slave of an external server
|
||||
* that is not in the configuration.
|
||||
* Intermediate masters (Relay Servers) are also slave and will be selected
|
||||
@ -467,7 +469,8 @@ BACKEND *master_host = NULL;
|
||||
|
||||
continue;
|
||||
}
|
||||
if (inst->servers[i] == master_host && (inst->bitvalue & SERVER_MASTER)) {
|
||||
if (inst->servers[i] == master_host && (inst->bitvalue & SERVER_MASTER))
|
||||
{
|
||||
/* If option is "master" return only the root Master as there
|
||||
* could be intermediate masters (Relay Servers)
|
||||
* and they must not be selected.
|
||||
@ -476,12 +479,15 @@ BACKEND *master_host = NULL;
|
||||
candidate = master_host;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* master_host is NULL, no master server.
|
||||
* If requested router_option is 'master'
|
||||
* candidate wll be NULL.
|
||||
*/
|
||||
if (inst->bitvalue & SERVER_MASTER) {
|
||||
if (inst->bitvalue & SERVER_MASTER)
|
||||
{
|
||||
candidate = NULL;
|
||||
break;
|
||||
}
|
||||
@ -522,10 +528,14 @@ BACKEND *master_host = NULL;
|
||||
* With router_option=slave a master_host could be set, so route traffic there.
|
||||
* Otherwise, just clean up and return NULL
|
||||
*/
|
||||
if (!candidate) {
|
||||
if (master_host) {
|
||||
if (!candidate)
|
||||
{
|
||||
if (master_host)
|
||||
{
|
||||
candidate = master_host;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to create new routing session. "
|
||||
"Couldn't find eligible candidate server. Freeing "
|
||||
"allocated resources.");
|
||||
@ -582,6 +592,7 @@ BACKEND *master_host = NULL;
|
||||
"Connections : %d",
|
||||
candidate->server->unique_name,
|
||||
candidate->current_connection_count);
|
||||
|
||||
return(void *) client_rses;
|
||||
}
|
||||
|
||||
@ -602,8 +613,7 @@ BACKEND *master_host = NULL;
|
||||
* @details (write detailed description here)
|
||||
*
|
||||
*/
|
||||
static void freeSession(
|
||||
ROUTER* router_instance,
|
||||
static void freeSession(ROUTER* router_instance,
|
||||
void* router_client_ses)
|
||||
{
|
||||
ROUTER_INSTANCE* router = (ROUTER_INSTANCE *) router_instance;
|
||||
@ -616,16 +626,21 @@ static void freeSession(
|
||||
|
||||
spinlock_acquire(&router->lock);
|
||||
|
||||
if (router->connections == router_cli_ses) {
|
||||
if (router->connections == router_cli_ses)
|
||||
{
|
||||
router->connections = router_cli_ses->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ROUTER_CLIENT_SES *ptr = router->connections;
|
||||
|
||||
while (ptr != NULL && ptr->next != router_cli_ses) {
|
||||
while (ptr != NULL && ptr->next != router_cli_ses)
|
||||
{
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
if (ptr != NULL) {
|
||||
if (ptr != NULL)
|
||||
{
|
||||
ptr->next = router_cli_ses->next;
|
||||
}
|
||||
}
|
||||
@ -642,7 +657,6 @@ static void freeSession(
|
||||
free(router_cli_ses);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close a session with the router, this is the mechanism
|
||||
* by which a router may cleanup data structure etc.
|
||||
@ -673,7 +687,8 @@ DCB* backend_dcb;
|
||||
/**
|
||||
* Close the backend server connection
|
||||
*/
|
||||
if (backend_dcb != NULL) {
|
||||
if (backend_dcb != NULL)
|
||||
{
|
||||
CHK_DCB(backend_dcb);
|
||||
dcb_close(backend_dcb);
|
||||
}
|
||||
@ -738,12 +753,10 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
||||
|
||||
char* trc = NULL;
|
||||
|
||||
switch(mysql_command) {
|
||||
switch (mysql_command)
|
||||
{
|
||||
case MYSQL_COM_CHANGE_USER:
|
||||
rc = backend_dcb->func.auth(
|
||||
backend_dcb,
|
||||
NULL,
|
||||
backend_dcb->session,
|
||||
rc = backend_dcb->func.auth(backend_dcb, NULL, backend_dcb->session,
|
||||
queue);
|
||||
break;
|
||||
case MYSQL_COM_QUERY:
|
||||
@ -762,7 +775,9 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
||||
trc ? ": " : ".",
|
||||
trc ? trc : "");
|
||||
free(trc);
|
||||
|
||||
return_rc:
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -904,6 +919,7 @@ static void handleError(
|
||||
}
|
||||
|
||||
/** to be inline'd */
|
||||
|
||||
/**
|
||||
* @node Acquires lock to router client session if it is not closed.
|
||||
*
|
||||
@ -926,11 +942,13 @@ static bool rses_begin_locked_router_action(
|
||||
|
||||
CHK_CLIENT_RSES(rses);
|
||||
|
||||
if (rses->rses_closed) {
|
||||
if (rses->rses_closed)
|
||||
{
|
||||
goto return_succp;
|
||||
}
|
||||
spinlock_acquire(&rses->rses_lock);
|
||||
if (rses->rses_closed) {
|
||||
if (rses->rses_closed)
|
||||
{
|
||||
spinlock_release(&rses->rses_lock);
|
||||
goto return_succp;
|
||||
}
|
||||
@ -941,6 +959,7 @@ return_succp:
|
||||
}
|
||||
|
||||
/** to be inline'd */
|
||||
|
||||
/**
|
||||
* @node Releases router client session lock.
|
||||
*
|
||||
@ -961,7 +980,6 @@ static void rses_end_locked_router_action(
|
||||
spinlock_release(&rses->rses_lock);
|
||||
}
|
||||
|
||||
|
||||
static int getCapabilities()
|
||||
{
|
||||
return RCAP_TYPE_PACKET_INPUT;
|
||||
@ -980,18 +998,22 @@ static int getCapabilities()
|
||||
*
|
||||
*/
|
||||
|
||||
static BACKEND *get_root_master(BACKEND **servers) {
|
||||
static BACKEND *get_root_master(BACKEND **servers)
|
||||
{
|
||||
int i = 0;
|
||||
BACKEND *master_host = NULL;
|
||||
|
||||
for (i = 0; servers[i]; i++) {
|
||||
if (servers[i] && (servers[i]->server->status & (SERVER_MASTER|SERVER_MAINT)) == SERVER_MASTER) {
|
||||
if (master_host && servers[i]->server->depth < master_host->server->depth) {
|
||||
master_host = servers[i];
|
||||
} else {
|
||||
if (master_host == NULL) {
|
||||
for (i = 0; servers[i]; i++)
|
||||
{
|
||||
if (servers[i] && (servers[i]->server->status & (SERVER_MASTER | SERVER_MAINT)) == SERVER_MASTER)
|
||||
{
|
||||
if (master_host && servers[i]->server->depth < master_host->server->depth)
|
||||
{
|
||||
master_host = servers[i];
|
||||
}
|
||||
else if (master_host == NULL)
|
||||
{
|
||||
master_host = servers[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user