From 2f8bb71a581d9f6dce2830f672913e87a0abcbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 27 Apr 2018 13:25:33 +0300 Subject: [PATCH] MXS-1507: Test resultset checksum functionality The test verifies that different results returned by the replayed transaction cause the replaying to be aborted. --- maxscale-system-test/CMakeLists.txt | 4 ++ .../mxs1507_inconsistent_trx.cpp | 63 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 maxscale-system-test/mxs1507_inconsistent_trx.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index b9521bbcf..10afe9eb1 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -617,6 +617,10 @@ add_test_executable(mxs1506_no_master.cpp mxs1506_no_master mxs1506_delayed_retr # https://jira.mariadb.org/browse/MXS-1507 add_test_executable(mxs1507_trx_replay.cpp mxs1507_trx_replay mxs1507_trx_replay LABELS readwritesplit REPL_BACKEND) +# MXS-1507: Inconsistent transactions +# 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-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/mxs1507_inconsistent_trx.cpp b/maxscale-system-test/mxs1507_inconsistent_trx.cpp new file mode 100644 index 000000000..d2c943961 --- /dev/null +++ b/maxscale-system-test/mxs1507_inconsistent_trx.cpp @@ -0,0 +1,63 @@ +/** + * MXS-1507: Test inconsistent result detection + * + * https://jira.mariadb.org/browse/MXS-1507 + */ +#include "testconnections.h" +#include +#include +#include + +using namespace std; + +int main(int argc, char** argv) +{ + TestConnections test(argc, argv); + + 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 err = [&](string q) + { + test.assert(!query(q), "Query should not work: %s", q.c_str()); + }; + + // Create a table and insert one value + test.maxscales->connect(); + ok("CREATE OR REPLACE TABLE test.t1 (id INT)"); + ok("INSERT INTO test.t1 VALUES (1)"); + + // Make sure it's replicated to all slaves before starting the transaction + test.repl->connect(); + test.repl->sync_slaves(); + + // Read the inserted value inside a read-only transaction + ok("START TRANSACTION READ ONLY"); + ok("SELECT * FROM test.t1"); + + // Modify the related data mid-transaction + execute_query(test.repl->nodes[0], "INSERT INTO test.t1 VALUES (2)"); + test.repl->sync_slaves(); + test.repl->disconnect(); + + // Block the node where the transaction is active + test.repl->block_node(1); + sleep(5); + + // The checksums for the results should conflict causing the replay to fail + err("COMMIT"); + test.maxscales->disconnect(); + + test.maxscales->connect(); + ok("DROP TABLE test.t1"); + test.maxscales->disconnect(); + + return test.global_result; +}