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
170 lines
5.5 KiB
Plaintext
170 lines
5.5 KiB
Plaintext
#==============================================================================
|
|
# Establish the level of IPV6 support
|
|
#==============================================================================
|
|
#==============================================================================
|
|
# Get hostname, port number
|
|
#==============================================================================
|
|
SELECT @@hostname INTO @MY_HOSTNAME;
|
|
SELECT @@port INTO @MY_MASTER_PORT;
|
|
#==============================================================================
|
|
# 1.0 Get the default connection object_instance_begin, thread id and verify
|
|
# the expected number of client connections.
|
|
#==============================================================================
|
|
#
|
|
# 1.1 Confirm only one client connection
|
|
#
|
|
SELECT COUNT(*) INTO @my_client_connections
|
|
FROM performance_schema.socket_instances
|
|
WHERE EVENT_NAME LIKE "%client_connection%";
|
|
#
|
|
# 1.2 Get the default THREAD_ID;
|
|
#
|
|
SELECT THREAD_ID INTO @my_thread_id
|
|
FROM performance_schema.threads
|
|
WHERE PROCESSLIST_ID = CONNECTION_ID();
|
|
#
|
|
# 1.3 Get the default OBJECT_INSTANCE_BEGIN
|
|
#
|
|
SELECT OBJECT_INSTANCE_BEGIN INTO @my_object_instance_begin
|
|
FROM performance_schema.socket_instances
|
|
WHERE THREAD_ID = @my_thread_id;
|
|
#==============================================================================
|
|
# 2.0 ESTABLISH TCP/IP CONNECTION 1
|
|
# Connect with IP = localhost (127.0.0.1 or ::1)
|
|
#==============================================================================
|
|
#
|
|
# 2.1 Get the connection thread id
|
|
#
|
|
SELECT THREAD_ID INTO @my_thread_id
|
|
FROM performance_schema.threads
|
|
WHERE PROCESSLIST_ID = CONNECTION_ID();
|
|
#
|
|
# 2.2 Get the connection object instance begin
|
|
#
|
|
SELECT OBJECT_INSTANCE_BEGIN INTO @my_object_instance_begin
|
|
FROM performance_schema.socket_instances
|
|
WHERE THREAD_ID = @my_thread_id;
|
|
#
|
|
# 2.3 Get the connection port
|
|
#
|
|
SELECT PORT INTO @my_port
|
|
FROM performance_schema.socket_instances
|
|
WHERE THREAD_ID = @my_thread_id;
|
|
#
|
|
# 2.4 Verify that the connection is 127.0.0.1 or ::1
|
|
#
|
|
SELECT COUNT(*) = 1 AS 'Expect 1'
|
|
FROM performance_schema.socket_instances
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND (IP LIKE '%127.0.0.1' OR IP LIKE '%::1')
|
|
AND PORT= @con1_port
|
|
AND OBJECT_INSTANCE_BEGIN= @con1_object_id;
|
|
Expect 1
|
|
1
|
|
#
|
|
# 2.5 Verify that the same connection is in the summary instance table
|
|
#
|
|
SELECT COUNT(*) = 1 AS 'Expect 1'
|
|
FROM performance_schema.socket_summary_by_instance
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND OBJECT_INSTANCE_BEGIN= @con1_object_id;
|
|
Expect 1
|
|
1
|
|
#
|
|
# Switch to connection default
|
|
#
|
|
connection default;
|
|
#==============================================================================
|
|
# 3.0 ESTABLISH TCP/IP CONNECTION 2
|
|
# Connect with IP = localhost (127.0.0.1 or ::1)
|
|
#==============================================================================
|
|
#
|
|
# 3.1 Get the connection thread id
|
|
#
|
|
SELECT THREAD_ID INTO @my_thread_id
|
|
FROM performance_schema.threads
|
|
WHERE PROCESSLIST_ID = CONNECTION_ID();
|
|
#
|
|
# 3.2 Get the connection object instance begin
|
|
#
|
|
SELECT OBJECT_INSTANCE_BEGIN INTO @my_object_instance_begin
|
|
FROM performance_schema.socket_instances
|
|
WHERE THREAD_ID = @my_thread_id;
|
|
#
|
|
# 3.3 Get the connection port
|
|
#
|
|
SELECT PORT INTO @my_port
|
|
FROM performance_schema.socket_instances
|
|
WHERE THREAD_ID = @my_thread_id;
|
|
#
|
|
# 3.4 Verify that the connection is 127.0.0.1 or ::1
|
|
#
|
|
SELECT COUNT(*) = 1 AS 'Expect 1'
|
|
FROM performance_schema.socket_instances
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND (IP LIKE '%127.0.0.1' OR IP LIKE '%::1')
|
|
AND PORT= @con2_port
|
|
AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
|
|
Expect 1
|
|
1
|
|
#
|
|
# 3.5 Verify that the same connection is in the summary instance table
|
|
#
|
|
SELECT COUNT(*) = 1 AS 'Expect 1'
|
|
FROM performance_schema.socket_summary_by_instance
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
|
|
Expect 1
|
|
1
|
|
#
|
|
# 3.6 Verify that the connection is 127.0.0.1 or ::1
|
|
#
|
|
SELECT COUNT(*) = 1 AS 'Expect 1'
|
|
FROM performance_schema.socket_instances
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND (IP LIKE '%127.0.0.1' OR IP LIKE '%::1')
|
|
AND PORT= @con2_port
|
|
AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
|
|
Expect 1
|
|
1
|
|
#==============================================================================
|
|
# 4.0 Verify both connections exist in the instance tables
|
|
#==============================================================================
|
|
connection default;
|
|
#
|
|
# 4.1 Verify that there are two TCP/IP connections in the socket instance table
|
|
#
|
|
SELECT COUNT(*) = 2 AS 'Expect 2'
|
|
FROM performance_schema.socket_instances
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin
|
|
AND (IP LIKE '%127.0.0.1' OR IP LIKE '%::1');
|
|
Expect 2
|
|
1
|
|
#
|
|
# 4.2 Verify that there are two TCP/IP connections in the summary instance table
|
|
#
|
|
SELECT COUNT(*) = 2 AS 'Expect 2'
|
|
FROM performance_schema.socket_summary_by_instance
|
|
WHERE EVENT_NAME LIKE '%client_connection%'
|
|
AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin;
|
|
Expect 2
|
|
1
|
|
#==============================================================================
|
|
# 5.0 Drop the client connections
|
|
#==============================================================================
|
|
# 5.1 Disconnect con1
|
|
disconnect con1;
|
|
# 5.2 Disconnect con2
|
|
disconnect con2;
|
|
connection default;
|
|
#==============================================================================
|
|
# 6.0 Verify sockets were removed from the instance tables
|
|
#==============================================================================
|
|
#
|
|
# 6.1 Verify that there are no TCP/IP connections in the socket instance table
|
|
#
|
|
#
|
|
# 6.2 Verify that there are no TCP/IP connections in the summary instance table
|
|
#
|