Merge branch 'develop' into 1.2.1-binlog_router_trx

This commit is contained in:
MassimilianoPinto
2015-09-30 14:20:39 +02:00
19 changed files with 147 additions and 163 deletions

View File

@ -23,12 +23,12 @@ endif()
target_link_libraries(maxscale ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++)
install(TARGETS maxscale DESTINATION ${MAXSCALE_BINDIR})
add_executable(maxkeys maxkeys.c secrets.c utils.c gwdirs.c)
target_link_libraries(maxkeys log_manager utils pthread crypt crypto)
add_executable(maxkeys maxkeys.c secrets.c utils.c gwdirs.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc)
target_link_libraries(maxkeys utils pthread crypt crypto)
install(TARGETS maxkeys DESTINATION ${MAXSCALE_BINDIR})
add_executable(maxpasswd maxpasswd.c secrets.c utils.c gwdirs.c)
target_link_libraries(maxpasswd log_manager utils pthread crypt crypto)
add_executable(maxpasswd maxpasswd.c secrets.c utils.c gwdirs.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc)
target_link_libraries(maxpasswd utils pthread crypt crypto)
install(TARGETS maxpasswd DESTINATION ${MAXSCALE_BINDIR})
if(BUILD_TESTS)

View File

@ -29,7 +29,7 @@
#include <skygw_utils.h>
#include <log_manager.h>
#include <gwdirs.h>
#include <sys/stat.h>
/** Defined in log_manager.cc */
extern int lm_enabled_logfiles_bitmask;
extern size_t log_ses_count[];
@ -154,6 +154,11 @@ FILE *fp;
char fname[1024], *home, *cpasswd;
initialise();
if(access(get_datadir(), F_OK) != 0)
if(mkdir(get_datadir(), S_IRWXU) != 0 && errno != EEXIST)
return ADMIN_ERR_PWDFILEOPEN;
snprintf(fname,1023, "%s/passwd", get_datadir());
fname[1023] = '\0';
if (users == NULL)

View File

@ -2334,6 +2334,7 @@ static char *InternalRouters[] = {
"cli",
"maxinfo",
"binlogrouter",
"testroute",
NULL
};

View File

@ -270,7 +270,7 @@ char *home, buf[1024];
/* Unlink any existing password file before running this test */
sprintf(buf, "%s/passwd", default_cachedir);
sprintf(buf, "%s/passwd", get_datadir());
if(!is_valid_posix_path(buf))
exit(1);
if (strcmp(buf, "/etc/passwd") != 0)

View File

@ -27,6 +27,13 @@
* @endverbatim
*/
// To ensure that ss_info_assert asserts also when builing in non-debug mode.
#if !defined(SS_DEBUG)
#define SS_DEBUG
#endif
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -59,7 +59,7 @@ int buflen;
printAllDCBs();
ss_info_dassert(true, "Something is true");
ss_dfprintf(stderr, "\t..done\n");
dcb_free(dcb);
dcb_close(dcb);
ss_dfprintf(stderr, "Freed original dcb");
ss_info_dassert(!dcb_isvalid(dcb), "Freed DCB must not be valid");
ss_dfprintf(stderr, "\t..done\nMake clone DCB a zombie");

View File

