mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Remove one of the major sources of race condiitons in mariadb-test. Normally, mariadb_close() sends COM_QUIT to the server and immediately disconnects. In mariadb-test it means the test can switch to another connection and sends queries to the server before the server even started parsing the COM_QUIT packet and these queries can see the connection as fully active, as it didn't reach dispatch_command yet. This is a major source of instability in tests and many - but not all, still less than a half - tests employ workarounds. The correct one is a pair count_sessions.inc/wait_until_count_sessions.inc. Also very popular was wait_until_disconnected.inc, which was completely useless, because it verifies that the connection is closed, and after disconnect it always is, it didn't verify whether the server processed COM_QUIT. Sadly the placebo was as widely used as the real thing. Let's fix this by making mariadb-test `disconnect` command _to wait_ for the server to confirm. This makes almost all workarounds redundant. In some cases count_sessions.inc/wait_until_count_sessions.inc is still needed, though, as only `disconnect` command is changed: * after external tools, like `exec $MYSQL` * after failed `connect` command * replication, after `STOP SLAVE` * Federated/CONNECT/SPIDER/etc after `DROP TABLE` and also in some XA tests, because an XA transaction is dissociated from the THD very late, after the server has closed the client connection. Collateral cleanups: fix comments, remove some redundant statements: * DROP IF EXISTS if nothing is known to exist * DROP table/view before DROP DATABASE * REVOKE privileges before DROP USER etc
130 lines
2.7 KiB
Plaintext
130 lines
2.7 KiB
Plaintext
#
|
|
# SELECT HIGH_PRIOIRITY
|
|
#
|
|
--source have_engine.inc
|
|
|
|
# We will have 3 connections:
|
|
# con1 will lock a table in READ mode
|
|
# con0 will run UPDATE (and will wait on the lock)
|
|
# con2 will start another SELECT
|
|
# con1 will then unlock the table
|
|
#
|
|
# With standard SELECT we should see updated rows in the 2nd result set,
|
|
# while with SELECT HIGH_PRIORITY we should still see only old rows in con2 resultset
|
|
# (and it shouldn't wait till the table is unlocked and UPDATE is executed).
|
|
|
|
--connect (con0,localhost,root,,)
|
|
SET lock_wait_timeout = 4;
|
|
--connect (con1,localhost,root,,)
|
|
SET lock_wait_timeout = 4;
|
|
--connect (con2,localhost,root,,)
|
|
SET lock_wait_timeout = 4;
|
|
|
|
|
|
# Part 1: Standard SELECT
|
|
# should be executed after the UPDATE
|
|
|
|
--source create_table.inc
|
|
INSERT INTO t1 (a,b) VALUES (1,'f'),(2,'b');
|
|
|
|
--connection con1
|
|
LOCK TABLE t1 READ;
|
|
|
|
--connection con0
|
|
--send
|
|
UPDATE t1 SET b = CONCAT(b,b);
|
|
|
|
--connection con2
|
|
let $show_statement = SHOW PROCESSLIST;
|
|
let $field = State;
|
|
let $condition = LIKE 'Waiting for table%';
|
|
let $wait_timeout = 2;
|
|
--source include/wait_show_condition.inc
|
|
--send
|
|
SELECT a,b FROM t1;
|
|
|
|
--connection con1
|
|
let $show_statement = SHOW PROCESSLIST;
|
|
let $field = Info;
|
|
let $condition = = 'SELECT a,b FROM t1';
|
|
let $wait_timeout = 2;
|
|
--source include/wait_show_condition.inc
|
|
if (!$found)
|
|
{
|
|
--let $mysql_errname = timeout in wait_show_condition.inc
|
|
--let $functionality = Table locking or UPDATE
|
|
--source unexpected_result.inc
|
|
}
|
|
|
|
UNLOCK TABLES;
|
|
|
|
--connection con0
|
|
--reap
|
|
if ($mysql_errname)
|
|
{
|
|
--let $my_last_stmt = UPDATE t1 SET b = CONCAT(b,b)
|
|
--let $functionality = UPDATE
|
|
--source unexpected_result.inc
|
|
}
|
|
|
|
--connection con2
|
|
--echo # Should return the new data
|
|
--sorted_result
|
|
--reap
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
# Part 2: SELECT HIGH_PRIORITY
|
|
# should be executed before the UPDATE
|
|
|
|
--source create_table.inc
|
|
INSERT INTO t1 (a,b) VALUES (1,'f'),(2,'b');
|
|
|
|
--connection con1
|
|
LOCK TABLE t1 READ;
|
|
|
|
--connection con0
|
|
--send
|
|
UPDATE t1 SET b = CONCAT(b,b,b);
|
|
|
|
--connection con2
|
|
let $condition = LIKE 'Waiting for table%';
|
|
let $field = State;
|
|
let $wait_timeout = 2;
|
|
--source include/wait_show_condition.inc
|
|
SET lock_wait_timeout = 1;
|
|
--echo # Should return old data
|
|
--sorted_result
|
|
SELECT HIGH_PRIORITY * FROM t1;
|
|
if ($mysql_errname)
|
|
{
|
|
--let $functionality = SELECT HIGH_PRIORITY
|
|
--source unexpected_result.inc
|
|
}
|
|
|
|
--connection con1
|
|
UNLOCK TABLES;
|
|
|
|
--connection con0
|
|
--reap
|
|
if ($mysql_errname)
|
|
{
|
|
--let $my_last_stmt = UPDATE t1 SET b = CONCAT(b,b,b)
|
|
--let $functionality = UPDATE
|
|
--source unexpected_result.inc
|
|
}
|
|
|
|
--disconnect con1
|
|
--disconnect con2
|
|
--disconnect con0
|
|
let $wait_timeout = 30;
|
|
|
|
--connection default
|
|
|
|
# Cleanup
|
|
DROP TABLE t1;
|
|
|
|
--source cleanup_engine.inc
|
|
|