diff --git a/core/dcb.c b/core/dcb.c index 23208a045..85d538a3c 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -48,6 +48,7 @@ #include #include #include +#include static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */ static SPINLOCK *dcbspin = NULL; diff --git a/core/depend.mk b/core/depend.mk index 2bb4bd23a..f72230a07 100644 --- a/core/depend.mk +++ b/core/depend.mk @@ -262,7 +262,7 @@ dcb.o: dcb.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/arpa/inet.h \ /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdbool.h \ ../include/gateway_mysql.h ../include/mysql_protocol.h ../include/dcb.h \ - ../include/poll.h + ../include/poll.h ../include/atomic.h load_utils.o: load_utils.c /usr/include/sys/param.h \ /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/limits.h \ /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/syslimits.h \ diff --git a/core/poll.c b/core/poll.c index 77e04556c..0909a8788 100644 --- a/core/poll.c +++ b/core/poll.c @@ -145,6 +145,11 @@ int i, nfds; atomic_add(&pollStats.n_hup, 1); dcb->func.hangup(dcb); } + if (ev & EPOLLOUT) + { + atomic_add(&pollStats.n_write, 1); + dcb->func.write_ready(dcb); + } if (ev & EPOLLIN) { if (dcb->state == DCB_STATE_LISTENING) @@ -158,11 +163,6 @@ int i, nfds; dcb->func.read(dcb); } } - if (ev & EPOLLOUT) - { - atomic_add(&pollStats.n_write, 1); - dcb->func.write_ready(dcb); - } } } if (shutdown) diff --git a/core/server.c b/core/server.c index 35ad228db..18d725692 100644 --- a/core/server.c +++ b/core/server.c @@ -58,7 +58,7 @@ SERVER *server; server->name = strdup(servname); server->protocol = strdup(protocol); server->port = port; - memset(&server->stats, sizeof(SERVER_STATS), 0); + memset(&server->stats, 0, sizeof(SERVER_STATS)); server->status = SERVER_RUNNING; server->nextdb = NULL; diff --git a/core/service.c b/core/service.c index c56a0126c..93f9177df 100644 --- a/core/service.c +++ b/core/service.c @@ -67,7 +67,7 @@ SERVICE *service; } service->name = strdup(servname); service->routerModule = strdup(router); - memset(&service->stats, sizeof(SERVICE_STATS), 0); + memset(&service->stats, 0, sizeof(SERVICE_STATS)); service->ports = NULL; service->stats.started = time(0); service->state = SERVICE_STATE_ALLOC; @@ -75,6 +75,8 @@ SERVICE *service; service->credentials.authdata = NULL; service->users = users_alloc(); service->routerOptions = NULL; + service->databases = NULL; + spinlock_init(&service->spin); spinlock_acquire(&service_spin); service->next = allServices; diff --git a/core/session.c b/core/session.c index d0f84e22b..9a6bc796d 100644 --- a/core/session.c +++ b/core/session.c @@ -61,7 +61,7 @@ SESSION *session; return NULL; session->service = service; session->client = client; - memset(&session->stats, sizeof(SESSION_STATS), 0); + memset(&session->stats, 0, sizeof(SESSION_STATS)); session->stats.connect = time(0); session->state = SESSION_STATE_ALLOC; client->session = session; diff --git a/modules/include/readconnection.h b/modules/include/readconnection.h index f4bf48b3e..cfbdf0331 100644 --- a/modules/include/readconnection.h +++ b/modules/include/readconnection.h @@ -51,6 +51,15 @@ typedef struct client_session { *next; } CLIENT_SESSION; +/** + * The statistics for this router instance + */ +typedef struct { + int n_sessions; /**< Number sessions created */ + int n_queries; /**< Number of queries forwarded */ +} ROUTER_STATS; + + /** * The per instance data for the router. */ @@ -61,6 +70,7 @@ typedef struct instance { BACKEND **servers; /**< The set of backend servers for this instance */ unsigned int bitmask; /**< Bitmask to apply to server->status */ unsigned int bitvalue; /**< Required value of server->status */ + ROUTER_STATS stats; /**< Statistics for this router */ struct instance *next; } INSTANCE; #endif diff --git a/modules/protocol/mysql_client.c b/modules/protocol/mysql_client.c index 6387c66e2..6de84b617 100644 --- a/modules/protocol/mysql_client.c +++ b/modules/protocol/mysql_client.c @@ -773,6 +773,7 @@ int gw_read_client_event(DCB* dcb) { ROUTER *router_instance = NULL; void *rsession = NULL; MySQLProtocol *protocol = NULL; + //uint8_t buffer[MAX_BUFFER_SIZE] = ""; int b = -1; if (dcb) { @@ -997,7 +998,7 @@ int gw_MySQLListener(DCB *listener, char *config_bind) { char *p; char address[1024]=""; int port=0; - int one; + int one = 1; // this gateway, as default, will bind on port 4404 for localhost only (config_bind != NULL) ? (bind_address_and_port = config_bind) : (bind_address_and_port = "127.0.0.1:4406"); diff --git a/modules/routing/readconnroute.c b/modules/routing/readconnroute.c index 9b05ad2e5..86f35ef76 100644 --- a/modules/routing/readconnroute.c +++ b/modules/routing/readconnroute.c @@ -134,6 +134,8 @@ int i, n; if ((inst = malloc(sizeof(INSTANCE))) == NULL) return NULL; + memset(&inst->stats, 0, sizeof(ROUTER_STATS)); + inst->service = service; spinlock_init(&inst->lock); inst->connections = NULL; @@ -291,6 +293,8 @@ int i; return NULL; } + inst->stats.n_sessions++; + /* Add this session to the list of active sessions */ spinlock_acquire(&inst->lock); client->next = inst->connections; @@ -353,8 +357,10 @@ CLIENT_SESSION *session = (CLIENT_SESSION *)router_session; static int routeQuery(ROUTER *instance, void *router_session, GWBUF *queue) { +INSTANCE *inst = (INSTANCE *)instance; CLIENT_SESSION *session = (CLIENT_SESSION *)router_session; + inst->stats.n_queries++; return session->dcb->func.write(session->dcb, queue); } @@ -380,5 +386,7 @@ int i = 0; } spinlock_release(&inst->lock); - dcb_printf(dcb, "Number of router sessions: %d\n", i); + dcb_printf(dcb, "\tNumber of router sessions: %d\n", inst->stats.n_sessions); + dcb_printf(dcb, "\tCurrent no. of router sessions: %d\n", i); + dcb_printf(dcb, "\tNumber of queries forwarded: %d\n", inst->stats.n_queries); } diff --git a/modules/routing/testroute.c b/modules/routing/testroute.c index 6fbd0e06b..80cd92178 100644 --- a/modules/routing/testroute.c +++ b/modules/routing/testroute.c @@ -20,12 +20,13 @@ static char *version_str = "V1.0.0"; -static ROUTER *createInstance(SERVICE *service); +static ROUTER *createInstance(SERVICE *service, char **options); static void *newSession(ROUTER *instance, SESSION *session); static void closeSession(ROUTER *instance, void *session); static int routeQuery(ROUTER *instance, void *session, GWBUF *queue); +static void diagnostic(ROUTER *instance, DCB *dcb); -static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery }; +static ROUTER_OBJECT MyObject = { createInstance, newSession, closeSession, routeQuery, diagnostic }; /** * Implementation of the mandatory version entry point @@ -72,7 +73,7 @@ GetModuleObject() * @return The instance data for this new instance */ static ROUTER * -createInstance(SERVICE *service) +createInstance(SERVICE *service, char **options) { return NULL; } @@ -108,3 +109,14 @@ routeQuery(ROUTER *instance, void *session, GWBUF *queue) { return 0; } + +/** + * Diagnostics routine + * + * @param instance The router instance + * @param dcb The DCB for diagnostic output + */ +static void +diagnostic(ROUTER *instance, DCB *dcb) +{ +}