Fix mysqlmon_external_master
Removed unneeded operations, added comments and cleanup. The test requires a larger rework to be more useful.
This commit is contained in:
parent
2e589e0328
commit
db6a187cd3
@ -2,36 +2,34 @@
|
||||
* Test monitoring and failover with ignore_external_masters=true
|
||||
*/
|
||||
#include "testconnections.h"
|
||||
|
||||
#include "fail_switch_rejoin_common.cpp"
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#define DOWN "Down"
|
||||
#define RUNNING "Running"
|
||||
#define MASTER "Master"
|
||||
#define SLAVE "Slave"
|
||||
const char DOWN[] = "Down";
|
||||
const char RUNNING[] = "Running";
|
||||
const char MASTER[] = "Master";
|
||||
const char SLAVE[] = "Slave";
|
||||
|
||||
const StringSet master_running = {MASTER, RUNNING};
|
||||
const StringSet slave_running = {SLAVE, RUNNING};
|
||||
const StringSet running = {RUNNING};
|
||||
const StringSet down = {DOWN};
|
||||
|
||||
static std::atomic<bool> is_running(true);
|
||||
|
||||
void check_status(TestConnections& test, const char* server, const StringSet& expected, const char* message)
|
||||
{
|
||||
StringSet state = test.get_server_status(server);
|
||||
test.expect(state == expected, "%s: %s", message, dump_status(state, expected).c_str());
|
||||
}
|
||||
|
||||
static bool is_running = true;
|
||||
|
||||
void writer_func(TestConnections* test)
|
||||
{
|
||||
while (is_running)
|
||||
{
|
||||
MYSQL* conn = open_conn(test->maxscales->rwsplit_port[0],
|
||||
test->maxscales->IP[0],
|
||||
"test",
|
||||
"test",
|
||||
false);
|
||||
MYSQL* conn = open_conn(test->maxscales->rwsplit_port[0], test->maxscales->IP[0],
|
||||
"test", "test", false);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
@ -41,7 +39,6 @@ void writer_func(TestConnections* test)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mysql_close(conn);
|
||||
}
|
||||
}
|
||||
@ -50,52 +47,59 @@ int main(int argc, char** argv)
|
||||
{
|
||||
Mariadb_nodes::require_gtid(true);
|
||||
TestConnections test(argc, argv);
|
||||
test.repl->connect();
|
||||
delete_slave_binlogs(test);
|
||||
|
||||
// Create a table and a user and start a thread that does writes
|
||||
test.repl->connect();
|
||||
execute_query(test.repl->nodes[0], "CREATE OR REPLACE TABLE test.t1 (id INT)");
|
||||
execute_query(test.repl->nodes[0], "DROP USER IF EXISTS 'test'@'%%'");
|
||||
execute_query(test.repl->nodes[0], "CREATE USER 'test'@'%%' IDENTIFIED BY 'test'");
|
||||
execute_query(test.repl->nodes[0], "GRANT INSERT, SELECT, UPDATE, DELETE ON *.* TO 'test'@'%%'");
|
||||
MYSQL* node0 = test.repl->nodes[0];
|
||||
execute_query(node0, "CREATE OR REPLACE TABLE test.t1 (id INT)");
|
||||
execute_query(node0, "DROP USER IF EXISTS 'test'@'%%'");
|
||||
execute_query(node0, "CREATE USER 'test'@'%%' IDENTIFIED BY 'test'");
|
||||
execute_query(node0, "GRANT INSERT, SELECT, UPDATE, DELETE ON *.* TO 'test'@'%%'");
|
||||
test.repl->sync_slaves();
|
||||
std::thread thr(writer_func, &test);
|
||||
|
||||
test.tprintf("Start by having the current master replicate from the external server");
|
||||
test.repl->connect();
|
||||
test.tprintf("Start by having the current master replicate from the external server.");
|
||||
test.repl->replicate_from(0, 3);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(1);
|
||||
check_status(test, "server1", master_running, "server1 should be the master");
|
||||
check_status(test, "server2", slave_running, "server2 should be a slave");
|
||||
check_status(test, "server3", slave_running, "server3 should be a slave");
|
||||
|
||||
test.tprintf("Stop server1, expect server2 to be promoted as the master");
|
||||
test.repl->stop_node(0);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
|
||||
check_status(test, "server1", down, "server1 should be down");
|
||||
check_status(test, "server2", master_running, "server2 should be the master");
|
||||
check_status(test, "server3", slave_running, "server3 should be a slave");
|
||||
|
||||
test.tprintf("Configure master-master replication between server2 and the external server");
|
||||
test.repl->replicate_from(1, 3);
|
||||
// Comment away next line since failover already created the external connection. Failover/switchover
|
||||
// does not respect 'ignore_external_master' when copying slave connections. Whether it should do it
|
||||
// is questionable.
|
||||
// TODO: Think about what to do with this test and the setting in general.
|
||||
// test.repl->replicate_from(1, 3);
|
||||
test.repl->replicate_from(3, 1);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(1);
|
||||
check_status(test, "server2", master_running, "server2 should still be the master");
|
||||
check_status(test, "server3", slave_running, "server3 should be a slave");
|
||||
|
||||
test.tprintf("Start server1, expect it to rejoin the cluster");
|
||||
// The rejoin should redirect the existing external master connection in server1.
|
||||
test.repl->start_node(0);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
check_status(test, "server1", slave_running, "server1 should be a slave");
|
||||
check_status(test, "server2", master_running, "server2 should still be the master");
|
||||
check_status(test, "server3", slave_running, "server3 should be a slave");
|
||||
|
||||
test.tprintf("Stop server2, expect server1 to be promoted as the master");
|
||||
test.repl->stop_node(1);
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
test.repl->connect();
|
||||
test.repl->replicate_from(0, 3);
|
||||
// Same as before.
|
||||
// test.repl->replicate_from(0, 3);
|
||||
test.repl->replicate_from(3, 0);
|
||||
test.maxscales->wait_for_monitor();
|
||||
|
||||
check_status(test, "server1", master_running, "server1 should be the master");
|
||||
check_status(test, "server2", down, "server2 should be down");
|
||||
@ -103,7 +107,7 @@ int main(int argc, char** argv)
|
||||
|
||||
test.tprintf("Start server2, expect it to rejoin the cluster");
|
||||
test.repl->start_node(1);
|
||||
test.maxscales->wait_for_monitor();
|
||||
test.maxscales->wait_for_monitor(2);
|
||||
check_status(test, "server1", master_running, "server1 should still be the master");
|
||||
check_status(test, "server2", slave_running, "server2 should be a slave");
|
||||
check_status(test, "server3", slave_running, "server3 should be a slave");
|
||||
|
Loading…
x
Reference in New Issue
Block a user