
The `global` parameter causes the time window defined by the `time` parameter to be applied at the instance level instead of the session level. This means that a write from one connection will cause all other connections to use the master for a certain period of time. Using a configurable time window for consistency is not good as it is not absolute and cannot adjust to how servers behave. One example that demonstrates this is when a slave is normally lagging behind by less than a second but some event causes the lag to spike up to several seconds. In this case the configured time window would no longer guarantee consistency. Another reason to avoid a "static" time window is the fact taht it prevents load balancing in the cases where slaves catch up to the master within time window. This happens when time is configured to a higher value to avoid inconsistencies at all costs. Added a test case that verified the feature works.
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
/**
|
|
* Test global mode for the CCRFilter
|
|
*/
|
|
|
|
#include "testconnections.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
TestConnections test(argc, argv);
|
|
|
|
auto conn = test.maxscales->rwsplit();
|
|
conn.connect();
|
|
test.expect(conn.query("CREATE OR REPLACE TABLE test.t1 (a LONGTEXT)"),
|
|
"Table creation should work: %s", conn.error());
|
|
conn.disconnect();
|
|
|
|
std::string data(1000000, 'a');
|
|
auto secondary = test.maxscales->rwsplit();
|
|
secondary.connect();
|
|
|
|
for (int i = 0; i < 50; i++)
|
|
{
|
|
conn.connect();
|
|
test.expect(conn.query("INSERT INTO test.t1 VALUES ('" + data + "')"),
|
|
"INSERT should work: %s", conn.error());
|
|
conn.disconnect();
|
|
|
|
// New connections should see the inserted rows
|
|
conn.connect();
|
|
auto count = std::stoi(conn.field("SELECT COUNT(*) FROM test.t1"));
|
|
test.expect(count == i + 1, "Missing `%d` rows.", (i + 1) - count);
|
|
conn.disconnect();
|
|
|
|
// Existing connections should also see the inserted rows
|
|
auto second_count = std::stoi(secondary.field("SELECT COUNT(*) FROM test.t1"));
|
|
test.expect(second_count == i + 1, "Missing `%d` rows from open connection.", (i + 1) - count);
|
|
}
|
|
|
|
conn.connect();
|
|
test.expect(conn.query("DROP TABLE test.t1"),
|
|
"Table creation should work: %s", conn.error());
|
|
conn.disconnect();
|
|
|
|
return test.global_result;
|
|
}
|