Compile readwritesplit as C++
Compiling readwritesplit as C++ allows the use of C++ containers.
This commit is contained in:
@ -40,6 +40,7 @@
|
||||
#include <maxscale/utils.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql_com.h>
|
||||
#include <mysqld_error.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
add_library(readwritesplit SHARED readwritesplit.c rwsplit_mysql.c rwsplit_route_stmt.c rwsplit_select_backends.c rwsplit_session_cmd.c rwsplit_tmp_table_multi.c)
|
||||
add_library(readwritesplit SHARED readwritesplit.cc rwsplit_mysql.cc rwsplit_route_stmt.cc rwsplit_select_backends.cc rwsplit_session_cmd.cc rwsplit_tmp_table_multi.cc)
|
||||
target_link_libraries(readwritesplit maxscale-common MySQLCommon)
|
||||
set_target_properties(readwritesplit PROPERTIES VERSION "1.0.2")
|
||||
install_module(readwritesplit core)
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
@ -21,7 +21,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <maxscale/router.h>
|
||||
#include "rwsplit_internal.h"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
@ -32,34 +32,13 @@
|
||||
#include <maxscale/alloc.h>
|
||||
|
||||
/**
|
||||
* @file readwritesplit.c The entry points for the read/write query splitting
|
||||
* router module.
|
||||
* 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. It also contains functions that are directly called
|
||||
* by the entry point functions. Some of these are used by functions in other
|
||||
* modules of the read write split router, others are used only within this
|
||||
* module.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 01/07/2013 Vilho Raatikka Initial implementation
|
||||
* 15/07/2013 Massimiliano Pinto Added clientReply from master only in case
|
||||
* of session change
|
||||
* 17/07/2013 Massimiliano Pinto clientReply is now used by mysql_backend
|
||||
* for all reply situations
|
||||
* 18/07/2013 Massimiliano Pinto routeQuery now handles COM_QUIT
|
||||
* as QUERY_TYPE_SESSION_WRITE
|
||||
* 17/07/2014 Massimiliano Pinto Server connection counter is updated in
|
||||
* closeSession
|
||||
* 09/09/2015 Martin Brampton Modify error handler
|
||||
* 25/09/2015 Martin Brampton Block callback processing when no router
|
||||
* session in the DCB
|
||||
* 03/08/2016 Martin Brampton Extract the API functions, move the rest
|
||||
*
|
||||
* @endverbatim
|
||||
* This file contains the entry points that comprise the API to the read
|
||||
* write query splitting router. It also contains functions that are
|
||||
* directly called by the entry point functions. Some of these are used by
|
||||
* functions in other modules of the read write split router, others are
|
||||
* used only within this module.
|
||||
*/
|
||||
|
||||
/** Maximum number of slaves */
|
||||
@ -134,6 +113,8 @@ static const MXS_ENUM_VALUE master_failure_mode_values[] =
|
||||
{NULL}
|
||||
};
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* The module entry point routine. It is this routine that
|
||||
* must return the structure that is referred to as the
|
||||
@ -208,6 +189,8 @@ MXS_MODULE *MXS_CREATE_MODULE()
|
||||
return &info;
|
||||
}
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
// TODO: Don't process parameters in readwritesplit
|
||||
static bool handle_max_slaves(ROUTER_INSTANCE *router, const char *str)
|
||||
{
|
||||
@ -250,7 +233,7 @@ static MXS_ROUTER *createInstance(SERVICE *service, char **options)
|
||||
{
|
||||
ROUTER_INSTANCE *router;
|
||||
|
||||
if ((router = MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL)
|
||||
if ((router = (ROUTER_INSTANCE*)MXS_CALLOC(1, sizeof(ROUTER_INSTANCE))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -267,13 +250,13 @@ static MXS_ROUTER *createInstance(SERVICE *service, char **options)
|
||||
|
||||
MXS_CONFIG_PARAMETER *params = service->svc_config_param;
|
||||
|
||||
router->rwsplit_config.use_sql_variables_in = config_get_enum(params, "use_sql_variables_in",
|
||||
router->rwsplit_config.use_sql_variables_in = (mxs_target_t)config_get_enum(params, "use_sql_variables_in",
|
||||
use_sql_variables_in_values);
|
||||
|
||||
router->rwsplit_config.slave_selection_criteria = config_get_enum(params, "slave_selection_criteria",
|
||||
router->rwsplit_config.slave_selection_criteria = (select_criteria_t)config_get_enum(params, "slave_selection_criteria",
|
||||
slave_selection_criteria_values);
|
||||
|
||||
router->rwsplit_config.master_failure_mode = config_get_enum(params, "master_failure_mode",
|
||||
router->rwsplit_config.master_failure_mode = (enum failure_mode)config_get_enum(params, "master_failure_mode",
|
||||
master_failure_mode_values);
|
||||
|
||||
router->rwsplit_config.max_slave_replication_lag = config_get_integer(params, "max_slave_replication_lag");
|
||||
@ -396,7 +379,7 @@ static MXS_ROUTER_SESSION *newSession(MXS_ROUTER *router_inst, MXS_SESSION *sess
|
||||
|
||||
router->stats.n_sessions += 1;
|
||||
|
||||
return (void *)client_rses;
|
||||
return (MXS_ROUTER_SESSION*)client_rses;
|
||||
}
|
||||
|
||||
/**
|
@ -16,13 +16,6 @@
|
||||
|
||||
/**
|
||||
* @file router.h - The read write split router module heder file
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* See GitHub https://github.com/mariadb-corporation/MaxScale
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#define MXS_MODULE_NAME "readwritesplit"
|
||||
@ -279,7 +272,7 @@ typedef struct backend_ref_st
|
||||
#endif
|
||||
SERVER_REF* ref;
|
||||
DCB* bref_dcb;
|
||||
bref_state_t bref_state;
|
||||
int bref_state;
|
||||
int bref_num_result_wait;
|
||||
sescmd_cursor_t bref_sescmd_cur;
|
||||
unsigned char reply_cmd; /**< The reply the backend server sent to a session command.
|
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#ifndef _RWSPLIT_INTERNAL_H
|
||||
#define _RWSPLIT_INTERNAL_H
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
@ -14,18 +12,9 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: rwsplit_internal.h
|
||||
* Author: mbrampton
|
||||
*
|
||||
* Created on 08 August 2016, 11:54
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
/* This needs to be removed along with dependency on it - see the
|
||||
* rwsplit_tmp_table_multi functions
|
||||
*/
|
||||
@ -52,9 +41,9 @@ void check_session_command_reply(GWBUF *writebuf, sescmd_cursor_t *scur, backend
|
||||
bool execute_sescmd_in_backend(backend_ref_t *backend_ref);
|
||||
bool handle_target_is_all(route_target_t route_target,
|
||||
ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
GWBUF *querybuf, int packet_type, qc_query_type_t qtype);
|
||||
int determine_packet_type(GWBUF *querybuf, bool *non_empty_packet);
|
||||
void log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t qtype);
|
||||
GWBUF *querybuf, int packet_type, uint32_t qtype);
|
||||
uint8_t determine_packet_type(GWBUF *querybuf, bool *non_empty_packet);
|
||||
void log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, uint32_t qtype);
|
||||
bool is_packet_a_one_way_message(int packet_type);
|
||||
sescmd_cursor_t *backend_ref_get_sescmd_cursor(backend_ref_t *bref);
|
||||
bool is_packet_a_query(int packet_type);
|
||||
@ -84,11 +73,11 @@ void rwsplit_hfree(void *fval);
|
||||
bool rwsplit_get_dcb(DCB **p_dcb, ROUTER_CLIENT_SES *rses, backend_type_t btype,
|
||||
char *name, int max_rlag);
|
||||
route_target_t get_route_target(ROUTER_CLIENT_SES *rses,
|
||||
qc_query_type_t qtype, HINT *hint);
|
||||
uint32_t qtype, HINT *hint);
|
||||
rses_property_t *rses_property_init(rses_property_type_t prop_type);
|
||||
int rses_property_add(ROUTER_CLIENT_SES *rses, rses_property_t *prop);
|
||||
void handle_multi_temp_and_load(ROUTER_CLIENT_SES *rses, GWBUF *querybuf,
|
||||
int packet_type, int *qtype);
|
||||
uint8_t packet_type, uint32_t *qtype);
|
||||
bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf,
|
||||
route_target_t route_target, DCB **target_dcb);
|
||||
bool handle_slave_is_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
@ -100,7 +89,7 @@ bool handle_got_target(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf, ROUTER_INSTANCE *inst,
|
||||
int packet_type,
|
||||
qc_query_type_t qtype);
|
||||
uint32_t qtype);
|
||||
|
||||
/*
|
||||
* The following are implemented in rwsplit_session_cmd.c
|
||||
@ -138,21 +127,12 @@ bool select_connect_backend_servers(backend_ref_t **p_master_ref,
|
||||
*/
|
||||
void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf,
|
||||
mysql_server_cmd_t packet_type);
|
||||
uint32_t packet_type);
|
||||
bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf,
|
||||
qc_query_type_t type);
|
||||
uint32_t type);
|
||||
void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf, qc_query_type_t type);
|
||||
bool check_for_multi_stmt(GWBUF *buf, void *protocol, mysql_server_cmd_t packet_type);
|
||||
qc_query_type_t determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet);
|
||||
GWBUF *querybuf, uint32_t type);
|
||||
bool check_for_multi_stmt(GWBUF *buf, void *protocol, uint8_t packet_type);
|
||||
uint32_t determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet);
|
||||
void close_failed_bref(backend_ref_t *bref, bool fatal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
#endif /* RWSPLIT_INTERNAL_H */
|
||||
|
@ -11,18 +11,15 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <maxscale/router.h>
|
||||
#include "rwsplit_internal.h"
|
||||
|
||||
#include <mysql.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
#include <maxscale/dcb.h>
|
||||
@ -30,7 +27,6 @@
|
||||
#include <maxscale/modinfo.h>
|
||||
#include <maxscale/modutil.h>
|
||||
#include <maxscale/protocol/mysql.h>
|
||||
#include <mysqld_error.h>
|
||||
#include <maxscale/alloc.h>
|
||||
|
||||
#if defined(SS_DEBUG)
|
||||
@ -40,22 +36,14 @@
|
||||
#define RWSPLIT_TRACE_MSG_LEN 1000
|
||||
|
||||
/**
|
||||
* @file rwsplit_mysql.c Functions within the read-write split router that
|
||||
* are specific to MySQL. The aim is to either remove these into a separate
|
||||
* module or to move them into the MySQL protocol modules.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 08/08/2016 Martin Brampton Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
* Functions within the read-write split router that are specific to
|
||||
* MySQL. The aim is to either remove these into a separate module or to
|
||||
* move them into the MySQL protocol modules.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following functions are called from elsewhere in the router and
|
||||
* are defined in rwsplit_internal.h. They are not intended to be called
|
||||
* are defined in rwsplit_internal.hh. They are not intended to be called
|
||||
* from outside this router.
|
||||
*/
|
||||
|
||||
@ -80,24 +68,24 @@
|
||||
* @param non_empty_packet bool indicating whether the packet is non-empty
|
||||
* @return The packet type, or MYSQL_COM_UNDEFINED; also the second parameter is set
|
||||
*/
|
||||
int
|
||||
uint8_t
|
||||
determine_packet_type(GWBUF *querybuf, bool *non_empty_packet)
|
||||
{
|
||||
mysql_server_cmd_t packet_type;
|
||||
uint8_t packet_type;
|
||||
uint8_t *packet = GWBUF_DATA(querybuf);
|
||||
|
||||
if (gw_mysql_get_byte3(packet) == 0)
|
||||
{
|
||||
/** Empty packet signals end of LOAD DATA LOCAL INFILE, send it to master*/
|
||||
*non_empty_packet = false;
|
||||
packet_type = MYSQL_COM_UNDEFINED;
|
||||
packet_type = (uint8_t)MYSQL_COM_UNDEFINED;
|
||||
}
|
||||
else
|
||||
{
|
||||
*non_empty_packet = true;
|
||||
packet_type = packet[4];
|
||||
}
|
||||
return (int)packet_type;
|
||||
return packet_type;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -157,7 +145,7 @@ is_packet_a_one_way_message(int packet_type)
|
||||
* @param qtype Query type
|
||||
*/
|
||||
void
|
||||
log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t qtype)
|
||||
log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, uint32_t qtype)
|
||||
{
|
||||
if (rses->load_data_state == LOAD_DATA_INACTIVE)
|
||||
{
|
||||
@ -219,7 +207,7 @@ log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t
|
||||
*/
|
||||
bool handle_target_is_all(route_target_t route_target, ROUTER_INSTANCE *inst,
|
||||
ROUTER_CLIENT_SES *rses, GWBUF *querybuf,
|
||||
int packet_type, qc_query_type_t qtype)
|
||||
int packet_type, uint32_t qtype)
|
||||
{
|
||||
bool result = false;
|
||||
|
@ -11,41 +11,62 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/router.h>
|
||||
#include <maxscale/modutil.h>
|
||||
|
||||
#include "rwsplit_internal.h"
|
||||
|
||||
/**
|
||||
* @file rwsplit_route_stmt.c The functions that support the routing of
|
||||
* queries to back end servers. All the functions in this module are internal
|
||||
* to the read write split router, and not intended to be called from
|
||||
* anywhere else.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 08/08/2016 Martin Brampton Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
* The functions that support the routing of queries to back end
|
||||
* servers. All the functions in this module are internal to the read
|
||||
* write split router, and not intended to be called from anywhere else.
|
||||
*/
|
||||
|
||||
extern int (*criteria_cmpfun[LAST_CRITERIA])(const void *, const void *);
|
||||
|
||||
static backend_ref_t *check_candidate_bref(backend_ref_t *cand,
|
||||
backend_ref_t *new,
|
||||
select_criteria_t sc);
|
||||
static backend_ref_t *get_root_master_bref(ROUTER_CLIENT_SES *rses);
|
||||
|
||||
/**
|
||||
* Find out which of the two backend servers has smaller value for select
|
||||
* criteria property.
|
||||
*
|
||||
* @param cand previously selected candidate
|
||||
* @param new challenger
|
||||
* @param sc select criteria
|
||||
*
|
||||
* @return pointer to backend reference of that backend server which has smaller
|
||||
* value in selection criteria. If either reference pointer is NULL then the
|
||||
* other reference pointer value is returned.
|
||||
*/
|
||||
static backend_ref_t *check_candidate_bref(backend_ref_t *cand,
|
||||
backend_ref_t *new_bref,
|
||||
select_criteria_t sc)
|
||||
{
|
||||
int (*p)(const void *, const void *);
|
||||
/** get compare function */
|
||||
p = criteria_cmpfun[sc];
|
||||
|
||||
if (new_bref == NULL)
|
||||
{
|
||||
return cand;
|
||||
}
|
||||
else if (cand == NULL || (p((void *)cand, (void *)new_bref) > 0))
|
||||
{
|
||||
return new_bref;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cand;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_connection_keepalive(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
DCB *target_dcb)
|
||||
{
|
||||
@ -88,8 +109,8 @@ void handle_connection_keepalive(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
GWBUF *querybuf)
|
||||
{
|
||||
qc_query_type_t qtype = QUERY_TYPE_UNKNOWN;
|
||||
int packet_type;
|
||||
uint32_t qtype = QUERY_TYPE_UNKNOWN;
|
||||
uint8_t packet_type;
|
||||
DCB *target_dcb = NULL;
|
||||
route_target_t route_target;
|
||||
bool succp = false;
|
||||
@ -103,7 +124,7 @@ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
|
||||
if (non_empty_packet)
|
||||
{
|
||||
handle_multi_temp_and_load(rses, querybuf, packet_type, (int *)&qtype);
|
||||
handle_multi_temp_and_load(rses, querybuf, packet_type, &qtype);
|
||||
|
||||
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
|
||||
{
|
||||
@ -211,7 +232,7 @@ bool route_single_stmt(ROUTER_INSTANCE *inst, ROUTER_CLIENT_SES *rses,
|
||||
bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf, ROUTER_INSTANCE *inst,
|
||||
int packet_type,
|
||||
qc_query_type_t qtype)
|
||||
uint32_t qtype)
|
||||
{
|
||||
bool succp;
|
||||
rses_property_t *prop;
|
||||
@ -717,12 +738,12 @@ return_succp:
|
||||
* if the query would otherwise be routed to slave.
|
||||
*/
|
||||
route_target_t get_route_target(ROUTER_CLIENT_SES *rses,
|
||||
qc_query_type_t qtype, HINT *hint)
|
||||
uint32_t qtype, HINT *hint)
|
||||
{
|
||||
bool trx_active = session_trx_is_active(rses->client_dcb->session);
|
||||
bool load_active = rses->load_data_state != LOAD_DATA_INACTIVE;
|
||||
mxs_target_t use_sql_variables_in = rses->rses_config.use_sql_variables_in;
|
||||
route_target_t target = TARGET_UNDEFINED;
|
||||
int target = TARGET_UNDEFINED;
|
||||
|
||||
if (rses->forced_node && rses->forced_node == rses->rses_master_ref)
|
||||
{
|
||||
@ -898,7 +919,7 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses,
|
||||
hint = hint->next;
|
||||
} /*< while (hint != NULL) */
|
||||
|
||||
return target;
|
||||
return (route_target_t)target;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -913,7 +934,7 @@ route_target_t get_route_target(ROUTER_CLIENT_SES *rses,
|
||||
*/
|
||||
void
|
||||
handle_multi_temp_and_load(ROUTER_CLIENT_SES *rses, GWBUF *querybuf,
|
||||
int packet_type, int *qtype)
|
||||
uint8_t packet_type, uint32_t *qtype)
|
||||
{
|
||||
/** Check for multi-statement queries. If no master server is available
|
||||
* and a multi-statement is issued, an error is returned to the client
|
||||
@ -1028,7 +1049,7 @@ bool handle_hinted_target(ROUTER_CLIENT_SES *rses, GWBUF *querybuf,
|
||||
* Set the name of searched
|
||||
* backend server.
|
||||
*/
|
||||
named_server = hint->data;
|
||||
named_server = (char*)hint->data;
|
||||
MXS_INFO("Hint: route to server '%s'", named_server);
|
||||
}
|
||||
else if (hint->type == HINT_PARAMETER &&
|
||||
@ -1412,40 +1433,6 @@ int rses_property_add(ROUTER_CLIENT_SES *rses, rses_property_t *prop)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out which of the two backend servers has smaller value for select
|
||||
* criteria property.
|
||||
*
|
||||
* @param cand previously selected candidate
|
||||
* @param new challenger
|
||||
* @param sc select criteria
|
||||
*
|
||||
* @return pointer to backend reference of that backend server which has smaller
|
||||
* value in selection criteria. If either reference pointer is NULL then the
|
||||
* other reference pointer value is returned.
|
||||
*/
|
||||
static backend_ref_t *check_candidate_bref(backend_ref_t *cand,
|
||||
backend_ref_t *new,
|
||||
select_criteria_t sc)
|
||||
{
|
||||
int (*p)(const void *, const void *);
|
||||
/** get compare function */
|
||||
p = criteria_cmpfun[sc];
|
||||
|
||||
if (new == NULL)
|
||||
{
|
||||
return cand;
|
||||
}
|
||||
else if (cand == NULL || (p((void *)cand, (void *)new) > 0))
|
||||
{
|
||||
return new;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cand;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************
|
||||
* This routine returns the root master server from MySQL replication tree
|
||||
* Get the root Master rule:
|
@ -11,7 +11,8 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
@ -20,19 +21,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <maxscale/router.h>
|
||||
#include "rwsplit_internal.h"
|
||||
|
||||
/**
|
||||
* @file rwsplit_select_backends.c The functions that implement back end
|
||||
* selection for the read write split router. All of these functions are
|
||||
* internal to that router and not intended to be called from elsewhere.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 08/08/2016 Martin Brampton Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
* The functions that implement back end selection for the read write
|
||||
* split router. All of these functions are internal to that router and
|
||||
* not intended to be called from elsewhere.
|
||||
*/
|
||||
|
||||
static bool connect_server(backend_ref_t *bref, MXS_SESSION *session, bool execute_history);
|
@ -11,7 +11,8 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
@ -20,19 +21,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <maxscale/router.h>
|
||||
#include "rwsplit_internal.h"
|
||||
|
||||
/**
|
||||
* @file rwsplit_session_cmd.c The functions that provide session command
|
||||
* handling for the read write split router.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 08/08/2016 Martin Brampton Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
* Functions for session command handling
|
||||
*/
|
||||
|
||||
static bool sescmd_cursor_history_empty(sescmd_cursor_t *scur);
|
@ -11,32 +11,22 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "readwritesplit.h"
|
||||
#include "readwritesplit.hh"
|
||||
#include "rwsplit_internal.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <maxscale/alloc.h>
|
||||
|
||||
/* Note that modutil contains much MySQL specific code */
|
||||
#include <maxscale/modutil.h>
|
||||
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/router.h>
|
||||
#include "rwsplit_internal.h"
|
||||
|
||||
/**
|
||||
* @file rwsplit_tmp_table.c The functions that carry out checks on
|
||||
* statements to see if they involve various operations involving temporary
|
||||
* tables or multi-statement queries.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 08/08/2016 Martin Brampton Initial implementation
|
||||
*
|
||||
* @endverbatim
|
||||
* The functions that carry out checks on statements to see if they involve
|
||||
* various operations involving temporary tables or multi-statement queries.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -55,7 +45,7 @@
|
||||
* @param type The type of the query resolved so far
|
||||
*/
|
||||
void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, GWBUF *querybuf,
|
||||
mysql_server_cmd_t packet_type)
|
||||
uint32_t packet_type)
|
||||
{
|
||||
if (packet_type != MYSQL_COM_QUERY && packet_type != MYSQL_COM_DROP_DB)
|
||||
{
|
||||
@ -81,7 +71,7 @@ void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, GWBUF *querybuf,
|
||||
{
|
||||
/* Not clear why the next six lines are outside the if block */
|
||||
klen = strlen(dbname) + strlen(tbl[i]) + 2;
|
||||
hkey = MXS_CALLOC(klen, sizeof(char));
|
||||
hkey = (char*)MXS_CALLOC(klen, sizeof(char));
|
||||
MXS_ABORT_IF_NULL(hkey);
|
||||
strcpy(hkey, dbname);
|
||||
strcat(hkey, ".");
|
||||
@ -113,7 +103,7 @@ void check_drop_tmp_table(ROUTER_CLIENT_SES *router_cli_ses, GWBUF *querybuf,
|
||||
*/
|
||||
bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf,
|
||||
qc_query_type_t qtype)
|
||||
uint32_t qtype)
|
||||
{
|
||||
|
||||
bool target_tmp_table = false;
|
||||
@ -199,7 +189,7 @@ bool is_read_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
* @param type The type of the query resolved so far
|
||||
*/
|
||||
void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
GWBUF *querybuf, qc_query_type_t type)
|
||||
GWBUF *querybuf, uint32_t type)
|
||||
{
|
||||
if (!qc_query_is_type(type, QUERY_TYPE_CREATE_TMP_TABLE))
|
||||
{
|
||||
@ -246,7 +236,7 @@ void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
if (tblname && strlen(tblname) > 0)
|
||||
{
|
||||
klen = strlen(dbname) + strlen(tblname) + 2;
|
||||
hkey = MXS_CALLOC(klen, sizeof(char));
|
||||
hkey = (char*)MXS_CALLOC(klen, sizeof(char));
|
||||
MXS_ABORT_IF_NULL(hkey);
|
||||
strcpy(hkey, dbname);
|
||||
strcat(hkey, ".");
|
||||
@ -321,7 +311,7 @@ void check_create_tmp_table(ROUTER_CLIENT_SES *router_cli_ses,
|
||||
* @param buf Buffer containing the full query
|
||||
* @return True if the query contains multiple statements
|
||||
*/
|
||||
bool check_for_multi_stmt(GWBUF *buf, void *protocol, mysql_server_cmd_t packet_type)
|
||||
bool check_for_multi_stmt(GWBUF *buf, void *protocol, uint8_t packet_type)
|
||||
{
|
||||
MySQLProtocol *proto = (MySQLProtocol *)protocol;
|
||||
bool rval = false;
|
||||
@ -362,16 +352,16 @@ bool check_for_multi_stmt(GWBUF *buf, void *protocol, mysql_server_cmd_t packet_
|
||||
* @param packet_type Integer denoting DB specific enum
|
||||
* @param non_empty_packet Boolean to be set by this function
|
||||
*
|
||||
* @return qc_query_type_t the query type; also the non_empty_packet bool is set
|
||||
* @return uint32_t the query type; also the non_empty_packet bool is set
|
||||
*/
|
||||
qc_query_type_t
|
||||
uint32_t
|
||||
determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet)
|
||||
{
|
||||
qc_query_type_t qtype = QUERY_TYPE_UNKNOWN;
|
||||
uint32_t qtype = QUERY_TYPE_UNKNOWN;
|
||||
|
||||
if (non_empty_packet)
|
||||
{
|
||||
mysql_server_cmd_t my_packet_type = (mysql_server_cmd_t)packet_type;
|
||||
uint8_t my_packet_type = (uint8_t)packet_type;
|
||||
switch (my_packet_type)
|
||||
{
|
||||
case MYSQL_COM_QUIT: /*< 1 QUIT will close all sessions */
|
Reference in New Issue
Block a user