Addition of the structure for the read write query splitter routing module. This is
in a seperate directory to the others as it is likely to be a complex routing module.
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
# Revision History
|
# Revision History
|
||||||
# Date Who Description
|
# Date Who Description
|
||||||
# 13/06/13 Mark Riddoch Initial routing module development
|
# 13/06/13 Mark Riddoch Initial routing module development
|
||||||
|
# 27/06/13 Mark Riddoch Addition of read write splitter
|
||||||
|
|
||||||
CC=cc
|
CC=cc
|
||||||
CFLAGS=-c -fPIC -I/usr/include -I../include -I../../include -Wall -g
|
CFLAGS=-c -fPIC -I/usr/include -I../include -I../../include -Wall -g
|
||||||
@ -30,7 +31,8 @@ DEBUGCLIOBJ=$(DEBUGCLISRCS:.c=.o)
|
|||||||
SRCS=$(TESTSRCS) $(READCONSRCS) $(DEBUGCLISRCS)
|
SRCS=$(TESTSRCS) $(READCONSRCS) $(DEBUGCLISRCS)
|
||||||
OBJ=$(SRCS:.c=.o)
|
OBJ=$(SRCS:.c=.o)
|
||||||
LIBS=-lssl
|
LIBS=-lssl
|
||||||
MODULES=libtestroute.so libreadconnroute.so libdebugcli.so
|
MODULES=libtestroute.so libreadconnroute.so libdebugcli.so \
|
||||||
|
libreadwritesplit.so
|
||||||
|
|
||||||
all: $(MODULES)
|
all: $(MODULES)
|
||||||
|
|
||||||
@ -43,18 +45,24 @@ libreadconnroute.so: $(READCONOBJ)
|
|||||||
libdebugcli.so: $(DEBUGCLIOBJ)
|
libdebugcli.so: $(DEBUGCLIOBJ)
|
||||||
$(CC) $(LDFLAGS) $(DEBUGCLIOBJ) $(LIBS) -o $@
|
$(CC) $(LDFLAGS) $(DEBUGCLIOBJ) $(LIBS) -o $@
|
||||||
|
|
||||||
|
libreadwritesplit.so:
|
||||||
|
(cd readwritesplit; make; cp $@ ..)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) $< -o $@
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) $(MODULES)
|
rm -f $(OBJ) $(MODULES)
|
||||||
|
(cd readwritesplit; make clean)
|
||||||
|
|
||||||
tags:
|
tags:
|
||||||
ctags $(SRCS) $(HDRS)
|
ctags $(SRCS) $(HDRS)
|
||||||
|
(cd readwritesplit; make tags)
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
@rm -f depend.mk
|
@rm -f depend.mk
|
||||||
cc -M $(CFLAGS) $(SRCS) > depend.mk
|
cc -M $(CFLAGS) $(SRCS) > depend.mk
|
||||||
|
(cd readwritesplit; make depend)
|
||||||
|
|
||||||
install: $(MODULES)
|
install: $(MODULES)
|
||||||
install -D $< $(DEST)/gateway/modules
|
install -D $< $(DEST)/gateway/modules
|
||||||
|
50
modules/routing/readwritesplit/Makefile
Normal file
50
modules/routing/readwritesplit/Makefile
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
# software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License as published by the Free Software Foundation,
|
||||||
|
# version 2.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Copyright SkySQL Ab 2013
|
||||||
|
#
|
||||||
|
# Revision History
|
||||||
|
# Date Who Description
|
||||||
|
# 27/06/13 Mark Riddoch Initial framework put in place
|
||||||
|
|
||||||
|
CC=cc
|
||||||
|
CFLAGS=-c -fPIC -I/usr/include -I../../include -I../../../include -Wall -g
|
||||||
|
LDFLAGS=-shared
|
||||||
|
SRCS=router.c
|
||||||
|
OBJ=$(SRCS:.c=.o)
|
||||||
|
LIBS=-lssl
|
||||||
|
MODULES=libreadwritesplit.so
|
||||||
|
|
||||||
|
all: $(MODULES)
|
||||||
|
|
||||||
|
libreadwritesplit.so: $(OBJ)
|
||||||
|
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ) $(MODULES)
|
||||||
|
|
||||||
|
tags:
|
||||||
|
ctags $(SRCS) $(HDRS)
|
||||||
|
|
||||||
|
depend:
|
||||||
|
@rm -f depend.mk
|
||||||
|
cc -M $(CFLAGS) $(SRCS) > depend.mk
|
||||||
|
|
||||||
|
install: $(MODULES)
|
||||||
|
install -D $< $(DEST)/gateway/modules
|
||||||
|
|
||||||
|
include depend.mk
|
0
modules/routing/readwritesplit/depend.mk
Normal file
0
modules/routing/readwritesplit/depend.mk
Normal file
160
modules/routing/readwritesplit/router.c
Normal file
160
modules/routing/readwritesplit/router.c
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of the SkySQL Gateway. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2013
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <router.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file router.c The entry points for the read/write query splitting
|
||||||
|
* router module.
|
||||||
|
*
|
||||||
|
* This file contains the entry points that comprise the API to the read write
|
||||||
|
* query splitting router.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static char *version_str = "V1.0.0";
|
||||||
|
|
||||||
|
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, diagnostic };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the mandatory version entry point
|
||||||
|
*
|
||||||
|
* @return version string of the module
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
version()
|
||||||
|
{
|
||||||
|
return version_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module initialisation routine, called when the module
|
||||||
|
* is first loaded.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ModuleInit()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Initialse read/writer splitting query router module.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module entry point routine. It is this routine that
|
||||||
|
* must populate the structure that is referred to as the
|
||||||
|
* "module object", this is a structure with the set of
|
||||||
|
* external entry points for this module.
|
||||||
|
*
|
||||||
|
* @return The module object
|
||||||
|
*/
|
||||||
|
ROUTER_OBJECT *
|
||||||
|
GetModuleObject()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Returing test router module object.\n");
|
||||||
|
return &MyObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of the router for a particular service
|
||||||
|
* within the gateway.
|
||||||
|
*
|
||||||
|
* The job of ths entry point is to create the service wide data needed
|
||||||
|
* for the query router. This is information needed to route queries that
|
||||||
|
* is not related to any individual client session, exmaples of data that
|
||||||
|
* might be stored in the ROUTER object for a particular query router are
|
||||||
|
* connections counts, last used connection etc so that balancing may
|
||||||
|
* take place.
|
||||||
|
*
|
||||||
|
* @param service The service this router is being create for
|
||||||
|
* @param options The options for this query router
|
||||||
|
*
|
||||||
|
* @return The instance data for this new instance
|
||||||
|
*/
|
||||||
|
static ROUTER *
|
||||||
|
createInstance(SERVICE *service, char **options)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associate a new session with this instance of the router.
|
||||||
|
*
|
||||||
|
* The session is used to store all the data required for a particular
|
||||||
|
* client connection.
|
||||||
|
*
|
||||||
|
* @param instance The router instance data
|
||||||
|
* @param session The session itself
|
||||||
|
* @return Session specific data for this session
|
||||||
|
*/
|
||||||
|
static void *
|
||||||
|
newSession(ROUTER *instance, SESSION *session)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a session with the router, this is the mechanism
|
||||||
|
* by which a router may cleanup data structure etc.
|
||||||
|
*
|
||||||
|
* @param instance The router instance data
|
||||||
|
* @param session The session being closed
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
closeSession(ROUTER *instance, void *session)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main routing entry, this is called with every packet that is
|
||||||
|
* received and has to be forwarded to the backend database.
|
||||||
|
*
|
||||||
|
* The routeQuery will make the routing decision based on the contents
|
||||||
|
* of the instance, session and the query itself in the queue. The
|
||||||
|
* data in the queue may not represent a complete query, it represents
|
||||||
|
* the data that has been received. The query router itself is responsible
|
||||||
|
* for buffering the partial query, a later call to the query router will
|
||||||
|
* contain the remainder, or part thereof of the query.
|
||||||
|
*
|
||||||
|
* @param instance The query router instance
|
||||||
|
* @param session The session assoicated with the client
|
||||||
|
* @param queue Gateway buffer queue with the packets received
|
||||||
|
*
|
||||||
|
* @return The number of queries forwarded
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
routeQuery(ROUTER *instance, void *session, GWBUF *queue)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnostics routine
|
||||||
|
*
|
||||||
|
* Print query router statistics to the DCB passed in
|
||||||
|
*
|
||||||
|
* @param instance The router instance
|
||||||
|
* @param dcb The DCB for diagnostic output
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
diagnostic(ROUTER *instance, DCB *dcb)
|
||||||
|
{
|
||||||
|
}
|
Reference in New Issue
Block a user