1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00
Files
mariadb/mysql-test/suite/perfschema/include/socket_event_dbg.inc
Sergei Golubchik bead24b7f3 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
2025-07-16 09:14:33 +07:00

129 lines
2.9 KiB
PHP

# include/socket_event.inc
#
# Auxiliary routine
# - running some statement in connection con1
# and checking the changes for the client_connction" entry belonging to con1
# within socket_summary_by_instance and
# - checking if the changes to values caused by the statement execution are
# reasonable and stable
#
# Requirements:
# 1. Have socket_summary_by_instance_func running
# 2. Have a connection con1
# @con1_object_instance_begin needs to be the OBJECT_INSTANCE_BEGIN
# value of the "client_connction" entry belonging to con1 within
# socket_summary_by_instance.
# 3. $statement needs to contain the statement to be executed by con1.
#
let $my_errno= 0;
let $loop_round= 1;
while($loop_round <= $loop_rounds)
{
if (!$my_socket_debug)
{
--disable_query_log
}
# Collect the current state
#==========================
eval $truncate;
eval $insert_before;
# Run the operation
#==================
if($is_connect)
{
let $statement= Connect (con1,$connect_host,$connect_user,,$connect_db,,);
# Some statements fail with ER_ACCESS_DENIED_ERROR
--disable_abort_on_error
--connect (con1,$connect_host,$connect_user,,$connect_db,,)
--enable_abort_on_error
let $my_errno= $mysql_errno;
}
if(!$is_connect)
{
--connection con1
# Print the statement outcome once.
if($loop_round == 1)
{
--enable_query_log
--enable_result_log
--horizontal_results
}
# One of the statements to be checked is expected to fail with ER_NO_SUCH_TABLE.
--disable_abort_on_error
eval $statement;
--enable_abort_on_error
if (!$my_socket_debug)
{
--disable_query_log
--disable_result_log
}
}
# Wait till the operation is really finished. We expect that there will be no
# changes to the statistics of the additional connection after this point of time.
#=================================================================================
--connection default
if($my_errno)
{
# Wait a bit and hope that the counter maintenence is finished.
--sleep 3
}
if(!$my_errno)
{
--source ../include/wait_till_sleep.inc
}
# Various checks
#===============
# 1. Check statistics in general
#-------------------------------
# ../include/socket_summary_check.inc also inserts the 'After' state into
# mysqltest.my_socket_summary_by_instance.
--source ../include/socket_summary_check_dbg.inc
if (!$my_socket_debug)
{
--disable_query_log
--disable_result_log
}
if($is_connect)
{
eval $get_object_instance_begin;
eval $insert_pseudo_before;
}
eval $insert_delta;
# Correct the values of the columns statement and run
eval
UPDATE mysqltest.socket_summary_by_instance_detail
SET statement = '$statement'
WHERE statement IS NULL;
eval
UPDATE mysqltest.socket_summary_by_instance_detail
SET run = $loop_round
WHERE run IS NULL;
if($is_connect)
{
if(!$my_errno)
{
--disconnect con1
--connection default
}
}
inc $loop_round;
}
--enable_query_log
--enable_result_log