MXS-1507: Test transaction replay with switchover
Added a test case that verifies that a successful transaction replay is performed when a master switchover is performed.
This commit is contained in:
parent
ff8a7c8b93
commit
9ef1ffa878
@ -621,6 +621,10 @@ add_test_executable(mxs1507_trx_replay.cpp mxs1507_trx_replay mxs1507_trx_replay
|
||||
# https://jira.mariadb.org/browse/MXS-1507
|
||||
add_test_executable(mxs1507_inconsistent_trx.cpp mxs1507_inconsistent_trx mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND)
|
||||
|
||||
# MXS-1507: Transaction migration
|
||||
# https://jira.mariadb.org/browse/MXS-1507
|
||||
add_test_executable(mxs1507_migrate_trx.cpp mxs1507_migrate_trx mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND)
|
||||
|
||||
# MXS-1509: Show correct server state for multisource replication
|
||||
# https://jira.mariadb.org/browse/MXS-1509
|
||||
add_test_executable(mxs1509.cpp mxs1509 mxs1509 LABELS mysqlmon REPL_BACKEND)
|
||||
|
90
maxscale-system-test/mxs1507_migrate_trx.cpp
Normal file
90
maxscale-system-test/mxs1507_migrate_trx.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* MXS-1507: Test migration of transactions
|
||||
*
|
||||
* https://jira.mariadb.org/browse/MXS-1507
|
||||
*/
|
||||
#include "testconnections.h"
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Mariadb_nodes::require_gtid(true);
|
||||
TestConnections test(argc, argv);
|
||||
string master = "server1";
|
||||
string slave = "server2";
|
||||
|
||||
auto switchover = [&]()
|
||||
{
|
||||
test.maxscales->ssh_node_f(0, true, "maxctrl call command mariadbmon switchover MySQL-Monitor %s %s",
|
||||
master.c_str(), slave.c_str());
|
||||
master.swap(slave);
|
||||
sleep(5); // Seems that the system needs a few seconds to stabilize
|
||||
};
|
||||
|
||||
auto query = [&](string q)
|
||||
{
|
||||
return execute_query_silent(test.maxscales->conn_rwsplit[0], q.c_str()) == 0;
|
||||
};
|
||||
|
||||
auto ok = [&](string q)
|
||||
{
|
||||
test.assert(query(q), "Query '%s' should work: %s", q.c_str(), mysql_error(test.maxscales->conn_rwsplit[0]));
|
||||
};
|
||||
|
||||
auto check = [&](string q)
|
||||
{
|
||||
ok("START TRANSACTION");
|
||||
Row row = get_row(test.maxscales->conn_rwsplit[0], q.c_str());
|
||||
ok("COMMIT");
|
||||
test.assert(!row.empty() && row[0] == "1", "Query should return 1: %s", q.c_str());
|
||||
};
|
||||
|
||||
// Create a table, insert a value and make sure it's replicated to all slaves
|
||||
test.maxscales->connect();
|
||||
ok("CREATE OR REPLACE TABLE test.t1 (id INT)");
|
||||
ok("INSERT INTO test.t1 VALUES (1)");
|
||||
test.repl->connect();
|
||||
test.repl->sync_slaves();
|
||||
test.maxscales->disconnect();
|
||||
|
||||
cout << "Commit transaction" << endl;
|
||||
test.maxscales->connect();
|
||||
ok("START TRANSACTION");
|
||||
ok("SELECT id FROM test.t1 WHERE id = 1 FOR UPDATE");
|
||||
switchover();
|
||||
ok("UPDATE test.t1 SET id = 2 WHERE id = 1");
|
||||
ok("COMMIT");
|
||||
check("SELECT COUNT(*) = 1 FROM t1 WHERE id = 2");
|
||||
|
||||
test.maxscales->disconnect();
|
||||
|
||||
cout << "Rollback transaction" << endl;
|
||||
test.maxscales->connect();
|
||||
ok("START TRANSACTION");
|
||||
ok("UPDATE test.t1 SET id = 1");
|
||||
switchover();
|
||||
ok("ROLLBACK");
|
||||
check("SELECT COUNT(*) = 1 FROM t1 WHERE id = 2");
|
||||
test.maxscales->disconnect();
|
||||
|
||||
cout << "Read-only transaction" << endl;
|
||||
test.maxscales->connect();
|
||||
ok("START TRANSACTION READ ONLY");
|
||||
ok("SELECT @@server_id"); // This causes a checksum mismatch if the transaction is migrated
|
||||
switchover();
|
||||
ok("COMMIT");
|
||||
test.maxscales->disconnect();
|
||||
|
||||
test.maxscales->connect();
|
||||
ok("DROP TABLE test.t1");
|
||||
test.maxscales->disconnect();
|
||||
|
||||
// Even number of switchovers should bring us back to the original master
|
||||
switchover();
|
||||
|
||||
return test.global_result;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user