Merge branch '2.3' into develop
This commit is contained in:
@ -913,6 +913,12 @@ add_test_executable(mxs2115_version_string.cpp mxs2115_version_string replicatio
|
||||
# MXS-2273: Introduce server state BEING_DRAINED
|
||||
add_test_executable(mxs2273_being_drained.cpp mxs2273_being_drained mxs2273_being_drained LABELS REPL_BACKEND)
|
||||
|
||||
# MXS-2295: COM_CHANGE_USER does not clear out session command history
|
||||
add_test_executable(mxs2295_change_user_loop.cpp mxs2295_change_user_loop mxs2295_change_user_loop LABELS REPL_BACKEND)
|
||||
|
||||
# MXS-2300: Prune session command history
|
||||
add_test_executable(mxs2300_history_pruning.cpp mxs2300_history_pruning mxs2300_history_pruning LABELS REPL_BACKEND)
|
||||
|
||||
############################################
|
||||
# BEGIN: binlogrouter and avrorouter tests #
|
||||
############################################
|
||||
|
||||
50
maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop
Executable file
50
maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop
Executable file
@ -0,0 +1,50 @@
|
||||
[maxscale]
|
||||
threads=###threads###
|
||||
log_info=1
|
||||
|
||||
[server1]
|
||||
type=server
|
||||
address=###node_server_IP_1###
|
||||
port=###node_server_port_1###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server2]
|
||||
type=server
|
||||
address=###node_server_IP_2###
|
||||
port=###node_server_port_2###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server3]
|
||||
type=server
|
||||
address=###node_server_IP_3###
|
||||
port=###node_server_port_3###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server4]
|
||||
type=server
|
||||
address=###node_server_IP_4###
|
||||
port=###node_server_port_4###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[MySQL Monitor]
|
||||
type=monitor
|
||||
module=mysqlmon
|
||||
servers=server1,server2,server3,server4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
monitor_interval=1000
|
||||
|
||||
[RW Split Router]
|
||||
type=service
|
||||
router=readwritesplit
|
||||
servers=server1,server2,server3,server4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
max_sescmd_history=20
|
||||
disable_sescmd_history=false
|
||||
|
||||
[RW Split Listener]
|
||||
type=listener
|
||||
service=RW Split Router
|
||||
protocol=MySQLClient
|
||||
port=4006
|
||||
51
maxscale-system-test/cnf/maxscale.cnf.template.mxs2300_history_pruning
Executable file
51
maxscale-system-test/cnf/maxscale.cnf.template.mxs2300_history_pruning
Executable file
@ -0,0 +1,51 @@
|
||||
[maxscale]
|
||||
threads=###threads###
|
||||
log_info=1
|
||||
|
||||
[server1]
|
||||
type=server
|
||||
address=###node_server_IP_1###
|
||||
port=###node_server_port_1###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server2]
|
||||
type=server
|
||||
address=###node_server_IP_2###
|
||||
port=###node_server_port_2###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server3]
|
||||
type=server
|
||||
address=###node_server_IP_3###
|
||||
port=###node_server_port_3###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[server4]
|
||||
type=server
|
||||
address=###node_server_IP_4###
|
||||
port=###node_server_port_4###
|
||||
protocol=MySQLBackend
|
||||
|
||||
[MySQL Monitor]
|
||||
type=monitor
|
||||
module=mysqlmon
|
||||
servers=server1,server2,server3,server4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
monitor_interval=1000
|
||||
|
||||
[RW Split Router]
|
||||
type=service
|
||||
router=readwritesplit
|
||||
servers=server1,server2,server3,server4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
max_sescmd_history=10
|
||||
prune_sescmd_history=true
|
||||
max_slave_connections=1
|
||||
|
||||
[RW Split Listener]
|
||||
type=listener
|
||||
service=RW Split Router
|
||||
protocol=MySQLClient
|
||||
port=4006
|
||||
@ -18,6 +18,7 @@ servers=server1, server2, server3, server4
|
||||
user=maxskysql
|
||||
password=skysql
|
||||
slave_selection_criteria=LEAST_ROUTER_CONNECTIONS
|
||||
max_slave_replication_lag=1
|
||||
|
||||
[Read-Connection-Router-Slave]
|
||||
type=service
|
||||
|
||||
@ -334,6 +334,16 @@ public:
|
||||
return mysql_error(m_conn);
|
||||
}
|
||||
|
||||
bool change_user(std::string user, std::string pw, std::string db = "test")
|
||||
{
|
||||
return mysql_change_user(m_conn, user.c_str(), pw.c_str(), db.c_str()) == 0;
|
||||
}
|
||||
|
||||
bool reset_connection()
|
||||
{
|
||||
return change_user(m_user, m_pw, m_db);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_host;
|
||||
int m_port;
|
||||
|
||||
@ -936,6 +936,18 @@ std::string Mariadb_nodes::get_server_id_str(int index)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::vector<int> Mariadb_nodes::get_all_server_ids()
|
||||
{
|
||||
std::vector<int> rval;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
rval.push_back(get_server_id(i));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool do_flush_hosts(MYSQL* conn)
|
||||
{
|
||||
int local_result = 0;
|
||||
|
||||
@ -316,6 +316,13 @@ public:
|
||||
int get_server_id(int index);
|
||||
std::string get_server_id_str(int index);
|
||||
|
||||
/**
|
||||
* Get server IDs of all servers
|
||||
*
|
||||
* @return List of server IDs
|
||||
*/
|
||||
std::vector<int> get_all_server_ids();
|
||||
|
||||
/**
|
||||
* @brief Execute 'mysqladmin flush-hosts' on all nodes
|
||||
* @return 0 in case of success
|
||||
|
||||
@ -196,7 +196,7 @@ int main(int argc, char** argv)
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"),
|
||||
},
|
||||
{
|
||||
bind(err, "SELECT 7"),
|
||||
bind(err, "SELECT 8"),
|
||||
bind(err, "COMMIT"),
|
||||
},
|
||||
{
|
||||
@ -252,9 +252,9 @@ int main(int argc, char** argv)
|
||||
|
||||
// Block and unblock the master
|
||||
test.repl->block_node(0);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
test.repl->unblock_node(0);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
|
||||
for (auto& f : a.post)
|
||||
{
|
||||
|
||||
66
maxscale-system-test/mxs2295_change_user_loop.cpp
Normal file
66
maxscale-system-test/mxs2295_change_user_loop.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* MXS-2295: COM_CHANGE_USER does not clear out session command history
|
||||
* https://jira.mariadb.org/browse/MXS-2295
|
||||
*/
|
||||
|
||||
#include "testconnections.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
|
||||
|
||||
Connection conn = test.maxscales->rwsplit();
|
||||
test.expect(conn.connect(), "Connection failed: %s", conn.error());
|
||||
|
||||
for (int i = 0; i <= 300 && test.global_result == 0; i++)
|
||||
{
|
||||
if (i % 50 == 0)
|
||||
{
|
||||
test.tprintf("Iteration: %d", i);
|
||||
}
|
||||
|
||||
test.set_timeout(60);
|
||||
|
||||
// Interleaved session commands, reads and "writes" (`SELECT @@last_insert_id` is treated as a master-only read)
|
||||
test.expect(conn.query("SET @a = 1"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("USE test"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("SET SQL_MODE=''"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("USE test"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("SELECT @@last_insert_id"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("SELECT 1"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("USE test"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("SELECT 1"), "Query failed: %s", conn.error());
|
||||
|
||||
// User variable inside transaction
|
||||
test.expect(conn.query("SET @a = 123"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("BEGIN"), "Query failed: %s", conn.error());
|
||||
Row row = conn.row("SELECT @a");
|
||||
test.expect(!row.empty() && row[0] == "123", "Invalid contents in user variable inside RW trx");
|
||||
test.expect(conn.query("COMMIT"), "Query failed: %s", conn.error());
|
||||
|
||||
// User variable outside transaction
|
||||
test.expect(conn.query("SET @a = 321"), "Query failed: %s", conn.error());
|
||||
row = conn.row("SELECT @a");
|
||||
test.expect(!row.empty() && row[0] == "321", "Invalid contents in user variable outside trx");
|
||||
|
||||
// User variable inside read-only transaction
|
||||
test.expect(conn.query("SET @a = 456"), "Query failed: %s", conn.error());
|
||||
test.expect(conn.query("START TRANSACTION READ ONLY"), "Query failed: %s", conn.error());
|
||||
row = conn.row("SELECT @a");
|
||||
test.expect(!row.empty() && row[0] == "456", "Invalid contents in user variable inside RO trx");
|
||||
test.expect(conn.query("COMMIT"), "Query failed: %s", conn.error());
|
||||
|
||||
test.expect(conn.query("PREPARE ps FROM 'SELECT 1'"), "PREPARE failed: %s", conn.error());
|
||||
row = conn.row("EXECUTE ps");
|
||||
test.expect(!row.empty() && row[0] == "1", "Invalid contents in PS result");
|
||||
test.expect(conn.query("DEALLOCATE PREPARE ps"), "DEALLOCATE failed: %s", conn.error());
|
||||
|
||||
test.expect(conn.reset_connection(), "Connection reset failed: %s", conn.error());
|
||||
}
|
||||
|
||||
test.log_excludes(0, "Router session exceeded session command history limit");
|
||||
test.log_includes(0, "Resetting session command history");
|
||||
|
||||
return test.global_result;
|
||||
}
|
||||
109
maxscale-system-test/mxs2300_history_pruning.cpp
Normal file
109
maxscale-system-test/mxs2300_history_pruning.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/**
|
||||
* MXS-2300: Session command history pruning
|
||||
*/
|
||||
|
||||
#include "testconnections.h"
|
||||
#include <sstream>
|
||||
|
||||
std::vector<int> ids;
|
||||
|
||||
void block_by_id(TestConnections& test, int id)
|
||||
{
|
||||
for (size_t i = 0; i < ids.size(); i++)
|
||||
{
|
||||
if (ids[i] == id)
|
||||
{
|
||||
test.repl->block_node(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unblock_by_id(TestConnections& test, int id)
|
||||
{
|
||||
for (size_t i = 0; i < ids.size(); i++)
|
||||
{
|
||||
if (ids[i] == id)
|
||||
{
|
||||
test.repl->unblock_node(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
|
||||
test.repl->connect();
|
||||
ids = test.repl->get_all_server_ids();
|
||||
test.repl->disconnect();
|
||||
|
||||
int master_id = test.get_master_server_id();
|
||||
Connection conn = test.maxscales->rwsplit();
|
||||
test.expect(conn.connect(), "Connection failed: %s", conn.error());
|
||||
|
||||
test.tprintf("Get the ID of the server we first start with");
|
||||
int first_id = std::stoi(conn.field("SELECT @@server_id"));
|
||||
|
||||
test.tprintf("The history size is set to 10 commands, execute five and check that they are retained");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
std::stringstream query;
|
||||
query << "SET @a" << i << " = " << i;
|
||||
conn.query(query.str());
|
||||
}
|
||||
|
||||
block_by_id(test, first_id);
|
||||
test.maxscales->wait_for_monitor();
|
||||
|
||||
int second_id = std::stoi(conn.field("SELECT @@server_id"));
|
||||
|
||||
test.tprintf("Make sure that a reconnection actually took place");
|
||||
test.expect(first_id != second_id && second_id > 0, "Invalid server ID: %d", second_id);
|
||||
test.expect(master_id != second_id, "SELECT should not go to the master");
|
||||
|
||||
test.tprintf("Check that the values were correctly set");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
std::string value = std::to_string(i);
|
||||
std::string query = "SELECT @a" + value;
|
||||
test.expect(conn.check(query, value), "Invalid value for user variable @a%s", value.c_str());
|
||||
}
|
||||
|
||||
unblock_by_id(test, first_id);
|
||||
|
||||
test.tprintf("Execute 15 commands and check that we lose the first five values");
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
std::stringstream query;
|
||||
query << "SET @b" << i << " =" << i;
|
||||
conn.query(query.str());
|
||||
}
|
||||
|
||||
block_by_id(test, second_id);
|
||||
test.maxscales->wait_for_monitor();
|
||||
|
||||
int third_id = std::stoi(conn.field("SELECT @@server_id"));
|
||||
|
||||
test.expect(third_id != second_id && third_id > 0, "Invalid server ID: %d", third_id);
|
||||
test.expect(master_id != third_id, "SELECT should not go to the master");
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
std::string variable = "@b" + std::to_string(i);
|
||||
std::string query = "SELECT IFNULL(" + variable + ", '" + variable + " is null')";
|
||||
test.expect(conn.check(query, variable + " is null"), "%s should not be set", variable.c_str());
|
||||
}
|
||||
|
||||
test.tprintf("Check that the remaining values were correctly set");
|
||||
for (int i = 5; i < 15; i++)
|
||||
{
|
||||
std::string value = std::to_string(i);
|
||||
std::string query = "SELECT @b" + value;
|
||||
std::string f = conn.field(query);
|
||||
test.expect(conn.check(query, value), "Invalid value for user variable @b%s: %s", value.c_str(), f.c_str());
|
||||
}
|
||||
|
||||
unblock_by_id(test, second_id);
|
||||
|
||||
return test.global_result;
|
||||
}
|
||||
@ -201,8 +201,6 @@ int main(int argc, char* argv[])
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
auto maxconn = test.maxscales->open_rwsplit_connection();
|
||||
test.try_query(maxconn, "FLUSH TABLES;");
|
||||
mysql_close(maxconn);
|
||||
|
||||
test.maxscales->wait_for_monitor(1);
|
||||
|
||||
check_status(test, "server1", mm_master_states);
|
||||
@ -214,6 +212,10 @@ int main(int argc, char* argv[])
|
||||
check_group(test, "server3", 1);
|
||||
check_group(test, "server4", 0);
|
||||
check_rlag(test, "server4", 1, max_rlag);
|
||||
// Need to send a read query so that rwsplit detects replication lag.
|
||||
test.try_query(maxconn, "SHOW DATABASES;");
|
||||
mysql_close(maxconn);
|
||||
test.log_includes(0, "is excluded from query routing.");
|
||||
|
||||
test.tprintf("Test 2 - Set nodes 0 and 1 into read-only mode");
|
||||
|
||||
@ -328,7 +330,6 @@ int main(int argc, char* argv[])
|
||||
test.maxscales->wait_for_monitor(1);
|
||||
maxconn = test.maxscales->open_rwsplit_connection();
|
||||
test.try_query(maxconn, "FLUSH TABLES;");
|
||||
mysql_close(maxconn);
|
||||
test.maxscales->wait_for_monitor(1);
|
||||
|
||||
check_status(test, "server1", slave_states);
|
||||
@ -349,6 +350,10 @@ int main(int argc, char* argv[])
|
||||
|
||||
check_status(test, "server1", slave_states);
|
||||
check_rlag(test, "server1", 0, 0);
|
||||
// Rwsplit should detects that replication lag is 0.
|
||||
test.try_query(maxconn, "SHOW DATABASES;");
|
||||
mysql_close(maxconn);
|
||||
test.log_includes(0, "is returned to query routing.");
|
||||
|
||||
// Test over, reset topology.
|
||||
const char reset_with_name[] = "STOP SLAVE '%s'; RESET SLAVE '%s' ALL;";
|
||||
|
||||
Reference in New Issue
Block a user