@ -41,6 +41,7 @@
#include <buffer.h>
#include <regex.h>
#include <modules.h>
#include <maxscale_test.h>
static char* server_options[] = {
"MariaDB Corporation MaxScale",
@ -65,6 +66,7 @@ static char* server_groups[] = {
};
int config_load(char *);
void config_enable_feedback_task(void);
int module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *cfg);
int do_http_post(GWBUF *buffer, void *cfg);
@ -78,7 +80,8 @@ int main(int argc, char** argv)
hkinit();
cnf = strdup("/etc/MaxScale.cnf");
cnf = malloc(sizeof(char) * (strlen(TEST_DIR) + strlen("/maxscale.cnf") + 1));
sprintf(cnf, "%s/maxscale.cnf", TEST_DIR);
printf("Config: %s\n",cnf);
@ -89,7 +92,7 @@ int main(int argc, char** argv)
}
config_load(cnf);
config_enable_feedback_task();
if ((fc = config_get_feedback_data()) == NULL)
{
FAILTEST("Configuration for Feedback was NULL.");

View File

@ -70,10 +70,11 @@ int
test2()
{
GWBUF *buffer;
char len = 128;
unsigned int len = 128;
char query[129];
buffer = gwbuf_alloc(132);
/** Allocate space for the COM_QUERY header and payload */
buffer = gwbuf_alloc(5 + 128);
ss_info_dassert((buffer != NULL),"Buffer should not be null");
memset(query,';',128);

View File

@ -86,7 +86,7 @@ int result;
sleep(10);
poll_shutdown();
ss_dfprintf(stderr, "\t..done\nTidy up.");
dcb_free(dcb);
dcb_close(dcb);
ss_dfprintf(stderr, "\t..done\n");
return 0;

View File

@ -27,6 +27,13 @@
* @endverbatim
*/
// To ensure that ss_info_assert asserts also when builing in non-debug mode.
#if !defined(SS_DEBUG)
#define SS_DEBUG
#endif
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -34,15 +41,6 @@
#include <test_utils.h>
#include <service.h>
static bool success = false;
int hup(DCB* dcb)
{
success = true;
return 1;
}
/**
* test1 Allocate a service and do lots of other things
*
@ -57,17 +55,6 @@ int result;
int argc = 3;
init_test_env(NULL);
/* char* argv[] = */
/* { */
/* "log_manager", */
/* "-j", */
/* TEST_LOG_DIR, */
/* NULL */
/* }; */
/* skygw_logmanager_init(argc,argv); */
/* poll_init(); */
/* hkinit(); */
/* Service tests */
ss_dfprintf(stderr,
@ -91,9 +78,9 @@ init_test_env(NULL);
result = serviceStart(service);
skygw_log_sync_all();
ss_info_dassert(0 != result, "Start should succeed");
result = serviceStop(service);
serviceStop(service);
skygw_log_sync_all();
ss_info_dassert(0 != result, "Stop should succeed");
ss_info_dassert(service->state == SERVICE_STATE_STOPPED, "Stop should succeed");
result = serviceStartAll();
skygw_log_sync_all();
ss_info_dassert(0 != result, "Start all should succeed");
@ -104,35 +91,26 @@ init_test_env(NULL);
result = serviceStart(service);
skygw_log_sync_all();
ss_info_dassert(0 != result, "Start should succeed");
result = serviceStop(service);
serviceStop(service);
skygw_log_sync_all();
ss_info_dassert(0 != result, "Stop should succeed");
ss_info_dassert(service->state == SERVICE_STATE_STOPPED, "Stop should succeed");
if((dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER)) == NULL)
return 1;
if((dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER)) == NULL)
return 1;
ss_info_dassert(dcb != NULL, "DCB allocation failed");
session = session_alloc(service,dcb);
ss_info_dassert(session != NULL, "Session allocation failed");
session->client->state = DCB_STATE_POLLING;
session->client->func.hangup = hup;
dcb->state = DCB_STATE_POLLING;
sleep(15);
ss_info_dassert(success, "Session timeout failed");
ss_info_dassert(dcb->state != DCB_STATE_POLLING, "Session timeout failed");
ss_dfprintf(stderr, "\t..done\nStopping Service.");
ss_info_dassert(0 != serviceStop(service), "Stop should succeed");
serviceStop(service);
ss_info_dassert(service->state == SERVICE_STATE_STOPPED, "Stop should succeed");
ss_dfprintf(stderr, "\t..done\n");
/** This is never used in MaxScale and will always fail due to service's
* stats.n_current value never being decremented */
/*
ss_dfprintf(stderr, "\t..done\nFreeing Service.");
ss_info_dassert(0 != service_free(service), "Free should succeed");
ss_dfprintf(stderr, "\t..done\n");
*/
return 0;
}

View File

