Merge branch '2.2' into develop

This commit is contained in:
Johan Wikman
2018-03-01 18:08:45 +02:00
18 changed files with 330 additions and 117 deletions

View File

@ -5,7 +5,7 @@
set(MAXSCALE_VERSION_MAJOR "2" CACHE STRING "Major version") set(MAXSCALE_VERSION_MAJOR "2" CACHE STRING "Major version")
set(MAXSCALE_VERSION_MINOR "2" CACHE STRING "Minor version") set(MAXSCALE_VERSION_MINOR "2" CACHE STRING "Minor version")
set(MAXSCALE_VERSION_PATCH "2" CACHE STRING "Patch version") set(MAXSCALE_VERSION_PATCH "3" CACHE STRING "Patch version")
# This should only be incremented if a package is rebuilt # This should only be incremented if a package is rebuilt
set(MAXSCALE_BUILD_NUMBER 1 CACHE STRING "Release number") set(MAXSCALE_BUILD_NUMBER 1 CACHE STRING "Release number")

View File

@ -605,6 +605,14 @@ add_test_executable(mxs1643_extra_events.cpp mxs1643_extra_events mxs1643_extra_
# https://jira.mariadb.org/browse/MXS-1653 # https://jira.mariadb.org/browse/MXS-1653
add_test_executable(mxs1653_ps_hang.cpp mxs1653_ps_hang replication LABELS REPL_BACKEND) add_test_executable(mxs1653_ps_hang.cpp mxs1653_ps_hang replication LABELS REPL_BACKEND)
# MXS-1677: sysbench failed to initialize w/ MaxScale read/write splitter
# https://jira.mariadb.org/browse/MXS-1677
add_test_executable(mxs1677_temp_table.cpp mxs1677_temp_table replication LABELS REPL_BACKEND)
# MXS-1678: Stopping IO thread on relay master causes it to be promoted as master
# https://jira.mariadb.org/browse/MXS-1678
add_test_executable(mxs1678_relay_master.cpp mxs1678_relay_master replication LABELS REPL_BACKEND)
# 'namedserverfilter' test # 'namedserverfilter' test
add_test_executable(namedserverfilter.cpp namedserverfilter namedserverfilter LABELS namedserverfilter LIGHT REPL_BACKEND) add_test_executable(namedserverfilter.cpp namedserverfilter namedserverfilter LABELS namedserverfilter LIGHT REPL_BACKEND)

View File

@ -0,0 +1,18 @@
/**
* MXS-1677: Error messages logged for non-text queries after temporary table is created
*
* https://jira.mariadb.org/browse/MXS-1677
*/
#include "testconnections.h"
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
test.maxscales->connect();
test.try_query(test.maxscales->conn_rwsplit[0], "CREATE TEMPORARY TABLE test.temp(id INT)");
test.maxscales->disconnect();
test.check_log_err(0, "The provided buffer does not contain a COM_QUERY, but a COM_QUIT", false);
return test.global_result;
}

View File

@ -0,0 +1,86 @@
/**
* MXS-1678: Stopping IO thread on relay master causes it to be promoted as master
*
* https://jira.mariadb.org/browse/MXS-1678
*/
#include "testconnections.h"
#include <set>
#include <string>
typedef std::set<std::string> StringSet;
// Note: This is backported from 2.2 and can be replaced with MaxScales::get_server_status once merged
StringSet state(TestConnections& test, const char* name)
{
StringSet rval;
char* res = test.ssh_maxscale_output(true, "maxadmin list servers|grep \'%s\'", name);
char* pipe = strrchr(res, '|');
if (res && pipe)
{
pipe++;
char* tok = strtok(pipe, ",");
while (tok)
{
char* p = tok;
char *end = strchr(tok, '\n');
if (!end)
{
end = strchr(tok, '\0');
}
// Trim leading whitespace
while (p < end && isspace(*p))
{
p++;
}
// Trim trailing whitespace
while (end > tok && isspace(*end))
{
*end-- = '\0';
}
rval.insert(p);
tok = strtok(NULL, ",\n");
}
}
free(res);
return rval;
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
test.repl->connect();
execute_query(test.repl->nodes[3], "STOP SLAVE");
execute_query(test.repl->nodes[3], "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d",
test.repl->IP_private[2], test.repl->port[2]);
execute_query(test.repl->nodes[3], "START SLAVE");
StringSet master = {"Master", "Running"};
StringSet slave = {"Slave", "Running"};
StringSet relay_master = {"Relay Master", "Slave", "Running"};
test.tprintf("Checking before stopping IO thread");
test.add_result(state(test, "server1") != master, "server1 is not a master");
test.add_result(state(test, "server2") != slave, "server2 is not a slave");
test.add_result(state(test, "server3") != relay_master, "server3 is not a relay master");
test.add_result(state(test, "server4") != slave, "server4 is not a slave");
execute_query(test.repl->nodes[2], "STOP SLAVE IO_THREAD");
sleep(10);
test.tprintf("Checking after stopping IO thread");
test.add_result(state(test, "server1") != master, "server1 is not a master");
test.add_result(state(test, "server2") != slave, "server2 is not a slave");
test.add_result(state(test, "server3") != relay_master, "server3 is not a relay master");
test.add_result(state(test, "server4") != slave, "server4 is not a slave");
test.repl->fix_replication();
return test.global_result;
}

