1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

mariadb-test: wait on disconnect

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
This commit is contained in:
Sergei Golubchik
2025-06-12 00:43:26 +02:00
committed by Dmitry Shulga
parent 18985d8471
commit bead24b7f3
347 changed files with 131 additions and 2015 deletions

View File

@@ -3,15 +3,8 @@
update performance_schema.setup_instruments set enabled='YES';
connection con1;
disconnect con1;
--source include/wait_until_disconnected.inc
connection con2;
disconnect con2;
--source include/wait_until_disconnected.inc
connection con3;
disconnect con3;
--source include/wait_until_disconnected.inc
connection default;

View File

@@ -115,9 +115,7 @@ if($is_connect)
{
if(!$my_errno)
{
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default
}
}

View File

@@ -39,7 +39,6 @@ if($mysql_errno)
if(!$mysql_errno)
{
disconnect checkcon123456789;
--source include/wait_until_disconnected.inc
}
connection default;
@@ -83,7 +82,6 @@ if($mysql_errno)
if(!$mysql_errno)
{
disconnect checkcon123456789a;
--source include/wait_until_disconnected.inc
}
connection default;

View File

@@ -2,9 +2,7 @@
# $out_file and $err_file must be set within pfs_upgrade.test.
#
--source include/count_sessions.inc
--exec $MYSQL_UPGRADE --skip-verbose --force > $MYSQLTEST_VARDIR/tmp/out_file 2> $MYSQLTEST_VARDIR/tmp/err_file
--source include/wait_until_count_sessions.inc
# Verify that mysql_upgrade does not complain about the performance_schema

View File

@@ -40,10 +40,7 @@ drop table test.t1;
drop table test.t2;
drop table test.t3;
update performance_schema.setup_instruments set enabled='YES';
connection con1;
disconnect con1;
connection con2;
disconnect con2;
connection con3;
disconnect con3;
connection default;

View File

@@ -30,7 +30,9 @@ GRANT USAGE ON *.* TO `pfsuser`@`localhost`
GRANT SELECT, UPDATE ON `performance_schema`.* TO `pfsuser`@`localhost`
select * from performance_schema.setup_instruments;
update performance_schema.setup_instruments set enabled='NO';
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
update performance_schema.setup_instruments set enabled='YES';
ERROR HY000: The MariaDB server is running with the --read-only=ON option so it cannot execute this statement
connection default;
grant READ_ONLY ADMIN on *.* to pfsuser@localhost;
flush privileges;

View File

@@ -154,10 +154,8 @@ Expect 2
# 5.0 Drop the client connections
#==============================================================================
# 5.1 Disconnect con1
connection con1;
disconnect con1;
# 5.2 Disconnect con2
connection con2;
disconnect con2;
connection default;
#==============================================================================

View File

@@ -199,11 +199,8 @@ wait/io/socket/sql/client_connection <LOCALHOST>
wait/io/socket/sql/client_connection <LOCALHOST>
wait/io/socket/sql/client_connection
connection default;
connection con1;
disconnect con1;
connection con2;
disconnect con2;
connection con3;
disconnect con3;
connection default;
# After waiting a bit we should have no differences to socket_instances

View File

@@ -117,12 +117,10 @@ consistent with totals in socket_summary_by_instance
#
# 5.1 Disconnect con1
#
connection con1;
disconnect con1;
#
# 5.2 Disconnect con2
#
connection con2;
disconnect con2;
#
# 5.3 Drop mysqltest

View File

@@ -219,4 +219,3 @@ connection default;
# It must reset all counters.
TRUNCATE TABLE performance_schema.socket_summary_by_instance;
# 6. Cleanup
connection default;

View File

@@ -951,10 +951,6 @@ where THREAD_ID = $con4_thread_id;
count(*)
0
connection default;
revoke all privileges, grant option from user1@localhost;
revoke all privileges, grant option from user2@localhost;
revoke all privileges, grant option from user3@localhost;
revoke all privileges, grant option from user4@localhost;
drop user user1@localhost;
drop user user2@localhost;
drop user user3@localhost;

View File

@@ -1272,7 +1272,6 @@ DELETE FROM db.t1;
#=======================================================================
# Cleanup
#=======================================================================
connection con1;
disconnect con1;
connection default;
DROP DATABASE db;

