MaxScale/maxscale-system-test/mxs1503_master_reconnection.cpp
Markus Mäkelä 876187b340
MXS-1503: Enable master reconnection
The `master_reconnection` parameter now controls both the reconnection of
the master server as well as the migration of the master server to another
server. Although these two cases appear to be different, the end result
from readwritesplit's point of view is the same and are thus controlled
with the same parameter.

The RWBackend class now resets its internal state when it is closed. This
allows readwritesplit to handle the case when a result was expected from
the master but the master died before the result was returned. The same
code should also handle slave connection failures mid-result, allowing
Backend reuse.

Added a test case that verifies the new functionality when combined with
`master_failure_mode=error_on_write`.
2018-04-03 13:30:51 +03:00

64 lines
1.7 KiB
C++

/**
* MXS-1503: Testing of master_reconnection and master_failure_mode=error_on_write
*
* https://jira.mariadb.org/browse/MXS-1503
*/
#include "testconnections.h"
#include <vector>
#include <iostream>
#include <functional>
using std::cout;
using std::endl;
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
auto query = [&test](std::string q)
{
return execute_query_silent(test.maxscales->conn_rwsplit[0], q.c_str());
};
auto error_matches = [&test](std::string q)
{
std::string err = mysql_error(test.maxscales->conn_rwsplit[0]);
return err.find(q) != std::string::npos;
};
auto block_master = [&test]()
{
test.repl->block_node(0);
sleep(10);
};
auto unblock_master = [&test]()
{
test.repl->unblock_node(0);
sleep(10);
};
test.maxscales->connect();
test.assert(query("DROP TABLE IF EXISTS test.t1") == 0,
"DROP TABLE should work.");
test.assert(query("CREATE TABLE test.t1 (id INT)") == 0,
"CREATE TABLE should work.");
test.assert(query("INSERT INTO test.t1 VALUES (1)") == 0,
"Write should work at the start of the test.");
block_master();
test.assert(query("INSERT INTO test.t1 VALUES (1)") != 0,
"Write should fail after master is blocked.");
test.assert(error_matches("read-only"),
"Error should mention read-only mode");
unblock_master();
test.assert(query("INSERT INTO test.t1 VALUES (1)") == 0,
"Write should work after unblocking master");
query("DROP TABLE test.t1");
return test.global_result;
}