diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 1e3009b7a..b1e87fdbe 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -613,6 +613,10 @@ add_test_executable(mxs1507_inconsistent_trx.cpp mxs1507_inconsistent_trx mxs150 # 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-1507: Transaction replay +# https://jira.mariadb.org/browse/MXS-1507 +add_test_executable(mxs1507_trx_stress.cpp mxs1507_trx_stress mxs1507_trx_stress 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) diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs1507_trx_stress b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1507_trx_stress new file mode 100644 index 000000000..b3d120c27 --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs1507_trx_stress @@ -0,0 +1,63 @@ +[maxscale] +threads=###threads### +log_info=1 + +[MySQL Monitor] +type=monitor +module=mysqlmon +servers=server1,server2,server3,server4 +user=maxskysql +passwd=skysql +monitor_interval=1000 +backend_connect_timeout=1 +backend_read_timeout=1 + + +[RW Split Router] +type=service +router=readwritesplit +servers=server1,server2,server3,server4 +user=maxskysql +passwd=skysql +transaction_replay=true +delayed_retry_timeout=30 + +[RW Split Listener] +type=listener +service=RW Split Router +protocol=MySQLClient +port=4006 + +[CLI] +type=service +router=cli + +[CLI Listener] +type=listener +service=CLI +protocol=maxscaled +socket=default + +[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 diff --git a/maxscale-system-test/mxs1507_trx_stress.cpp b/maxscale-system-test/mxs1507_trx_stress.cpp new file mode 100644 index 000000000..2edf35977 --- /dev/null +++ b/maxscale-system-test/mxs1507_trx_stress.cpp @@ -0,0 +1,87 @@ +/** + * MXS-1507: Transaction replay stress test + * + * https://jira.mariadb.org/browse/MXS-1507 + */ +#include "testconnections.h" +#include +#include +#include +#include + +using namespace std; + +atomic running{true}; + +void client_thr(TestConnections* test, int id) +{ + MYSQL* conn = test->maxscales->open_rwsplit_connection(); + + while (running && test->global_result == 0) + { + test->try_query(conn, "START TRANSACTION"); + test->try_query(conn, "INSERT INTO test.t1 (a) VALUES (%d)", id); + int last_id = mysql_insert_id(conn); + test->try_query(conn, "UPDATE test.t1 SET a = -1 WHERE id = %d", last_id); + test->try_query(conn, "COMMIT", id); + test->try_query(conn, "DELETE FROM test.t1 WHERE id = %d", last_id); + sleep(1); + } + + mysql_close(conn); +} + +int main(int argc, char** argv) +{ + Mariadb_nodes::require_gtid(true); + TestConnections test(argc, argv); + + test.repl->connect(); + + cout << "Creating table" << endl; + test.try_query(test.repl->nodes[0], "CREATE OR REPLACE TABLE " + "test.t1 (id int, a int)"); + + cout << "Syncing slaves" << endl; + test.repl->sync_slaves(); + + + cout << "Starting threads" << endl; + const int N_THREADS = 1; + vector threads; + + for (int i = 0; i < N_THREADS; i++) + { + threads.emplace_back(client_thr, &test, i); + } + + for (int i = 0; i < 5; i++) + { + sleep(10); + test.repl->block_node(0); + sleep(10); + test.repl->unblock_node(0); + } + + cout << "Stopping threads" << endl; + running = false; + + // Should be plenty of time for the threads to stop + test.set_timeout(60); + + for (auto& a : threads) + { + a.join(); + } + + test.stop_timeout(); + + test.repl->fix_replication(); + + test.repl->connect(); + execute_query_silent(test.repl->nodes[0], "DROP TABLE test.t1"); + execute_query_silent(test.repl->nodes[0], "DROP USER 'testuser'@'%'"); + test.repl->disconnect(); + + return test.global_result; +}