@ -27,6 +27,13 @@
* @endverbatim
*/
// To ensure that ss_info_assert asserts also when builing in non-debug mode.
#if !defined(SS_DEBUG)
#define SS_DEBUG
#endif
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -472,73 +472,55 @@ bool check_time(char* str)
#endif
#define IS_RVRS_TIME(tr) (mktime(&tr->end) < mktime(&tr->start))
/**
* Parses a null-terminated string into two tm_t structs that mark a timerange
* Parses a null-terminated string into a timerange defined by two ISO-8601 compliant
* times separated by a single dash. The times are interpreted at one second precision
* and follow the extended format by separating the hours, minutes and seconds with
* semicolons.
* @param str String to parse
* @param instance FW_FILTER instance
* @return If successful returns a pointer to the new TIMERANGE instance. If errors occurred or
* the timerange was invalid, a NULL pointer is returned.
*/
TIMERANGE* parse_time(char* str, FW_INSTANCE* instance)
static TIMERANGE* parse_time(const char* str)
{
assert(str != NULL);
TIMERANGE* tr = NULL;
int intbuffer[3];
int* idest = intbuffer;
char strbuffer[3];
char *ptr,*sdest;
struct tm* tmptr;
char strbuf[strlen(str) + 1];
char *separator;
struct tm start, end;
TIMERANGE* tr = NULL;
assert(str != NULL && instance != NULL);
tr = (TIMERANGE*)calloc(1,sizeof(TIMERANGE));
strcpy(strbuf, str);
if(tr == NULL){
skygw_log_write(LOGFILE_ERROR, "dbfwfilter: malloc returned NULL.");
return NULL;
}
if ((separator = strchr(strbuf, '-')))
{
*separator++ = '\0';
if (strptime(strbuf, "%H:%M:%S", &start) &&
strptime(separator, "%H:%M:%S", &end))
{
/** The time string was valid */
CHK_TIMES((&start));
CHK_TIMES((&end));
memset(&tr->start,0,sizeof(struct tm));
memset(&tr->end,0,sizeof(struct tm));
ptr = str;
sdest = strbuffer;
tmptr = &tr->start;
tr = (TIMERANGE*) malloc(sizeof(TIMERANGE));
while(ptr - str < 19){
if(isdigit(*ptr)){
*sdest = *ptr;
}else if(*ptr == ':' ||*ptr == '-' || *ptr == '\0' || *ptr == ' '){
*sdest = '\0';
*idest++ = atoi(strbuffer);
sdest = strbuffer;
if(*ptr == '-' || *ptr == '\0'){
tmptr->tm_hour = intbuffer[0];
tmptr->tm_min = intbuffer[1];
tmptr->tm_sec = intbuffer[2];
CHK_TIMES(tmptr);
if(*ptr == '\0' || *ptr == ' '){
return tr;
}
idest = intbuffer;
tmptr = &tr->end;
}
ptr++;
continue;
}
ptr++;
sdest++;
}
free(tr);
return NULL;
if (tr)
{
tr->start = start;
tr->end = end;
tr->next = NULL;
}
else
{
skygw_log_write(LOGFILE_ERROR, "dbfwfilter: malloc returned NULL.");
}
}
}
return tr;
}
/**
* Splits the reversed timerange into two.
*@param tr A reversed timerange
@ -1020,7 +1002,7 @@ bool parse_rule(char* rule, FW_INSTANCE* instance)
goto retblock;
}
TIMERANGE *tmp = parse_time(tok,instance);
TIMERANGE *tmp = parse_time(tok);
if(tmp == NULL)
{

View File

@ -242,19 +242,17 @@ typedef struct backend_ref_st {
#endif
} backend_ref_t;
typedef struct rwsplit_config_st {
int rw_max_slave_conn_percent;
int rw_max_slave_conn_count;
select_criteria_t rw_slave_select_criteria;
int rw_max_slave_replication_lag;
target_t rw_use_sql_variables_in;
int rw_max_sescmd_history_size;
bool disable_sescmd_hist;
bool disable_slave_recovery;
bool master_reads; /*< Use master for reads */
typedef struct rwsplit_config_st
{
int rw_max_slave_conn_percent;
int rw_max_slave_conn_count;
select_criteria_t rw_slave_select_criteria;
int rw_max_slave_replication_lag;
target_t rw_use_sql_variables_in;
int rw_max_sescmd_history_size;
bool rw_disable_sescmd_hist;
bool rw_master_reads; /*< Use master for reads */
} rwsplit_config_t;
#if defined(PREP_STMT_CACHING)

View File