View File

@ -3544,6 +3544,7 @@ static bool parse_query(GWBUF* query, uint32_t collect)
{ {
MXS_ERROR("The provided buffer does not contain a COM_QUERY, but a %s.", MXS_ERROR("The provided buffer does not contain a COM_QUERY, but a %s.",
STRPACKETTYPE(MYSQL_GET_COMMAND(data))); STRPACKETTYPE(MYSQL_GET_COMMAND(data)));
ss_dassert(!true);
} }
} }
else else

View File

@ -2087,10 +2087,10 @@ expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y).
expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y).
{spanBinaryExpr(&A,pParse,@OP,&X,&Y);} {spanBinaryExpr(&A,pParse,@OP,&X,&Y);}
%ifdef MAXSCALE %ifdef MAXSCALE
expr(A) ::= expr(X) PLUS|MINUS INTERVAL INTEGER id. { expr(A) ::= INTERVAL INTEGER(X) id. {
// Here we could check that id is one of MICROSECOND, SECOND, MINUTE // Here we could check that id is one of MICROSECOND, SECOND, MINUTE
// HOUR, DAY, WEEK, etc. // HOUR, DAY, WEEK, etc.
A=X; spanExpr(&A, pParse, @X, &X);
} }
%endif %endif
expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y).

View File

@ -1044,6 +1044,11 @@ public:
return rv; return rv;
} }
const std::string& name() const
{
return m_name;
}
void print(ostream& out) const void print(ostream& out) const
{ {
out << m_name; out << m_name;
@ -1166,6 +1171,19 @@ bool operator == (const QcFunctionInfo& lhs, const QcFunctionInfo& rhs)
return lhs.eq(rhs); return lhs.eq(rhs);
} }
void collect_missing_function_names(const std::set<QcFunctionInfo>& one,
const std::set<QcFunctionInfo>& other,
std::set<std::string>* pNames)
{
for (std::set<QcFunctionInfo>::const_iterator i = one.begin(); i != one.end(); ++i)
{
if (other.count(*i) == 0)
{
pNames->insert(i->name());
}
}
}
bool compare_get_function_info(QUERY_CLASSIFIER* pClassifier1, GWBUF* pCopy1, bool compare_get_function_info(QUERY_CLASSIFIER* pClassifier1, GWBUF* pCopy1,
QUERY_CLASSIFIER* pClassifier2, GWBUF* pCopy2) QUERY_CLASSIFIER* pClassifier2, GWBUF* pCopy2)
{ {
@ -1198,9 +1216,49 @@ bool compare_get_function_info(QUERY_CLASSIFIER* pClassifier1, GWBUF* pCopy1,
success = true; success = true;
} }
else else
{
std::set<std::string> names1;
collect_missing_function_names(f1, f2, &names1);
std::set<std::string> names2;
collect_missing_function_names(f2, f1, &names2);
bool real_error = false;
// We assume that names1 are from the qc_mysqlembedded and names2 from qc_sqlite.
// The embedded parser reports all date_add(), adddate(), date_sub() and subdate()
// functions as date_add_interval(). Further, all "DATE + INTERVAL ..." cases become
// use of date_add_interval() functions.
for (std::set<std::string>::iterator i = names1.begin(); i != names1.end(); ++i)
{
if (*i == "date_add_interval")
{
if ((names2.count("date_add") == 0) &&
(names2.count("adddate") == 0) &&
(names2.count("date_sub") == 0) &&
(names2.count("subdate") == 0) &&
(names2.count("+") == 0) &&
(names2.count("-") == 0))
{
real_error = true;
}
}
else
{
real_error = true;
}
}
if (real_error)
{ {
ss << "ERR: " << f1 << " != " << f2; ss << "ERR: " << f1 << " != " << f2;
} }
else
{
ss << "Ok : " << f1 << " != " << f2;
success = true;
}
}
report(success, ss.str()); report(success, ss.str());

View File

@ -89,3 +89,11 @@ call p1();
call p1(@var); call p1(@var);
create or replace table t (a int); create or replace table t (a int);
# MXS-1688
select id from db2.t1 where DATE_SUB("2017-06-15", INTERVAL 10 DAY) < "2017-06-15";
select id from db2.t1 where SUBDATE("2017-06-15", INTERVAL 10 DAY) < "2017-06-15";
select id from db2.t1 where DATE_ADD("2017-06-15", INTERVAL 10 DAY) < "2017-06-15";
select id from db2.t1 where ADDDATE("2017-06-15", INTERVAL 10 DAY) < "2017-06-15";
SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
SELECT '2005-01-01' - INTERVAL 1 SECOND;

View File

@ -1773,7 +1773,7 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
master_up = true; master_up = true;
} }
if (script && *script && (events & event)) if (script && (events & event))
{ {
monitor_launch_script(monitor, ptr, script, monitor->script_timeout); monitor_launch_script(monitor, ptr, script, monitor->script_timeout);
} }

