Make bug509 more Galera friendly
The test now skips execution of inserts to separate nodes. This should guarantee that the nodes are synced at all times. The test now does the inserts and selects inside a transaction to force the reads to the same node where the inserts are done.
This commit is contained in:
parent
4f675997fb
commit
0cd62c6f29
@ -1,39 +1,14 @@
|
||||
/**
|
||||
* @file bug509.cpp regression case for bug 509 and 507 ( "Referring to a nonexisting server in servers=... doesn't even raise a warning"
|
||||
* and "rw-split router does not send last_insert_id() to master" )
|
||||
* @file bug509.cpp regression case for bug 509 "rw-split router does not send last_insert_id() to master"
|
||||
*
|
||||
* - "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));",
|
||||
* - do a number of INSERTs first using RWsplit, then directly Galera nodes.
|
||||
* - do "select @@wsrep_node_address, last_insert_id();" and "select last_insert_id(), @@wsrep_node_address;" and compares results.
|
||||
* - do "insert into t2 (x) values (i);" 1000 times and compares results of
|
||||
* - do "insert into t2 (x) values (i);" 50 times and compares results of
|
||||
* "select @@wsrep_node_address, last_insert_id();" and "select last_insert_id(), @@wsrep_node_address;"
|
||||
*
|
||||
* Test fails if results are different (after 5 seconds of waiting after last INSERT)
|
||||
*/
|
||||
|
||||
/*
|
||||
Kolbe Kegel 2014-09-01 14:48:12 UTC
|
||||
For some reason, the order of terms in the field list of a SELECT statement influences how the rw-split router decides where to send a statement.
|
||||
|
||||
mariadb> select @@wsrep_node_address, last_insert_id();
|
||||
+----------------------+------------------+
|
||||
| @@wsrep_node_address | last_insert_id() |
|
||||
+----------------------+------------------+
|
||||
| 192.168.30.31 | 7 |
|
||||
+----------------------+------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mariadb> select last_insert_id(), @@wsrep_node_address;
|
||||
+------------------+----------------------+
|
||||
| last_insert_id() | @@wsrep_node_address |
|
||||
+------------------+----------------------+
|
||||
| 0 | 192.168.30.33 |
|
||||
+------------------+----------------------+
|
||||
1 row in set (0.00 sec)
|
||||
Comment 1 Vilho Raatikka 2014-09-03 20:44:17 UTC
|
||||
Added code to detect last_insert_id() function and now both types of elements are routed to master and their order of appearance doesn't matter.
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "testconnections.h"
|
||||
@ -49,59 +24,22 @@ int main(int argc, char *argv[])
|
||||
Test->galera->connect();
|
||||
Test->connect_maxscale();
|
||||
|
||||
if (Test->galera->N < 3)
|
||||
{
|
||||
Test->tprintf("There is not enoght nodes for test\n");
|
||||
delete Test;
|
||||
exit(1);
|
||||
}
|
||||
Test->tprintf("Creating table");
|
||||
Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t2;");
|
||||
Test->try_query(Test->conn_rwsplit, "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));");
|
||||
Test->tprintf("Doing INSERT through readwritesplit");
|
||||
Test->try_query(Test->conn_rwsplit, "START TRANSACTION");
|
||||
Test->try_query(Test->conn_rwsplit, "insert into t2 (x) values (1);");
|
||||
|
||||
Test->tprintf("Creating table\n");
|
||||
Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS t2;");
|
||||
Test->try_query(Test->conn_rwsplit,
|
||||
(char *) "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));");
|
||||
Test->tprintf("Doing INSERTs\n");
|
||||
Test->try_query(Test->conn_rwsplit, (char *) "insert into t2 (x) values (1);");
|
||||
char last_insert_id1[1024] = "";
|
||||
char last_insert_id2[1024] = "";
|
||||
find_field(Test->conn_rwsplit, sel1, "last_insert_id()", last_insert_id1);
|
||||
find_field(Test->conn_rwsplit, sel2, "last_insert_id()", last_insert_id2);
|
||||
Test->try_query(Test->conn_rwsplit, "COMMIT");
|
||||
|
||||
Test->try_query(Test->galera->nodes[0], (char *) "insert into t2 (x) values (2);");
|
||||
Test->try_query(Test->galera->nodes[0], (char *) "insert into t2 (x) values (3);");
|
||||
|
||||
Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (4);");
|
||||
Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (5);");
|
||||
Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (6);");
|
||||
|
||||
Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (7);");
|
||||
Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (8);");
|
||||
Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (9);");
|
||||
Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (10);");
|
||||
|
||||
Test->stop_timeout();
|
||||
Test->repl->sync_slaves();
|
||||
|
||||
Test->tprintf("Trying \n");
|
||||
char last_insert_id1[1024];
|
||||
char last_insert_id2[1024];
|
||||
if ( (
|
||||
find_field(
|
||||
Test->conn_rwsplit, sel1,
|
||||
"last_insert_id()", &last_insert_id1[0])
|
||||
!= 0 ) || (
|
||||
find_field(
|
||||
Test->conn_rwsplit, sel2,
|
||||
"last_insert_id()", &last_insert_id2[0])
|
||||
!= 0 ))
|
||||
{
|
||||
Test->tprintf("last_insert_id() fied not found!!\n");
|
||||
delete Test;
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Test->tprintf("'%s' gave last_insert_id() %s\n", sel1, last_insert_id1);
|
||||
Test->tprintf("'%s' gave last_insert_id() %s\n", sel2, last_insert_id2);
|
||||
Test->add_result(strcmp(last_insert_id1, last_insert_id2),
|
||||
"last_insert_id() are different depending in which order terms are in SELECT\n");
|
||||
}
|
||||
Test->tprintf("'%s' gave last_insert_id() %s", sel1, last_insert_id1);
|
||||
Test->tprintf("'%s' gave last_insert_id() %s", sel2, last_insert_id2);
|
||||
Test->add_result(strcmp(last_insert_id1, last_insert_id2), "last_insert_id() are different depending in which order terms are in SELECT");
|
||||
|
||||
char id_str[1024];
|
||||
char str1[1024];
|
||||
@ -110,12 +48,13 @@ int main(int argc, char *argv[])
|
||||
for (int i = 100; i < iterations; i++)
|
||||
{
|
||||
Test->set_timeout(50);
|
||||
Test->try_query(Test->conn_rwsplit, "START TRANSACTION");
|
||||
Test->add_result(execute_query(Test->conn_rwsplit, "insert into t2 (x) values (%d);", i), "Query failed");
|
||||
|
||||
sprintf(str1, "select * from t2 where x=%d;", i);
|
||||
|
||||
find_field(Test->conn_rwsplit, sel1, "last_insert_id()", &last_insert_id1[0]);
|
||||
find_field(Test->conn_rwsplit, str1, "id", &id_str[0]);
|
||||
find_field(Test->conn_rwsplit, sel1, "last_insert_id()", last_insert_id1);
|
||||
find_field(Test->conn_rwsplit, str1, "id", id_str);
|
||||
|
||||
int n = 0;
|
||||
|
||||
@ -127,6 +66,8 @@ int main(int argc, char *argv[])
|
||||
n++;
|
||||
}
|
||||
|
||||
Test->try_query(Test->conn_rwsplit, "COMMIT");
|
||||
|
||||
Test->add_result(strcmp(last_insert_id1, id_str),
|
||||
"last_insert_id is not equal to id even after waiting 5 seconds");
|
||||
|
||||
@ -136,6 +77,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Test->try_query(Test->conn_rwsplit, "DROP TABLE t2;");
|
||||
Test->check_maxscale_alive();
|
||||
|
||||
int rval = Test->global_result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user