From e46ae59265036ff2653e2bba4a0e71b048db4b4f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 15 Oct 2023 23:50:30 +0200 Subject: [PATCH] MDEV-27523 main.delayed fails with wrong error code or timeout when executed after main.deadlock_ftwrl don't forget to reset mdl_context.m_deadlock_overweight when taking the THD out of the cache - the history of previous connections should not affect the weight in deadlock victim selection (small cleanup of the test to help the correct merge) --- mysql-test/main/delayed.result | 11 +---------- mysql-test/main/delayed.test | 29 +---------------------------- sql/mdl.h | 5 +++-- sql/sql_class.cc | 1 + 4 files changed, 6 insertions(+), 40 deletions(-) diff --git a/mysql-test/main/delayed.result b/mysql-test/main/delayed.result index fe284dfcdad..af486201907 100644 --- a/mysql-test/main/delayed.result +++ b/mysql-test/main/delayed.result @@ -1,4 +1,3 @@ -drop table if exists t1; create table t1 (a char(10), tmsp timestamp); insert into t1 set a = 1; insert delayed into t1 set a = 2; @@ -259,7 +258,6 @@ INSERT DELAYED INTO t1 SET b= b(); ERROR 42000: FUNCTION test.b does not exist DROP TABLE t1; End of 5.0 tests -DROP TABLE IF EXISTS t1,t2; SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'; CREATE TABLE `t1` ( `id` int(11) PRIMARY KEY auto_increment, @@ -293,7 +291,6 @@ set global low_priority_updates = 1; select @@global.low_priority_updates; @@global.low_priority_updates 1 -drop table if exists t1; create table t1 (a int, b int); insert into t1 values (1,1); lock table t1 read; @@ -322,7 +319,6 @@ set global low_priority_updates = @old_delayed_updates; # # Bug #47682 strange behaviour of INSERT DELAYED # -DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1 (f1 integer); CREATE TABLE t2 (f1 integer); FLUSH TABLES WITH READ LOCK; @@ -335,8 +331,6 @@ End of 5.1 tests # # Bug #47274 assert in open_table on CREATE TABLE # -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t2; CREATE TABLE t1 ( f1 INTEGER AUTO_INCREMENT, PRIMARY KEY (f1)); # The following CREATE TABLEs before gave an assert. INSERT DELAYED t1 VALUES (4); @@ -352,14 +346,12 @@ CREATE TABLE t2 (f1 INTEGER); INSERT DELAYED t1 VALUES (7); CREATE TABLE t1 LIKE t2; ERROR 42S01: Table 't1' already exists -DROP TABLE t2; -DROP TABLE t1; +DROP TABLE t2, t1; # # Bug#54332 Deadlock with two connections doing LOCK TABLE+INSERT DELAYED # # This test is not supposed to work under --ps-protocol since # INSERT DELAYED doesn't work under LOCK TABLES with this protocol. -DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); CREATE TABLE t3 (a INT); @@ -450,7 +442,6 @@ DROP TABLE t1, t2, t3; # connect con1,localhost,root,,; connection default; -drop table if exists t1, t2, tm; create table t1(a int); create table t2(a int); create table tm(a int) engine=merge union=(t1, t2); diff --git a/mysql-test/main/delayed.test b/mysql-test/main/delayed.test index 2cf34b5975b..2b9eb083f13 100644 --- a/mysql-test/main/delayed.test +++ b/mysql-test/main/delayed.test @@ -21,9 +21,6 @@ select @@global.storage_engine in ("memory","myisam","archive","blackhole") as `TRUE`; enable_query_log; ---disable_warnings -drop table if exists t1; ---enable_warnings create table t1 (a char(10), tmsp timestamp); insert into t1 set a = 1; insert delayed into t1 set a = 2; @@ -276,9 +273,6 @@ DROP TABLE t1; # # Bug#27358 INSERT DELAYED does not honour SQL_MODE of the client # ---disable_warnings -DROP TABLE IF EXISTS t1,t2; ---enable_warnings SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'; CREATE TABLE `t1` ( `id` int(11) PRIMARY KEY auto_increment, @@ -315,9 +309,6 @@ set @old_delayed_updates = @@global.low_priority_updates; set global low_priority_updates = 1; select @@global.low_priority_updates; ---disable_warnings -drop table if exists t1; ---enable_warnings create table t1 (a int, b int); insert into t1 values (1,1); lock table t1 read; @@ -351,10 +342,6 @@ set global low_priority_updates = @old_delayed_updates; --echo # Bug #47682 strange behaviour of INSERT DELAYED --echo # ---disable_warnings -DROP TABLE IF EXISTS t1, t2; ---enable_warnings - CREATE TABLE t1 (f1 integer); CREATE TABLE t2 (f1 integer); @@ -378,11 +365,6 @@ DROP TABLE t1, t2; --echo # Bug #47274 assert in open_table on CREATE TABLE --echo # ---disable_warnings -DROP TABLE IF EXISTS t1; -DROP TABLE IF EXISTS t2; ---enable_warnings - CREATE TABLE t1 ( f1 INTEGER AUTO_INCREMENT, PRIMARY KEY (f1)); --echo # The following CREATE TABLEs before gave an assert. @@ -404,9 +386,7 @@ INSERT DELAYED t1 VALUES (7); --error ER_TABLE_EXISTS_ERROR CREATE TABLE t1 LIKE t2; -DROP TABLE t2; -DROP TABLE t1; - +DROP TABLE t2, t1; --echo # --echo # Bug#54332 Deadlock with two connections doing LOCK TABLE+INSERT DELAYED @@ -417,10 +397,6 @@ DROP TABLE t1; --disable_ps_protocol --disable_view_protocol ---disable_warnings -DROP TABLE IF EXISTS t1, t2; ---enable_warnings - CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); CREATE TABLE t3 (a INT); @@ -573,9 +549,6 @@ DROP TABLE t1, t2, t3; --disable_view_protocol connect (con1,localhost,root,,); connection default; ---disable_warnings -drop table if exists t1, t2, tm; ---enable_warnings create table t1(a int); create table t2(a int); create table tm(a int) engine=merge union=(t1, t2); diff --git a/sql/mdl.h b/sql/mdl.h index 1f14188ec59..418dd6d3bd7 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -919,7 +919,8 @@ public: already has received some signal or closed signal slot. */ - void init(MDL_context_owner *arg) { m_owner= arg; } + void init(MDL_context_owner *arg) { m_owner= arg; reset(); } + void reset() { m_deadlock_overweight= 0; } void set_needs_thr_lock_abort(bool needs_thr_lock_abort) { @@ -1028,7 +1029,7 @@ private: */ MDL_wait_for_subgraph *m_waiting_for; LF_PINS *m_pins; - uint m_deadlock_overweight= 0; + uint m_deadlock_overweight; private: MDL_ticket *find_ticket(MDL_request *mdl_req, enum_mdl_duration *duration); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1d278a01947..479ff0e68d0 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1209,6 +1209,7 @@ const Type_handler *THD::type_handler_for_datetime() const void THD::init() { DBUG_ENTER("thd::init"); + mdl_context.reset(); mysql_mutex_lock(&LOCK_global_system_variables); plugin_thdvar_init(this); /*