View File

@ -629,6 +629,25 @@ static bool check_server_permissions(SERVICE *service, SERVER* server,
} }
} }
// Check whether the current user has the SHOW DATABASES privilege
if (mxs_mysql_query(mysql, "SELECT show_db_priv FROM mysql.user "
"WHERE CONCAT(user, '@', host) = CURRENT_USER()") == 0)
{
MYSQL_RES* res = mysql_use_result(mysql);
if (res)
{
MYSQL_ROW row = mysql_fetch_row(res);
if (row && strcasecmp(row[0], "Y") != 0)
{
MXS_WARNING("[%s] User '%s' is missing the SHOW DATABASES privilege.",
service->name, user);
}
mysql_free_result(res);
}
}
mysql_close(mysql); mysql_close(mysql);
return rval; return rval;

View File

@ -35,7 +35,7 @@ USTR [%-_[:alnum:][:punct:]]+
CMP [=<>!]+ CMP [=<>!]+
%% %%
"\n"+ return '\n'; {SPACE}"\n"+ return '\n';
{COMMENT} return FWTOK_COMMENT; {COMMENT} return FWTOK_COMMENT;
deny|allow MXS_WARNING("Use of '%s' is deprecated, use 'match' instead", yytext);return FWTOK_MATCH; deny|allow MXS_WARNING("Use of '%s' is deprecated, use 'match' instead", yytext);return FWTOK_MATCH;
rule return FWTOK_RULE; rule return FWTOK_RULE;

View File

