Addition of server macros to determine server state

Addition of rule in readconnroute to take server state into account

Addition of "current connections" statistic in the server
This commit is contained in:
Mark Riddoch 2013-06-26 00:58:58 +02:00
parent 3338e9cdb0
commit c7a424cdab
5 changed files with 43 additions and 3 deletions

View File

@ -174,7 +174,8 @@ GWPROTOCOL *funcs;
dcb_free(dcb);
return NULL;
}
server->stats.n_connections++;
atomic_add(&server->stats.n_connections, 1);
atomic_add(&server->stats.n_current, 1);
poll_add_dcb(dcb);
/*

View File

@ -119,6 +119,8 @@ printServer(SERVER *server)
printf("\tServer: %s\n", server->name);
printf("\tProtocol: %s\n", server->protocol);
printf("\tPort: %d\n", server->port);
printf("\tTotal connections: %d\n", server->stats.n_connections);
printf("\tCurrent connections: %d\n", server->stats.n_current);
}
/**
@ -163,6 +165,7 @@ SERVER *ptr;
dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol);
dcb_printf(dcb, "\tPort: %d\n", ptr->port);
dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections);
dcb_printf(dcb, "\tCurrent no. of connections: %d\n", ptr->stats.n_current);
ptr = ptr->next;
}
spinlock_release(&server_spin);
@ -183,6 +186,7 @@ dprintServer(DCB *dcb, SERVER *server)
dcb_printf(dcb, "\tProtocol: %s\n", server->protocol);
dcb_printf(dcb, "\tPort: %d\n", server->port);
dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections);
dcb_printf(dcb, "\tCurrent No. of connections: %d\n", server->stats.n_current);
}
/**

View File

@ -40,6 +40,7 @@
*/
typedef struct {
int n_connections; /**< Number of connections */
int n_current; /**< Current connections */
} SERVER_STATS;
/**
@ -58,9 +59,37 @@ typedef struct server {
struct server *nextdb; /**< Next server in list attached to a service */
} SERVER;
/**
* Status bits in the server->status member.
*
* These are a bitmap of attributes that may be applied to a server
*/
#define SERVER_RUNNING 0x0001 /**<< The server is up and running */
#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */
/**
* Is the server running - the macro returns true if the server is marked as running
* regardless of it's state as a master or slave
*/
#define SERVER_IS_RUNNING(server) ((server)->status & SERVER_RUNNING)
/**
* Is the server marked as down - the macro returns true if the server is beleived
* to be inoperable.
*/
#define SERVER_IS_DOWN(server) (((server)->status & SERVER_RUNNING) == 0)
/**
* Is the server a master? The server must be both running and marked as master
* in order for the macro to return true
*/
#define SERVER_IS_MASTER(server) \
(((server)->status & (SERVER_RUNNING|SERVER_MASTER)) == (SERVER_RUNNING|SERVER_MASTER))
/**
* Is the server a slave? The server must be both running and marked as a slave
* in order for the macro to return true
*/
#define SERVER_IS_SLAVE(server) \
(((server)->status & (SERVER_RUNNING|SERVER_MASTER)) == SERVER_RUNNING)
extern SERVER *server_alloc(char *, char *, unsigned short);
extern int server_free(SERVER *);

View File

@ -154,6 +154,8 @@ CLI_SESSION *client;
client->next = inst->sessions;
inst->sessions = client;
spinlock_release(&inst->lock);
session->state = SESSION_STATE_READY;
return (void *)client;
}

View File

@ -193,8 +193,11 @@ int i;
candidate = inst->servers[0];
for (i = 1; inst->servers[i]; i++)
{
if (inst->servers[i] && inst->servers[i]->count < candidate->count)
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
&& inst->servers[i]->count < candidate->count)
{
candidate = inst->servers[i];
}
}
/*
@ -243,8 +246,9 @@ CLIENT_SESSION *session = (CLIENT_SESSION *)router_session;
* Close the connection to the backend
*/
session->dcb->func.close(session->dcb);
atomic_add(&session->backend->count, -1);
atomic_add(&session->backend->server->stats.n_current, -1);
spinlock_acquire(&inst->lock);
if (inst->connections == session)
inst->connections = session->next;