@ -3,9 +3,22 @@ set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPAT
target_link_libraries(binlogrouter ssl pthread log_manager)
install(TARGETS binlogrouter DESTINATION ${MAXSCALE_LIBDIR})
add_executable(maxbinlogcheck maxbinlogcheck.c blr_file.c blr_cache.c blr_master.c blr_slave.c blr.c ${CMAKE_SOURCE_DIR}/server/core/service.c ${CMAKE_SOURCE_DIR}/server/core/spinlock.c ${CMAKE_SOURCE_DIR}/server/core/buffer.c ${CMAKE_SOURCE_DIR}/server/core/atomic.c ${CMAKE_SOURCE_DIR}/server/core/hint.c ${CMAKE_SOURCE_DIR}/server/core/gwdirs.c ${CMAKE_SOURCE_DIR}/server/core/server.c ${CMAKE_SOURCE_DIR}/server/core/dcb.c ${CMAKE_SOURCE_DIR}/server/core/users.c ${CMAKE_SOURCE_DIR}/server/core/dbusers.c ${CMAKE_SOURCE_DIR}/server/core/utils.c ${CMAKE_SOURCE_DIR}/server/core/hashtable.c ${CMAKE_SOURCE_DIR}/server/core/poll.c ${CMAKE_SOURCE_DIR}/server/core/gwbitmask.c ${CMAKE_SOURCE_DIR}/server/core/config.c ${CMAKE_SOURCE_DIR}/server/core/session.c ${CMAKE_SOURCE_DIR}/server/core/housekeeper.c ${CMAKE_SOURCE_DIR}/server/core/filter.c ${CMAKE_SOURCE_DIR}/server/core/resultset.c ${CMAKE_SOURCE_DIR}/server/core/load_utils.c ${CMAKE_SOURCE_DIR}/server/core/monitor.c ${CMAKE_SOURCE_DIR}/server/core/gw_utils.c ${CMAKE_SOURCE_DIR}/server/core/thread.c ${CMAKE_SOURCE_DIR}/server/core/secrets.c)
add_executable(maxbinlogcheck maxbinlogcheck.c blr_file.c blr_cache.c blr_master.c blr_slave.c blr.c
${CMAKE_SOURCE_DIR}/server/core/service.c ${CMAKE_SOURCE_DIR}/server/core/spinlock.c
${CMAKE_SOURCE_DIR}/server/core/buffer.c ${CMAKE_SOURCE_DIR}/server/core/atomic.c
${CMAKE_SOURCE_DIR}/server/core/hint.c ${CMAKE_SOURCE_DIR}/server/core/gwdirs.c
${CMAKE_SOURCE_DIR}/server/core/server.c ${CMAKE_SOURCE_DIR}/server/core/dcb.c
${CMAKE_SOURCE_DIR}/server/core/users.c ${CMAKE_SOURCE_DIR}/server/core/dbusers.c
${CMAKE_SOURCE_DIR}/server/core/utils.c ${CMAKE_SOURCE_DIR}/server/core/hashtable.c
${CMAKE_SOURCE_DIR}/server/core/poll.c ${CMAKE_SOURCE_DIR}/server/core/gwbitmask.c
${CMAKE_SOURCE_DIR}/server/core/config.c ${CMAKE_SOURCE_DIR}/server/core/session.c
${CMAKE_SOURCE_DIR}/server/core/housekeeper.c ${CMAKE_SOURCE_DIR}/server/core/filter.c
${CMAKE_SOURCE_DIR}/server/core/resultset.c ${CMAKE_SOURCE_DIR}/server/core/load_utils.c
${CMAKE_SOURCE_DIR}/server/core/monitor.c ${CMAKE_SOURCE_DIR}/server/core/gw_utils.c
${CMAKE_SOURCE_DIR}/server/core/thread.c ${CMAKE_SOURCE_DIR}/server/core/secrets.c
${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc)
target_link_libraries(maxbinlogcheck utils ssl pthread log_manager ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} aio rt crypt dl crypto inih z m stdc++ ${CURL_LIBRARIES})
target_link_libraries(maxbinlogcheck utils ssl pthread ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} aio rt crypt dl crypto inih z m stdc++ ${CURL_LIBRARIES})
install(TARGETS maxbinlogcheck DESTINATION bin)

View File