@ -17,7 +17,7 @@
#define MXS_MODULE_NAME "mariadbmon" #define MXS_MODULE_NAME "mariadbmon"
#include "mariadbmon.hh" #include "../mysqlmon.h"
#include <inttypes.h> #include <inttypes.h>
#include <limits> #include <limits>
#include <string> #include <string>
@ -31,7 +31,6 @@
#include <maxscale/modulecmd.h> #include <maxscale/modulecmd.h>
#include <maxscale/modutil.h> #include <maxscale/modutil.h>
#include <maxscale/mysql_utils.h> #include <maxscale/mysql_utils.h>
#include <maxscale/secrets.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
// TODO: For monitorAddParameters // TODO: For monitorAddParameters
#include "../../../core/internal/monitor.h" #include "../../../core/internal/monitor.h"
@ -990,10 +989,8 @@ static bool set_replication_credentials(MYSQL_MONITOR *handle, const MXS_CONFIG_
if (*repl_user && *repl_pw) if (*repl_user && *repl_pw)
{ {
handle->replication_user = repl_user; handle->replication_user = MXS_STRDUP_A(repl_user);
char* decrypted = decrypt_password(repl_pw); handle->replication_password = decrypt_password(repl_pw);
handle->replication_password = decrypted;
MXS_FREE(decrypted);
rval = true; rval = true;
} }
@ -1036,22 +1033,22 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
if (handle) if (handle)
{ {
handle->shutdown = 0; handle->shutdown = 0;
handle->script.clear(); MXS_FREE(handle->script);
handle->replication_user.clear(); MXS_FREE(handle->replication_user);
handle->replication_password.clear(); MXS_FREE(handle->replication_password);
MXS_FREE(handle->excluded_servers); MXS_FREE(handle->excluded_servers);
handle->excluded_servers = NULL; handle->excluded_servers = NULL;
handle->n_excluded = 0; handle->n_excluded = 0;
} }
else else
{ {
handle = new MYSQL_MONITOR; handle = (MYSQL_MONITOR *) MXS_MALLOC(sizeof(MYSQL_MONITOR));
HASHTABLE *server_info = hashtable_alloc(MAX_NUM_SLAVES, HASHTABLE *server_info = hashtable_alloc(MAX_NUM_SLAVES,
hashtable_item_strhash, hashtable_item_strcmp); hashtable_item_strhash, hashtable_item_strcmp);
if (server_info == NULL) if (handle == NULL || server_info == NULL)
{ {
delete handle; MXS_FREE(handle);
hashtable_free(server_info); hashtable_free(server_info);
return NULL; return NULL;
} }
@ -1063,6 +1060,7 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
handle->id = config_get_global_options()->id; handle->id = config_get_global_options()->id;
handle->warn_set_standalone_master = true; handle->warn_set_standalone_master = true;
handle->master_gtid_domain = -1; handle->master_gtid_domain = -1;
handle->external_master_host[0] = '\0';
handle->external_master_port = PORT_UNKNOWN; handle->external_master_port = PORT_UNKNOWN;
handle->monitor = monitor; handle->monitor = monitor;
} }
@ -1079,14 +1077,15 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
handle->failcount = config_get_integer(params, CN_FAILCOUNT); handle->failcount = config_get_integer(params, CN_FAILCOUNT);
handle->allow_cluster_recovery = config_get_bool(params, "allow_cluster_recovery"); handle->allow_cluster_recovery = config_get_bool(params, "allow_cluster_recovery");
handle->mysql51_replication = config_get_bool(params, "mysql51_replication"); handle->mysql51_replication = config_get_bool(params, "mysql51_replication");
handle->script = config_get_string(params, "script"); handle->script = config_copy_string(params, "script");
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values); handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
handle->auto_failover = config_get_bool(params, CN_AUTO_FAILOVER);
handle->failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT); handle->failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT);
handle->switchover_timeout = config_get_integer(params, CN_SWITCHOVER_TIMEOUT); handle->switchover_timeout = config_get_integer(params, CN_SWITCHOVER_TIMEOUT);
handle->auto_failover = config_get_bool(params, CN_AUTO_FAILOVER);
handle->auto_rejoin = config_get_bool(params, CN_AUTO_REJOIN);
handle->verify_master_failure = config_get_bool(params, CN_VERIFY_MASTER_FAILURE); handle->verify_master_failure = config_get_bool(params, CN_VERIFY_MASTER_FAILURE);
handle->master_failure_timeout = config_get_integer(params, CN_MASTER_FAILURE_TIMEOUT); handle->master_failure_timeout = config_get_integer(params, CN_MASTER_FAILURE_TIMEOUT);
handle->auto_rejoin = config_get_bool(params, CN_AUTO_REJOIN);
handle->excluded_servers = NULL; handle->excluded_servers = NULL;
handle->n_excluded = mon_config_get_servers(params, CN_NO_PROMOTE_SERVERS, monitor, handle->n_excluded = mon_config_get_servers(params, CN_NO_PROMOTE_SERVERS, monitor,
&handle->excluded_servers); &handle->excluded_servers);
@ -1115,8 +1114,9 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
if (error) if (error)
{ {
hashtable_free(handle->server_info); hashtable_free(handle->server_info);
MXS_FREE(handle->script);
MXS_FREE(handle->excluded_servers); MXS_FREE(handle->excluded_servers);
delete handle; MXS_FREE(handle);
handle = NULL; handle = NULL;
} }
else else
@ -1127,7 +1127,8 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
{ {
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", monitor->name); MXS_ERROR("Failed to start monitor thread for monitor '%s'.", monitor->name);
hashtable_free(handle->server_info); hashtable_free(handle->server_info);
delete handle; MXS_FREE(handle->script);
MXS_FREE(handle);
handle = NULL; handle = NULL;
} }
} }
@ -1206,7 +1207,8 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
dcb_printf(dcb, "Switchover timeout: %u\n", handle->switchover_timeout); dcb_printf(dcb, "Switchover timeout: %u\n", handle->switchover_timeout);
dcb_printf(dcb, "Automatic rejoin: %s\n", handle->auto_rejoin ? "Enabled" : "Disabled"); dcb_printf(dcb, "Automatic rejoin: %s\n", handle->auto_rejoin ? "Enabled" : "Disabled");
dcb_printf(dcb, "MaxScale monitor ID: %lu\n", handle->id); dcb_printf(dcb, "MaxScale monitor ID: %lu\n", handle->id);
dcb_printf(dcb, "Detect replication lag: %s\n", (handle->replicationHeartbeat) ? "Enabled" : "Disabled"); dcb_printf(dcb, "Detect replication lag: %s\n", (handle->replicationHeartbeat == 1) ?
"Enabled" : "Disabled");
dcb_printf(dcb, "Detect stale master: %s\n", (handle->detectStaleMaster == 1) ? dcb_printf(dcb, "Detect stale master: %s\n", (handle->detectStaleMaster == 1) ?
"Enabled" : "Disabled"); "Enabled" : "Disabled");
if (handle->n_excluded > 0) if (handle->n_excluded > 0)
@ -1280,9 +1282,9 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
json_object_set_new(rval, CN_SWITCHOVER_TIMEOUT, json_integer(handle->switchover_timeout)); json_object_set_new(rval, CN_SWITCHOVER_TIMEOUT, json_integer(handle->switchover_timeout));
json_object_set_new(rval, CN_AUTO_REJOIN, json_boolean(handle->auto_rejoin)); json_object_set_new(rval, CN_AUTO_REJOIN, json_boolean(handle->auto_rejoin));
if (!handle->script.empty()) if (handle->script)
{ {
json_object_set_new(rval, "script", json_string(handle->script.c_str())); json_object_set_new(rval, "script", json_string(handle->script));
} }
if (handle->n_excluded > 0) if (handle->n_excluded > 0)
{ {
@ -1433,7 +1435,7 @@ static bool do_show_slave_status(MYSQL_MONITOR* mon,
* root master server. * root master server.
* Please note, there could be no slaves at all if Slave_SQL_Running == 'No' * Please note, there could be no slaves at all if Slave_SQL_Running == 'No'
*/ */
if (serv_info->slave_status.slave_io_running && server_version != MYSQL_SERVER_VERSION_51) if (server_version != MYSQL_SERVER_VERSION_51)
{ {
/* Get Master_Server_Id */ /* Get Master_Server_Id */
master_server_id = scan_server_id(row[i_master_server_id]); master_server_id = scan_server_id(row[i_master_server_id]);
@ -2110,7 +2112,7 @@ monitorMain(void *arg)
MYSQL_MONITOR *handle = (MYSQL_MONITOR *) arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *) arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITORED_SERVER *ptr; MXS_MONITORED_SERVER *ptr;
bool replication_heartbeat; int replication_heartbeat;
bool detect_stale_master; bool detect_stale_master;
int num_servers = 0; int num_servers = 0;
MXS_MONITORED_SERVER *root_master = NULL; MXS_MONITORED_SERVER *root_master = NULL;
@ -2283,20 +2285,21 @@ monitorMain(void *arg)
if (master_info->slave_status.master_host != handle->external_master_host || if (master_info->slave_status.master_host != handle->external_master_host ||
master_info->slave_status.master_port != handle->external_master_port) master_info->slave_status.master_port != handle->external_master_port)
{ {
const string new_ext_host = master_info->slave_status.master_host; const char* new_ext_host = master_info->slave_status.master_host.c_str();
const int new_ext_port = master_info->slave_status.master_port; const int new_ext_port = master_info->slave_status.master_port;
if (handle->external_master_port == PORT_UNKNOWN) if (handle->external_master_port == PORT_UNKNOWN)
{ {
MXS_NOTICE("Cluster master server is replicating from an external master: %s:%d", MXS_NOTICE("Cluster master server is replicating from an external master: %s:%d",
new_ext_host.c_str(), new_ext_port); new_ext_host, new_ext_port);
} }
else else
{ {
MXS_NOTICE("The external master of the cluster has changed: %s:%d -> %s:%d.", MXS_NOTICE("The external master of the cluster has changed: %s:%d -> %s:%d.",
handle->external_master_host.c_str(), handle->external_master_port, handle->external_master_host, handle->external_master_port,
new_ext_host.c_str(), new_ext_port); new_ext_host, new_ext_port);
} }
handle->external_master_host = new_ext_host; snprintf(handle->external_master_host, sizeof(handle->external_master_host),
"%s", new_ext_host);
handle->external_master_port = new_ext_port; handle->external_master_port = new_ext_port;
} }
} }
@ -2306,7 +2309,7 @@ monitorMain(void *arg)
{ {
MXS_NOTICE("Cluster lost the external master."); MXS_NOTICE("Cluster lost the external master.");
} }
handle->external_master_host.clear(); handle->external_master_host[0] = '\0';
handle->external_master_port = PORT_UNKNOWN; handle->external_master_port = PORT_UNKNOWN;
} }
} }
@ -2467,7 +2470,7 @@ monitorMain(void *arg)
* After updating the status of all servers, check if monitor events * After updating the status of all servers, check if monitor events
* need to be launched. * need to be launched.
*/ */
mon_process_state_changes(mon, handle->script.c_str(), handle->events); mon_process_state_changes(mon, handle->script, handle->events);
bool failover_performed = false; // Has an automatic failover been performed this loop? bool failover_performed = false; // Has an automatic failover been performed this loop?
if (handle->auto_failover) if (handle->auto_failover)
@ -3666,7 +3669,7 @@ bool start_external_replication(MYSQL_MONITOR* mon, MXS_MONITORED_SERVER* new_ma
mxs_mysql_query(new_master->con, "START SLAVE;") == 0) mxs_mysql_query(new_master->con, "START SLAVE;") == 0)
{ {
MXS_NOTICE("New master starting replication from external master %s:%d.", MXS_NOTICE("New master starting replication from external master %s:%d.",
mon->external_master_host.c_str(), mon->external_master_port); mon->external_master_host, mon->external_master_port);
rval = true; rval = true;
} }
else else

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#ifndef _MARIADBMON_H #ifndef _MYSQLMON_H
#define _MARIADBMON_H #define _MYSQLMON_H
/* /*
* Copyright (c) 2016 MariaDB Corporation Ab * Copyright (c) 2016 MariaDB Corporation Ab
* *
@ -15,65 +15,72 @@
*/ */
/** /**
* @file mysqlmon.hh - The MySQL monitor * @file mysqlmon.h - The MySQL monitor
*/ */
#include <maxscale/cppdefs.hh> #include <maxscale/cdefs.h>
#include <string> #include <stdio.h>
#include <stdlib.h>
#include <maxscale/config.h> #include <string.h>
#include <maxscale/dcb.h>
#include <maxscale/hashtable.h>
#include <maxscale/monitor.h> #include <maxscale/monitor.h>
#include <maxscale/spinlock.h>
#include <maxscale/thread.h> #include <maxscale/thread.h>
#include <mysql.h>
#include <mysqld_error.h>
#include <maxscale/log_manager.h>
#include <maxscale/secrets.h>
#include <maxscale/dcb.h>
#include <maxscale/modinfo.h>
#include <maxscale/config.h>
#include <maxscale/hashtable.h>
using std::string; MXS_BEGIN_DECLS
// MySQL Monitor module instance
class MYSQL_MONITOR /**
* The handle for an instance of a MySQL Monitor module
*/
typedef struct
{ {
public:
MXS_MONITOR* monitor; /**< Generic monitor object */
THREAD thread; /**< Monitor thread */ THREAD thread; /**< Monitor thread */
int shutdown; /**< Flag to shutdown the monitor thread */ int shutdown; /**< Flag to shutdown the monitor thread */
int status; /**< Monitor status */ int status; /**< Monitor status */
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
HASHTABLE *server_info; /**< Contains server specific information */
bool warn_set_standalone_master; /**< Log a warning when setting standalone master */
unsigned long id; /**< Monitor ID */ unsigned long id; /**< Monitor ID */
int replicationHeartbeat; /**< Monitor flag for MySQL replication heartbeat */
// Values updated by monitor
int64_t master_gtid_domain; /**< Gtid domain currently used by the master */
string external_master_host; /**< External master host, for fail/switchover */
int external_master_port; /**< External master port */
// Replication topology detection settings
bool mysql51_replication; /**< Use MySQL 5.1 replication */
bool detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */ bool detectStaleMaster; /**< Monitor flag for MySQL replication Stale Master detection */
bool detectStaleSlave; /**< Monitor flag for MySQL replication Stale Master detection */ bool detectStaleSlave; /**< Monitor flag for MySQL replication Stale Master detection */
bool multimaster; /**< Detect and handle multi-master topologies */ bool multimaster; /**< Detect and handle multi-master topologies */
bool ignore_external_masters; /**< Ignore masters outside of the monitor configuration */ bool ignore_external_masters; /**< Ignore masters outside of the monitor configuration */
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
bool mysql51_replication; /**< Use MySQL 5.1 replication */
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
char* script; /**< Script to call when state changes occur on servers */
uint64_t events; /**< enabled events */
HASHTABLE *server_info; /**< Contains server specific information */
bool detect_standalone_master; /**< If standalone master are detected */ bool detect_standalone_master; /**< If standalone master are detected */
bool replicationHeartbeat; /**< Monitor flag for MySQL replication heartbeat */ int failcount; /**< How many monitoring cycles servers must be
down before failover is initiated */
// Failover, switchover and rejoin settings bool allow_cluster_recovery; /**< Allow failed servers to rejoin the cluster */
string replication_user; /**< Replication user for CHANGE MASTER TO-commands */ bool warn_set_standalone_master; /**< Log a warning when setting standalone master */
string replication_password; /**< Replication password for CHANGE MASTER TO-commands */ bool auto_failover; /**< If automatic master failover is enabled */
int failcount; /**< How many monitoring cycles master must be down before auto-failover
* begins */
uint32_t failover_timeout; /**< Timeout in seconds for the master failover */ uint32_t failover_timeout; /**< Timeout in seconds for the master failover */
uint32_t switchover_timeout; /**< Timeout in seconds for the master switchover */ uint32_t switchover_timeout; /**< Timeout in seconds for the master switchover */
char* replication_user; /**< Replication user for failover */
char* replication_password; /**< Replication password for failover*/
bool verify_master_failure; /**< Whether master failure is verified via slaves */ bool verify_master_failure; /**< Whether master failure is verified via slaves */
int master_failure_timeout; /**< Master failure verification (via slaves) time in seconds */ int master_failure_timeout; /**< Time in seconds to wait before doing failover */
bool auto_failover; /**< If automatic master failover is enabled */ int64_t master_gtid_domain; /**< Gtid domain currently used by the master */
char external_master_host[MAX_SERVER_ADDRESS_LEN]; /**< External master host, for fail/switchover */
int external_master_port; /**< External master port */
bool auto_rejoin; /**< Attempt to start slave replication on standalone servers or servers bool auto_rejoin; /**< Attempt to start slave replication on standalone servers or servers
* replicating from the wrong master automatically. */ replicating from the wrong master. */
MXS_MONITORED_SERVER** excluded_servers; /**< Servers banned for master promotion during auto-failover. */
int n_excluded; /**< Number of excluded servers */ int n_excluded; /**< Number of excluded servers */
MXS_MONITORED_SERVER** excluded_servers; /**< Servers banned for master promotion during auto-failover. */
// Other settings MXS_MONITOR* monitor;
string script; /**< Script to call when state changes occur on servers */ } MYSQL_MONITOR;
uint64_t events; /**< enabled events */
bool allow_cluster_recovery; /**< Allow failed servers to rejoin the cluster */ MXS_END_DECLS
};
#endif #endif