View File

@@ -6,10 +6,6 @@
# TODO: remove this when P_S works with embedded.
--source include/not_embedded.inc
# make sure we're alone
let $count_sessions= 1;
--source include/wait_until_count_sessions.inc
# basic performance_schema.session_connect_attrs tests
# check the presence of the pre-defined attributes
@@ -78,6 +74,3 @@ SELECT SUM(ISNULL(ATTR_VALUE)), COUNT(*)
change_user root,,test;
DROP USER wl5924@localhost;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc

View File

@@ -69,7 +69,6 @@ update performance_schema.setup_instruments set enabled='YES';
unlock tables;
disconnect con1;
--source include/wait_until_disconnected.inc
connection default;

View File

@@ -96,10 +96,6 @@ SELECT `USER`, `HOST`, VARIABLE_NAME, VARIABLE_VALUE
--disconnect con1
--disconnect con2
# Wait till all disconnects are completed
let $count_sessions= 2;
--source include/wait_until_count_sessions.inc
--disable_query_log
eval SELECT VARIABLE_NAME, (VARIABLE_VALUE - $initial) AS DELTA from performance_schema.global_status WHERE VARIABLE_NAME = 'Select_range';
--enable_query_log
@@ -112,10 +108,6 @@ eval SELECT VARIABLE_NAME, (VARIABLE_VALUE - $initial) AS DELTA from performance
--disconnect con3
# Wait till all disconnects are completed
let $count_sessions= 1;
--source include/wait_until_count_sessions.inc
--disable_query_log
eval SELECT VARIABLE_NAME, (VARIABLE_VALUE - $initial) AS DELTA from performance_schema.global_status WHERE VARIABLE_NAME = 'Select_range';
--enable_query_log

View File

@@ -316,7 +316,6 @@ TRUNCATE TABLE performance_schema.events_waits_current;
--echo # Clean up
--disconnect pfs_user_4
--source include/wait_until_disconnected.inc
--connection default
REVOKE ALL PRIVILEGES, GRANT OPTION FROM pfs_user_4;
DROP USER pfs_user_4;

View File

@@ -43,11 +43,11 @@ select @@global.read_only;
show grants;
--disable_result_log
select * from performance_schema.setup_instruments;
--enable_result_log
--error ER_OPTION_PREVENTS_STATEMENT
update performance_schema.setup_instruments set enabled='NO';
--error ER_OPTION_PREVENTS_STATEMENT
update performance_schema.setup_instruments set enabled='YES';
--enable_result_log
connection default;
@@ -61,13 +61,11 @@ select @@global.read_only;
show grants;
--disable_result_log
select * from performance_schema.setup_instruments;
--enable_result_log
update performance_schema.setup_instruments set enabled='NO';
update performance_schema.setup_instruments set enabled='YES';
--enable_result_log
disconnect con1;
--source include/wait_until_disconnected.inc
connection default;
set global read_only= @start_read_only;

View File

@@ -203,9 +203,6 @@ select * from performance_schema.threads;
select * from test.v1;
--disconnect con5
--source include/wait_until_disconnected.inc
--connection default
drop view test.v1;

View File

@@ -7,7 +7,6 @@
--source include/have_perfschema.inc
--source include/not_embedded.inc
--source include/no_protocol.inc
--source include/count_sessions.inc
--echo #
--echo # TEST 1
@@ -106,7 +105,6 @@ SELECT @bytes_before > @bytes_after AS 'Expect 1';
SELECT @bytes_after AS 'Expect 0';
disconnect con1;
--source include/wait_until_count_sessions.inc
--echo #
@@ -119,8 +117,6 @@ disconnect con1;
--echo # Default connection
--let $initial_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)
--source include/count_sessions.inc
--echo #
--echo # First connection
--connect (con1, localhost, root,,)
@@ -151,7 +147,6 @@ SET long_query_time = @@global.long_query_time;
--connection default
--disconnect con1
--source include/wait_until_count_sessions.inc
--echo #
--echo # Default connection

View File

