Conflicts:
	gcov.diff
	server/core/buffer.c
	server/include/buffer.h
	server/modules/routing/readwritesplit/readwritesplit.c
This commit is contained in:
VilhoRaatikka
2014-08-29 18:50:32 +03:00
44 changed files with 3446 additions and 323 deletions

View File

@ -32,8 +32,9 @@
# are behind SS_DEBUG macros.
# 29/06/13 Vilho Raatikka Reverted Query classifier changes because
# gateway needs mysql client lib, not qc.
# 24/07/13 Mark Ridoch Addition of encryption routines
# 30/05/14 Mark Ridoch Filter API added
# 24/07/13 Mark Riddoch Addition of encryption routines
# 30/05/14 Mark Riddoch Filter API added
# 25/07/14 Mark Riddoch Addition of hints
include ../../build_gateway.inc
@ -57,7 +58,7 @@ LDFLAGS=-rdynamic -L$(LOGPATH) \
SRCS= atomic.c buffer.c spinlock.c gateway.c \
gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c \
poll.c config.c users.c hashtable.c dbusers.c thread.c gwbitmask.c \
monitor.c adminusers.c secrets.c filter.c modutil.c
monitor.c adminusers.c secrets.c filter.c modutil.c hint.c
HDRS= ../include/atomic.h ../include/buffer.h ../include/dcb.h \
../include/gw.h ../modules/include/mysql_client_server_protocol.h \
@ -65,7 +66,7 @@ HDRS= ../include/atomic.h ../include/buffer.h ../include/dcb.h \
../include/modules.h ../include/poll.h ../include/config.h \
../include/users.h ../include/hashtable.h ../include/gwbitmask.h \
../include/adminusers.h ../include/version.h ../include/maxscale.h \
../include/filter.h modutil.h
../include/filter.h modutil.h hint.h
OBJ=$(SRCS:.c=.o)

View File

@ -32,6 +32,7 @@
* 11/07/13 Mark Riddoch Add reference count mechanism
* 16/07/2013 Massimiliano Pinto Added command type to gwbuf struct
* 24/06/2014 Mark Riddoch Addition of gwbuf_trim
* 15/07/2014 Mark Riddoch Addition of properties
*
* @endverbatim
*/
@ -88,6 +89,8 @@ SHARED_BUF *sbuf;
sbuf->refcount = 1;
rval->sbuf = sbuf;
rval->next = NULL;
rval->hint = NULL;
rval->properties = NULL;
rval->gwbuf_type = GWBUF_TYPE_UNDEFINED;
rval->gwbuf_info = GWBUF_INFO_NONE;
rval->gwbuf_bufobj = NULL;
@ -103,6 +106,8 @@ SHARED_BUF *sbuf;
void
gwbuf_free(GWBUF *buf)
{
BUF_PROPERTY *prop;
buffer_object_t* bo;
CHK_GWBUF(buf);
@ -110,12 +115,28 @@ gwbuf_free(GWBUF *buf)
{
free(buf->sbuf->data);
free(buf->sbuf);
bo = buf->gwbuf_bufobj;
bo = buf->gwbuf_bufobj;
while (bo != NULL)
{
bo = gwbuf_remove_buffer_object(buf, bo);
}
}
while (buf->properties)
{
prop = buf->properties;
buf->properties = prop->next;
free(prop->name);
free(prop->value);
free(prop);
}
/** Release the hint */
while (buf->hint)
{
HINT* h = buf->hint;
buf->hint = buf->hint->next;
hint_free(h);
}
free(buf);
}
@ -145,6 +166,8 @@ GWBUF *rval;
rval->start = buf->start;
rval->end = buf->end;
rval->gwbuf_type = buf->gwbuf_type;
rval->properties = NULL;
rval->hint = NULL;
rval->gwbuf_info = buf->gwbuf_info;
rval->gwbuf_bufobj = buf->gwbuf_bufobj;
rval->next = NULL;
@ -173,6 +196,8 @@ GWBUF *gwbuf_clone_portion(
clonebuf->start = (void *)((char*)buf->start)+start_offset;
clonebuf->end = (void *)((char *)clonebuf->start)+length;
clonebuf->gwbuf_type = buf->gwbuf_type; /*< clone the type for now */
clonebuf->properties = NULL;
clonebuf->hint = NULL;
clonebuf->gwbuf_info = buf->gwbuf_info;
clonebuf->gwbuf_bufobj = buf->gwbuf_bufobj;
clonebuf->next = NULL;
@ -424,20 +449,125 @@ void* gwbuf_get_buffer_object_data(
return bo->bo_data;
}
/**
* @return pointer to next buffer object or NULL
*/
static buffer_object_t* gwbuf_remove_buffer_object(
GWBUF* buf,
buffer_object_t* bufobj)
GWBUF* buf,
buffer_object_t* bufobj)
{
buffer_object_t* next;
next = bufobj->bo_next;
/** Call corresponding clean-up function to clean buffer object's data */
bufobj->bo_donefun_fp(bufobj->bo_data);
free(bufobj);
return next;
buffer_object_t* next;
next = bufobj->bo_next;
/** Call corresponding clean-up function to clean buffer object's data */
bufobj->bo_donefun_fp(bufobj->bo_data);
free(bufobj);
return next;
}
/**
* Add a property to a buffer.
*
* @param buf The buffer to add the property to
* @param name The property name
* @param value The property value
* @return Non-zero on success
*/
int
gwbuf_add_property(GWBUF *buf, char *name, char *value)
{
BUF_PROPERTY *prop;
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
return 0;
prop->name = strdup(name);
prop->value = strdup(value);
spinlock_acquire(&buf->gwbuf_lock);
prop->next = buf->properties;
buf->properties = prop;
spinlock_release(&buf->gwbuf_lock);
return 1;
}
/**
* Return the value of a buffer property
* @param buf The buffer itself
* @param name The name of the property to return
* @return The property value or NULL if the property was not found.
*/
char *
gwbuf_get_property(GWBUF *buf, char *name)
{
BUF_PROPERTY *prop;
spinlock_acquire(&buf->gwbuf_lock);
prop = buf->properties;
while (prop && strcmp(prop->name, name) != 0)
prop = prop->next;
spinlock_release(&buf->gwbuf_lock);
if (prop)
return prop->value;
return NULL;
}
/**
* Convert a chain of GWBUF structures into a single GWBUF structure
*
* @param orig The chain to convert
* @return The contiguous buffer
*/
GWBUF *
gwbuf_make_contiguous(GWBUF *orig)
{
GWBUF *newbuf;
char *ptr;
int len;
if (orig->next == NULL)
return orig;
if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL)
{
ptr = GWBUF_DATA(newbuf);
while (orig)
{
len = GWBUF_LENGTH(orig);
memcpy(ptr, GWBUF_DATA(orig), len);
ptr += len;
orig = gwbuf_consume(orig, len);
}
}
return newbuf;
}
/**
* Add hint to a buffer.
*
* @param buf The buffer to add the hint to
* @param hint The hint itself
* @return Non-zero on success
*/
int
gwbuf_add_hint(GWBUF *buf, HINT *hint)
{
HINT *ptr;
spinlock_acquire(&buf->gwbuf_lock);
if (buf->hint)
{
ptr = buf->hint;
while (ptr->next)
ptr = ptr->next;
ptr->next = hint;
}
else
{
buf->hint = hint;
}
spinlock_release(&buf->gwbuf_lock);
return 1;
}