@ -702,7 +702,7 @@ createInstance(SERVICE *service, char **options)
}
/** These options cancel each other out */
if(router->rwsplit_config.disable_sescmd_hist && router->rwsplit_config.rw_max_sescmd_history_size > 0)
if(router->rwsplit_config.rw_disable_sescmd_hist && router->rwsplit_config.rw_max_sescmd_history_size > 0)
{
router->rwsplit_config.rw_max_sescmd_history_size = 0;
}
@ -1246,7 +1246,7 @@ static bool get_dcb(
(max_rlag == MAX_RLAG_UNDEFINED ||
(b->backend_server->rlag != MAX_RLAG_NOT_AVAILABLE &&
b->backend_server->rlag <= max_rlag)) &&
!rses->rses_config.master_reads)
!rses->rses_config.rw_master_reads)
{
/** found slave */
candidate_bref = &backend_ref[i];
@ -2022,6 +2022,9 @@ static int routeQuery(
}
else
{
/** route_single_stmt expects the buffer to be contiguous. */
querybuf = gwbuf_make_contiguous(querybuf);
succp = route_single_stmt(inst, router_cli_ses, querybuf);
}
}
@ -2053,6 +2056,9 @@ static int routeQuery(
}
else
{
/** route_single_stmt expects the buffer to be contiguous. */
querybuf = gwbuf_make_contiguous(querybuf);
succp = route_single_stmt(inst, router_cli_ses, querybuf);
}
@ -2108,6 +2114,7 @@ static bool route_single_stmt(
int rlag_max = MAX_RLAG_UNDEFINED;
backend_type_t btype; /*< target backend type */
ss_dassert(querybuf->next == NULL); // The buffer must be contiguous.
ss_dassert(!GWBUF_IS_TYPE_UNDEFINED(querybuf));
/**
@ -2130,12 +2137,6 @@ static bool route_single_stmt(
succp = false;
goto retblock;
}
/** If buffer is not contiguous, make it such */
if (querybuf->next != NULL)
{
querybuf = gwbuf_make_contiguous(querybuf);
}
packet = GWBUF_DATA(querybuf);
packet_len = gw_mysql_get_byte3(packet);
@ -2896,7 +2897,7 @@ static void clientReply (
bool rconn = false;
writebuf = sescmd_cursor_process_replies(writebuf, bref, &rconn);
if(rconn && !router_inst->rwsplit_config.disable_slave_recovery)
if(rconn && !router_inst->rwsplit_config.rw_disable_sescmd_hist)
{
select_connect_backend_servers(&router_cli_ses->rses_master_ref,
router_cli_ses->rses_backend_ref,
@ -4540,21 +4541,17 @@ static bool route_session_write(
goto return_succp;
}
if(router_cli_ses->rses_config.rw_max_sescmd_history_size > 0 &&
router_cli_ses->rses_nsescmd >= router_cli_ses->rses_config.rw_max_sescmd_history_size)
{
LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Router session exceeded session command history limit. "
"Closing router session. <")));
gwbuf_free(querybuf);
rses_end_locked_router_action(router_cli_ses);
router_cli_ses->client_dcb->func.hangup(router_cli_ses->client_dcb);
goto return_succp;
}
if (router_cli_ses->rses_config.rw_max_sescmd_history_size > 0 &&
router_cli_ses->rses_nsescmd >= router_cli_ses->rses_config.rw_max_sescmd_history_size)
{
skygw_log_write(LE, "Warning: Router session exceeded session command history limit. "
"Slave recovery is disabled and only slave servers with consistent session state are used "
"for the duration of the session.");
router_cli_ses->rses_config.rw_disable_sescmd_hist = true;
router_cli_ses->rses_config.rw_max_sescmd_history_size = 0;
}
if(router_cli_ses->rses_config.disable_sescmd_hist)
if(router_cli_ses->rses_config.rw_disable_sescmd_hist)
{
rses_property_t *prop, *tmp;
backend_ref_t* bref;
@ -4783,15 +4780,11 @@ static void rwsplit_process_router_options(
}
else if(strcmp(options[i],"disable_sescmd_history") == 0)
{
router->rwsplit_config.disable_sescmd_hist = config_truth_value(value);
}
else if(strcmp(options[i],"disable_slave_recovery") == 0)
{
router->rwsplit_config.disable_slave_recovery = config_truth_value(value);
router->rwsplit_config.rw_disable_sescmd_hist = config_truth_value(value);
}
else if(strcmp(options[i],"master_accept_reads") == 0)
{
router->rwsplit_config.master_reads = config_truth_value(value);
router->rwsplit_config.rw_master_reads = config_truth_value(value);
}
}
} /*< for */
@ -5038,7 +5031,7 @@ static bool handle_error_new_connection(
* Try to get replacement slave or at least the minimum
* number of slave connections for router session.
*/
if(inst->rwsplit_config.disable_slave_recovery)
if(inst->rwsplit_config.rw_disable_sescmd_hist)
{
succp = have_enough_servers(&myrses,1,router_nservers,inst) ? true : false;
}

View File

@ -26,7 +26,7 @@ else
TDIR=.
fi
RUNCMD=mysql\ --host=$THOST\ -P$TPORT\ -u$TUSER\ -p$TPWD\ --unbuffered=true\ --disable-reconnect\ --silent\ --comment
RUNCMD="mysql --host=$THOST -P$TPORT -u$TUSER -p$TPWD --unbuffered=true --disable-reconnect --silent -c"
i=0
while read -r LINE