@@ -26,14 +26,10 @@
--source include/have_innodb.inc
--source include/have_debug_sync.inc
--enable_connect_log
--echo #
--echo # ================================================================================
--echo # SETUP
--echo # ================================================================================
--echo # Save the initial number of concurrent sessions
--source include/count_sessions.inc
--echo #
--echo # Verify EXAMPLE plugin is not loaded
SELECT COUNT(*) = 0 AS "Expect 1" FROM information_schema.plugins WHERE plugin_name = "EXAMPLE";
@@ -181,18 +177,9 @@ WHERE variable_name LIKE "example_%" ORDER BY variable_value;
--echo # ================================================================================
--echo # 3.5 - DISCONNECT CLIENTS
--echo # ================================================================================
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection con3
--disconnect con3
--source include/wait_until_disconnected.inc
--connection default
--echo #
@@ -250,18 +237,9 @@ WHERE variable_name LIKE "example_%" ORDER BY variable_value;
--echo # ================================================================================
--echo # 3.11 - DISCONNECT CLIENTS
--echo # ================================================================================
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection con3
--disconnect con3
--source include/wait_until_disconnected.inc
--connection default
--echo #
@@ -314,8 +292,3 @@ select @@session.innodb_strict_mode;
--echo #
--echo #
--disable_connect_log
--echo #
--echo # Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc

View File

@@ -257,14 +257,10 @@ WHERE EVENT_NAME LIKE '%client_connection%'
--echo #==============================================================================
--echo # 5.1 Disconnect con1
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--echo # 5.2 Disconnect con2
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection default
--echo #==============================================================================

View File

@@ -436,15 +436,9 @@ $part;
# DROP CLIENT CONNECTIONS
#
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection con3
--disconnect con3
--source include/wait_until_disconnected.inc
--connection default
#

View File

@@ -327,12 +327,8 @@ $part;
#
--echo # Disconnect con1 and con2
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection default
#

View File

@@ -317,16 +317,12 @@ if (`SELECT @tables_match = 0`)
--echo #
--echo # 5.1 Disconnect con1
--echo #
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--echo #
--echo # 5.2 Disconnect con2
--echo #
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--echo #
--echo # 5.3 Drop mysqltest

View File

@@ -1680,8 +1680,6 @@ if($print_details)
--disable_query_log
DROP SCHEMA mysqltest;
DROP SCHEMA mysqlsupertest;
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default
--enable_query_log

View File

@@ -1696,9 +1696,6 @@ if($print_details)
--disable_query_log
DROP SCHEMA mysqltest;
DROP SCHEMA mysqlsupertest;
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default
--enable_query_log

View File

@@ -13,9 +13,6 @@ TRUNCATE TABLE performance_schema.events_statements_history;
--echo # concurrency check through multi connections
# Save the initial number of concurrent sessions
--source include/count_sessions.inc
CREATE DATABASE db1;
CREATE DATABASE db2;
CREATE DATABASE db3;
@@ -127,6 +124,3 @@ DROP DATABASE db3;
disconnect con1;
disconnect con2;
disconnect con3;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc

View File

@@ -650,10 +650,6 @@ evalp select /*4-3*/ count(*) from performance_schema.events_waits_history_long
--connection default
revoke all privileges, grant option from user1@localhost;
revoke all privileges, grant option from user2@localhost;
revoke all privileges, grant option from user3@localhost;
revoke all privileges, grant option from user4@localhost;
drop user user1@localhost;
drop user user2@localhost;
drop user user3@localhost;

View File

@@ -702,9 +702,7 @@ CALL transaction_verifier(0, @con2_thread_id, 'transaction', 'ACTIVE', 0, '', ''
--echo #
--echo ## Drop connection
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection default
--echo #

View File

@@ -374,9 +374,7 @@ eval SET @all_threads= 0;
--echo #=======================================================================
--echo # Cleanup
--echo #=======================================================================
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default
DROP DATABASE db;
UPDATE performance_schema.setup_instruments SET enabled='YES', timed='YES';

View File

@@ -29,10 +29,6 @@ select VARIABLE_NAME, VARIABLE_VALUE
--connection default
--disconnect con1
# Wait till all disconnects are completed
let $count_sessions= 1;
--source include/wait_until_count_sessions.inc
select VARIABLE_NAME, VARIABLE_VALUE
from performance_schema.user_variables_by_thread
order by VARIABLE_NAME;