153
server/core/hint.c Normal file
View File

@ -0,0 +1,153 @@
/*
* This file is distributed as part of MaxScale. 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 2014
*/
#include <stdio.h>
#include <stdlib.h>
#include <hint.h>
/**
* @file hint.c generic support routines for hints.
*
* @verbatim
* Revision History
*
* Date Who Description
* 25/07/14 Mark Riddoch Initial implementation
*
* @endverbatim
*/
/**
* Duplicate a list of hints
*
* @param hint The hint list to duplicate
* @return A duplicate of the list
*/
HINT *
hint_dup(HINT *hint)
{
HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2;
ptr1 = hint;
while (ptr1)
{
if ((ptr2 = (HINT *)malloc(sizeof(HINT))) == NULL)
return nlhead;
ptr2->type = ptr1->type;
if (ptr1->data)
ptr2->data = strdup(ptr1->data);
else
ptr2->data = NULL;
if (ptr1->value)
ptr2->value = strdup(ptr1->value);
else
ptr2->value = NULL;
ptr2->next = NULL;
if (nltail)
{
nltail->next = ptr2;
nltail = ptr2;
}
else
{
nlhead = ptr2;
nltail = ptr2;
}
ptr1 = ptr1->next;
}
return nlhead;
}
/**
* Create a ROUTE TO type hint
*
* @param head The current hint list
* @param type The HINT_TYPE
* @param data Data may be NULL or the name of a server to route to
* @return The result hint list
*/
HINT *
hint_create_route(HINT *head, HINT_TYPE type, char *data)
{
HINT *hint;
if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL)
return head;
hint->next = head;
hint->type = type;
if (data)
hint->data = strdup(data);
else
hint->data = NULL;
hint->value = NULL;
return hint;
}
/**
* Create name/value parameter hint
*
* @param head The current hint list
* @param pname The parameter name
* @param value The parameter value
* @return The result hint list
*/
HINT *
hint_create_parameter(HINT *head, char *pname, char *value)
{
HINT *hint;
if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL)
return head;
hint->next = head;
hint->type = HINT_PARAMETER;
hint->data = pname;
hint->value = strdup(value);
return hint;
}
/**
* free_hint - free a hint
*
* @param hint The hint to free
*/
void
hint_free(HINT *hint)
{
if (hint->data)
free(hint->data);
if (hint->value)
free(hint->value);
free(hint);
}
bool hint_exists(
HINT** p_hint,
HINT_TYPE type)
{
bool succp = false;
while (*p_hint != NULL)
{
if ((*p_hint)->type == type)
{
succp = true;
}
p_hint = &(*p_hint)->next;
}
return succp;
}

View File

@ -79,7 +79,7 @@ unsigned char *ptr;
*length += (*ptr++ << 8);
ptr += 2; // Skip sequence id and COM_QUERY byte
*length = *length - 1;
*sql = (char *) ptr;
*sql = (char *)ptr;
return 1;
}

View File

@ -416,6 +416,8 @@ char *status = NULL;
strcat(status, "Slave, ");
if (server->status & SERVER_JOINED)
strcat(status, "Synced, ");
if (server->status & SERVER_NDB)
strcat(status, "NDB, ");
if (server->status & SERVER_RUNNING)
strcat(status, "Running");
else

View File

@ -62,4 +62,4 @@ runtests: $(TESTS)
@echo "-------------------------------" >> $(TESTLOG)
$(foreach var,$(TESTS),./runtest.sh $(var) $(TESTLOG);)
@echo "" >> $(TESTLOG)
@cat $(TESTLOG) >> $(TEST_MAXSCALE_LOG)
@cat $(TESTLOG) >> $(TEST_MAXSCALE_LOG)