Addition of server status flags
Addition of dcb role API
This commit is contained in:
12
core/dcb.c
12
core/dcb.c
@ -509,3 +509,15 @@ va_list args;
|
||||
buf->end = GWBUF_DATA(buf) + strlen(GWBUF_DATA(buf)) + 1;
|
||||
dcb->func.write(dcb, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the role that a DCB plays within a session.
|
||||
*
|
||||
* @param dcb
|
||||
* @return Non-zero if the DCB is the client of the session
|
||||
*/
|
||||
int
|
||||
dcb_isclient(DCB *dcb)
|
||||
{
|
||||
return (dcb->session && dcb == dcb->session->client);
|
||||
}
|
||||
|
@ -68,7 +68,8 @@ gateway.o: gateway.c ../include/gw.h /usr/include/stdio.h \
|
||||
../include/thread.h /usr/include/pthread.h /usr/include/sched.h \
|
||||
/usr/include/bits/sched.h /usr/include/bits/setjmp.h ../include/buffer.h \
|
||||
../include/mysql_protocol.h ../include/dcb.h ../include/service.h \
|
||||
../include/server.h ../include/session.h
|
||||
../include/server.h ../include/session.h ../include/modules.h \
|
||||
../include/poll.h
|
||||
gateway_mysql_protocol.o: gateway_mysql_protocol.c ../include/gw.h \
|
||||
/usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \
|
||||
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
|
||||
@ -350,9 +351,9 @@ server.o: server.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/bits/time.h /usr/include/sys/sysmacros.h \
|
||||
/usr/include/bits/pthreadtypes.h /usr/include/alloca.h \
|
||||
/usr/include/string.h /usr/include/xlocale.h ../include/session.h \
|
||||
../include/server.h ../include/spinlock.h ../include/thread.h \
|
||||
/usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \
|
||||
/usr/include/bits/setjmp.h ../include/dcb.h ../include/buffer.h
|
||||
../include/server.h ../include/dcb.h ../include/spinlock.h \
|
||||
../include/thread.h /usr/include/pthread.h /usr/include/sched.h \
|
||||
/usr/include/bits/sched.h /usr/include/bits/setjmp.h ../include/buffer.h
|
||||
poll.o: poll.c /usr/include/stdio.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
|
||||
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \
|
||||
|
@ -38,8 +38,8 @@
|
||||
#include <server.h>
|
||||
#include <dcb.h>
|
||||
#include <session.h>
|
||||
|
||||
void myfree(void** pp) { free(*pp); *pp = NULL; }
|
||||
#include <modules.h>
|
||||
#include <poll.h>
|
||||
|
||||
/* basic signal handling */
|
||||
static void sighup_handler (int i) {
|
||||
@ -167,7 +167,6 @@ main(int argc, char **argv)
|
||||
{
|
||||
int daemon_mode = 1;
|
||||
sigset_t sigset;
|
||||
int nfds;
|
||||
int n;
|
||||
unsigned short port = 4406;
|
||||
SERVICE *service1, *service2;
|
||||
@ -249,8 +248,6 @@ SERVER *server1, *server2, *server3;
|
||||
serviceStart(service1);
|
||||
serviceStart(service2);
|
||||
|
||||
fprintf(stderr, ">> GATEWAY poll maxevents is %i\n", MAX_EVENTS);
|
||||
|
||||
while (1)
|
||||
{
|
||||
poll();
|
||||
|
@ -59,6 +59,7 @@ SERVER *server;
|
||||
server->protocol = strdup(protocol);
|
||||
server->port = port;
|
||||
memset(&server->stats, sizeof(SERVER_STATS), 0);
|
||||
server->status = 0;
|
||||
server->nextdb = NULL;
|
||||
|
||||
spinlock_acquire(&server_spin);
|
||||
@ -165,3 +166,29 @@ SERVER *ptr;
|
||||
}
|
||||
spinlock_release(&server_spin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a set of server status flags to a string, the returned
|
||||
* string has been malloc'd and must be free'd by the caller
|
||||
*
|
||||
* @param SERVER The server to return the status of
|
||||
* @return A string representation of the status flags
|
||||
*/
|
||||
char *
|
||||
server_status(SERVER *server)
|
||||
{
|
||||
char *status = NULL;
|
||||
|
||||
if ((status = (char *)malloc(200)) == NULL)
|
||||
return NULL;
|
||||
status[0] = 0;
|
||||
if (server->status & SERVER_RUNNING)
|
||||
strcat(status, "Running, ");
|
||||
else
|
||||
strcat(status, "Down, ");
|
||||
if (server->status & SERVER_MASTER)
|
||||
strcat(status, "Master");
|
||||
else
|
||||
strcat(status, "Slave");
|
||||
return status;
|
||||
}
|
||||
|
@ -66,9 +66,16 @@ SESSION *session;
|
||||
session->state = SESSION_STATE_ALLOC;
|
||||
client->session = session;
|
||||
|
||||
// this will prevent the connect() backends via connect_dcb() for listening socket
|
||||
/*
|
||||
* Only create a router session if we are not the listening
|
||||
* DCB. Creating a router session may create a connection to a
|
||||
* backend server, depending upon the router module implementation
|
||||
* and should be avoided for the listener session
|
||||
*/
|
||||
if (client->state != DCB_STATE_LISTENING)
|
||||
{
|
||||
session->router_session = service->router->newSession(service->router_instance, session);
|
||||
}
|
||||
|
||||
spinlock_acquire(&session_spin);
|
||||
session->next = allSessions;
|
||||
|
@ -142,5 +142,6 @@ extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
|
||||
extern void dprintDCB(DCB *, DCB *); /* Debug to print a DCB in the system */
|
||||
extern const char *gw_dcb_state2string(int); /* DCB state to string */
|
||||
extern void dcb_printf(DCB *, const char *, ...); /* DCB version of printf */
|
||||
extern int dcb_isclient(DCB *);
|
||||
|
||||
#endif
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_EVENTS 1000000
|
||||
#define EXIT_FAILURE 1
|
||||
|
||||
// network buffer is 32K
|
||||
|
@ -29,6 +29,7 @@
|
||||
*
|
||||
* Date Who Description
|
||||
* 14/06/13 Mark Riddoch Initial implementation
|
||||
* 21/06/13 Mark Riddoch Addition of server status flags
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -51,14 +52,20 @@ typedef struct server {
|
||||
char *name; /**< Server name/IP address*/
|
||||
unsigned short port; /**< Port to listen on */
|
||||
char *protocol; /**< Protocol module to use */
|
||||
unsigned int status; /**< Status flag bitmap for the server */
|
||||
SERVER_STATS stats; /**< The server statistics */
|
||||
struct server *next; /**< Next server */
|
||||
struct server *nextdb; /**< Next server in lsit attached to a service */
|
||||
struct server *nextdb; /**< Next server in list attached to a service */
|
||||
} 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 */
|
||||
|
||||
|
||||
extern SERVER *server_alloc(char *, char *, unsigned short);
|
||||
extern int server_free(SERVER *);
|
||||
extern void printServer(SERVER *);
|
||||
extern void printAllServers();
|
||||
extern void dprintAllServers(DCB *);
|
||||
extern char *server_status(SERVER *);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user