View File

@ -17,7 +17,7 @@
#define MXS_MODULE_NAME "ndbclustermon" #define MXS_MODULE_NAME "ndbclustermon"
#include "ndbclustermon.h" #include "../mysqlmon.h"
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/mysql_utils.h> #include <maxscale/mysql_utils.h>
@ -103,7 +103,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
static void * static void *
startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params) startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
{ {
NDBC_MONITOR *handle = mon->handle; MYSQL_MONITOR *handle = mon->handle;
bool have_events = false, script_error = false; bool have_events = false, script_error = false;
if (handle != NULL) if (handle != NULL)
@ -113,7 +113,7 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
} }
else else
{ {
if ((handle = (NDBC_MONITOR *) MXS_MALLOC(sizeof(NDBC_MONITOR))) == NULL) if ((handle = (MYSQL_MONITOR *) MXS_MALLOC(sizeof(MYSQL_MONITOR))) == NULL)
{ {
return NULL; return NULL;
} }
@ -154,7 +154,7 @@ startMonitor(MXS_MONITOR *mon, const MXS_CONFIG_PARAMETER *params)
static void static void
stopMonitor(MXS_MONITOR *mon) stopMonitor(MXS_MONITOR *mon)
{ {
NDBC_MONITOR *handle = (NDBC_MONITOR *) mon->handle; MYSQL_MONITOR *handle = (MYSQL_MONITOR *) mon->handle;
handle->shutdown = 1; handle->shutdown = 1;
thread_wait(handle->thread); thread_wait(handle->thread);
@ -306,7 +306,7 @@ monitorDatabase(MXS_MONITORED_SERVER *database, char *defaultUser, char *default
static void static void
monitorMain(void *arg) monitorMain(void *arg)
{ {
NDBC_MONITOR *handle = (NDBC_MONITOR*)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR*)arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITORED_SERVER *ptr; MXS_MONITORED_SERVER *ptr;
size_t nrounds = 0; size_t nrounds = 0;

View File

@ -1,6 +1,5 @@
#pragma once #ifndef _MYSQLMON_H
#ifndef _NDBCMON_H #define _MYSQLMON_H
#define _NDBCMON_H
/* /*
* Copyright (c) 2016 MariaDB Corporation Ab * Copyright (c) 2016 MariaDB Corporation Ab
* *
@ -14,27 +13,39 @@
* Public License. * Public License.
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <monitor.h>
#include <spinlock.h>
#include <thread.h>
#include <mysql.h>
#include <mysqld_error.h>
#include <log_manager.h>
#include <secrets.h>
#include <dcb.h>
#include <modinfo.h>
#include <config.h>
#include <externcmd.h>
/** /**
* @file ndbclustermon.h - The NDB Cluster monitor * @file ndbclustermon.h - The NDB Cluster monitor
* *
*/ */
#include <maxscale/monitor.h> /**
#include <maxscale/spinlock.h> * The handle for an instance of a NDB Cluster Monitor module
#include <maxscale/thread.h> */
// The handle for an instance of a NDB Cluster Monitor module
typedef struct typedef struct
{ {
THREAD thread; /**< Monitor thread */
SPINLOCK lock; /**< The monitor spinlock */ SPINLOCK lock; /**< The monitor spinlock */
unsigned long id; /**< Monitor ID */ pthread_t tid; /**< id of monitor thread */
uint64_t events; /*< enabled events */
int shutdown; /**< Flag to shutdown the monitor thread */ int shutdown; /**< Flag to shutdown the monitor thread */
int status; /**< Monitor status */ int status; /**< Monitor status */
MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */ unsigned long id; /**< Monitor ID */
MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */ char* script; /*< Script to call when state changes occur on servers */
MXS_MONITOR* monitor; bool events[MAX_MONITOR_EVENT]; /*< enabled events */
} NDBC_MONITOR; } MYSQL_MONITOR;
#endif #endif

View File

@ -548,27 +548,20 @@ static inline bool connection_is_valid(ROUTER_INSTANCE* inst, ROUTER_CLIENT_SES*
if (SERVER_IS_RUNNING(router_cli_ses->backend->server) && if (SERVER_IS_RUNNING(router_cli_ses->backend->server) &&
(router_cli_ses->backend->server->status & inst->bitmask & inst->bitvalue)) (router_cli_ses->backend->server->status & inst->bitmask & inst->bitvalue))
{ {
if (inst->bitvalue & SERVER_MASTER) if ((inst->bitvalue & SERVER_MASTER) && router_cli_ses->backend->active)
{ {
SERVER_REF* master = get_root_master(inst->service->dbref); // If we're using an active master server, verify that it is still a master
if (master)
{
/** Check that the master we are connected to and the one we
* determined from the replication topology are one and the same */
rval = router_cli_ses->backend == get_root_master(inst->service->dbref); rval = router_cli_ses->backend == get_root_master(inst->service->dbref);
} }
else else
{ {
/** No master is available but the one we are connected to is /**
* still a master. This most likely means that the servers for * Either we don't use master type servers or the server reference
* the service have been modified at runtime. */ * is deactivated. We let deactivated connection close gracefully
rval = true; * so we simply assume it is OK. This allows a server to be taken
} * out of use in a manner that won't cause errors to the connected
} * clients.
else */
{
// Not a master and bitmask check is OK, everything is OK
rval = true; rval = true;
} }
} }

View File

@ -174,12 +174,13 @@ log_transaction_status(RWSplitSession *rses, GWBUF *querybuf, uint32_t qtype)
MXS_SESSION *ses = rses->client_dcb->session; MXS_SESSION *ses = rses->client_dcb->session;
const char *autocommit = session_is_autocommit(ses) ? "[enabled]" : "[disabled]"; const char *autocommit = session_is_autocommit(ses) ? "[enabled]" : "[disabled]";
const char *transaction = session_trx_is_active(ses) ? "[open]" : "[not open]"; const char *transaction = session_trx_is_active(ses) ? "[open]" : "[not open]";
uint32_t plen = MYSQL_GET_PACKET_LEN(querybuf);
const char *querytype = qtypestr == NULL ? "N/A" : qtypestr; const char *querytype = qtypestr == NULL ? "N/A" : qtypestr;
const char *hint = querybuf->hint == NULL ? "" : ", Hint:"; const char *hint = querybuf->hint == NULL ? "" : ", Hint:";
const char *hint_type = querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type); const char *hint_type = querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type);
MXS_INFO("> Autocommit: %s, trx is %s, cmd: (0x%02x) %s, type: %s, stmt: %.*s%s %s", MXS_INFO("> Autocommit: %s, trx is %s, cmd: (0x%02x) %s, plen: %u, type: %s, pastmt: %.*s%s %s",
autocommit, transaction, command, STRPACKETTYPE(command), autocommit, transaction, command, STRPACKETTYPE(command), plen,
querytype, len, sql, hint, hint_type); querytype, len, sql, hint, hint_type);
MXS_FREE(qtypestr); MXS_FREE(qtypestr);

View File

@ -835,10 +835,10 @@ handle_multi_temp_and_load(RWSplitSession *rses, GWBUF *querybuf,
/** /**
* Check if the query has anything to do with temporary tables. * Check if the query has anything to do with temporary tables.
*/ */
if (rses->have_tmp_tables) if (rses->have_tmp_tables && is_packet_a_query(packet_type))
{ {
check_drop_tmp_table(rses, querybuf); check_drop_tmp_table(rses, querybuf);
if (is_packet_a_query(packet_type) && is_read_tmp_table(rses, querybuf, *qtype)) if (is_read_tmp_table(rses, querybuf, *qtype))
{ {
*qtype |= QUERY_TYPE_MASTER_READ; *qtype |= QUERY_TYPE_MASTER_READ;
} }