From 5acd391e8b2d4d760ae7f96a59413c9ea247e9b1 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 4 Sep 2019 04:29:03 +1000 Subject: [PATCH 01/30] MDEV-16039 Crash when selecting virtual columns generated using functions with DAYNAME() * Allocate items on thd->mem_root while refixing vcol exprs * Make vcol tree changes register and roll them back after the statement is executed. Explanation: Due to collation implementation specifics an Item tree could change while fixing. The tricky thing here is to make it on a proper arena. It's usually not a problem when a field is deterministic, however, makes a pain vice-versa, during allocation allocating. A non-deterministic field should be refixed on each statement, since it depends on the environment state. Changing the tree will be temporary and therefore it should be reverted after the statement execution. --- mysql-test/suite/gcol/r/gcol_bugfixes.result | 66 ++++++++++++++++++ mysql-test/suite/gcol/t/gcol_bugfixes.test | 70 ++++++++++++++++++++ sql/item.cc | 27 +------- sql/sql_base.cc | 43 +++++++----- sql/sql_class.cc | 4 +- sql/sql_class.h | 13 +++- sql/sql_parse.cc | 2 +- sql/sql_prepare.cc | 4 +- sql/table.cc | 16 ++++- sql/table.h | 1 + 10 files changed, 195 insertions(+), 51 deletions(-) diff --git a/mysql-test/suite/gcol/r/gcol_bugfixes.result b/mysql-test/suite/gcol/r/gcol_bugfixes.result index 9aff30aabc9..8eb7a9372b5 100644 --- a/mysql-test/suite/gcol/r/gcol_bugfixes.result +++ b/mysql-test/suite/gcol/r/gcol_bugfixes.result @@ -603,3 +603,69 @@ test gcol_t1 sidea NEVER NULL test gcol_t1 sideb NEVER NULL test gcol_t1 sidec VIRTUAL GENERATED ALWAYS sqrt(`sidea` * `sidea` + `sideb` * `sideb`) DROP TABLE gcol_t1; +# +# MDEV-16039 Crash when selecting virtual columns +# generated using functions with DAYNAME() +# +CREATE TABLE t1 ( +suppliersenttoday INT NOT NULL, +suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05'))) +) COLLATE utf8_bin; +INSERT INTO t1 (suppliersenttoday) VALUES (0); +INSERT INTO t1 (suppliersenttoday) VALUES (0); +SELECT * FROM t1; +suppliersenttoday suppliercaptoday +0 Wednesday +0 Wednesday +PREPARE STMT FROM 'INSERT INTO t1 (suppliersenttoday) VALUES (1)'; +CREATE OR REPLACE TABLE t1 ( +suppliersenttoday INT NOT NULL, +suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05'))) +) COLLATE utf8_bin; +EXECUTE STMT; +EXECUTE STMT; +SELECT * FROM t1; +suppliersenttoday suppliercaptoday +1 Wednesday +1 Wednesday +DROP TABLE t1; +# (duplicate) MDEV-20380 Server crash during update +CREATE TABLE gafld ( +nuigafld INTEGER NOT NULL, +ucrgafld VARCHAR(30) COLLATE UTF8_BIN NOT NULL +DEFAULT SUBSTRING_INDEX(USER(),'@',1) +); +EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE gafld ALL NULL NULL NULL NULL 1 Using where +EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE gafld ALL NULL NULL NULL NULL 1 Using where +DROP TABLE gafld; +# (duplicate) MDEV-17653 replace into generated columns is unstable +# Some columns are snipped from the MDEV test +CREATE TABLE t ( +c0 TIMESTAMP NOT NULL DEFAULT current_timestamp() +ON UPDATE current_timestamp(), +c1 DECIMAL(27,25) GENERATED ALWAYS AS (DAYOFMONTH('2020-02-05')), +c4 TIME NOT NULL, +c8 SMALLINT(6) GENERATED ALWAYS AS +(CONCAT_WS(CONVERT(C1 USING CP932), +'900') <> (c4 = 1)), +PRIMARY KEY (c4) +) DEFAULT CHARSET=latin1; +REPLACE INTO t SET c0 = '2018-06-03 10:31:43', c4 = '02:58:55'; +REPLACE INTO t SET c0 = '2018-06-03 10:31:44', c4 = '02:58:55'; +REPLACE INTO t SET c0 = '2018-06-03 10:31:45', c4 = '02:58:55'; +DROP TABLE t; +# (duplicate) MDEV-17986 crash when I insert on a table +CREATE OR REPLACE TABLE t2 ( +number BIGINT(20) NOT NULL, +lrn BIGINT(20) NOT NULL DEFAULT 0, +source VARCHAR(15) NOT NULL +DEFAULT (REVERSE(SUBSTRING_INDEX(REVERSE(user()), '@', 1))), +PRIMARY KEY (number) +); +REPLACE t2(number) VALUES('1'); +REPLACE t2(number) VALUES('1'); +DROP TABLE t2; diff --git a/mysql-test/suite/gcol/t/gcol_bugfixes.test b/mysql-test/suite/gcol/t/gcol_bugfixes.test index 5563347a02a..033c430853d 100644 --- a/mysql-test/suite/gcol/t/gcol_bugfixes.test +++ b/mysql-test/suite/gcol/t/gcol_bugfixes.test @@ -564,3 +564,73 @@ SELECT table_schema,table_name,column_name,extra,is_generated,generation_express FROM information_schema.columns WHERE table_name='gcol_t1'; DROP TABLE gcol_t1; + +--echo # +--echo # MDEV-16039 Crash when selecting virtual columns +--echo # generated using functions with DAYNAME() +--echo # + +CREATE TABLE t1 ( + suppliersenttoday INT NOT NULL, + suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05'))) +) COLLATE utf8_bin; + +INSERT INTO t1 (suppliersenttoday) VALUES (0); +INSERT INTO t1 (suppliersenttoday) VALUES (0); +SELECT * FROM t1; + +PREPARE STMT FROM 'INSERT INTO t1 (suppliersenttoday) VALUES (1)'; + +CREATE OR REPLACE TABLE t1 ( + suppliersenttoday INT NOT NULL, + suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05'))) +) COLLATE utf8_bin; + +EXECUTE STMT; +EXECUTE STMT; +SELECT * FROM t1; + +DROP TABLE t1; + +--echo # (duplicate) MDEV-20380 Server crash during update +CREATE TABLE gafld ( + nuigafld INTEGER NOT NULL, + ucrgafld VARCHAR(30) COLLATE UTF8_BIN NOT NULL + DEFAULT SUBSTRING_INDEX(USER(),'@',1) +); +EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10; +EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10; +DROP TABLE gafld; + +--echo # (duplicate) MDEV-17653 replace into generated columns is unstable +--echo # Some columns are snipped from the MDEV test +CREATE TABLE t ( + c0 TIMESTAMP NOT NULL DEFAULT current_timestamp() + ON UPDATE current_timestamp(), + c1 DECIMAL(27,25) GENERATED ALWAYS AS (DAYOFMONTH('2020-02-05')), + c4 TIME NOT NULL, + c8 SMALLINT(6) GENERATED ALWAYS AS + (CONCAT_WS(CONVERT(C1 USING CP932), + '900') <> (c4 = 1)), + PRIMARY KEY (c4) +) DEFAULT CHARSET=latin1; + +REPLACE INTO t SET c0 = '2018-06-03 10:31:43', c4 = '02:58:55'; +REPLACE INTO t SET c0 = '2018-06-03 10:31:44', c4 = '02:58:55'; +REPLACE INTO t SET c0 = '2018-06-03 10:31:45', c4 = '02:58:55'; + +DROP TABLE t; + +--echo # (duplicate) MDEV-17986 crash when I insert on a table +CREATE OR REPLACE TABLE t2 ( + number BIGINT(20) NOT NULL, + lrn BIGINT(20) NOT NULL DEFAULT 0, + source VARCHAR(15) NOT NULL + DEFAULT (REVERSE(SUBSTRING_INDEX(REVERSE(user()), '@', 1))), + PRIMARY KEY (number) +); + +REPLACE t2(number) VALUES('1'); +REPLACE t2(number) VALUES('1'); + +DROP TABLE t2; diff --git a/sql/item.cc b/sql/item.cc index 9451d4203ca..644bef7524a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2325,14 +2325,7 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll, bool res= FALSE; uint i; - /* - In case we're in statement prepare, create conversion item - in its memory: it will be reused on each execute. - */ - Query_arena backup; - Query_arena *arena= thd->stmt_arena->is_stmt_prepare() ? - thd->activate_stmt_arena_if_needed(&backup) : - NULL; + DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare()); for (i= 0, arg= args; i < nargs; i++, arg+= item_sep) { @@ -2354,20 +2347,8 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll, res= TRUE; break; // we cannot return here, we need to restore "arena". } - /* - If in statement prepare, then we create a converter for two - constant items, do it once and then reuse it. - If we're in execution of a prepared statement, arena is NULL, - and the conv was created in runtime memory. This can be - the case only if the argument is a parameter marker ('?'), - because for all true constants the charset converter has already - been created in prepare. In this case register the change for - rollback. - */ - if (thd->stmt_arena->is_stmt_prepare()) - *arg= conv; - else - thd->change_item_tree(arg, conv); + + thd->change_item_tree(arg, conv); if (conv->fix_fields(thd, arg)) { @@ -2375,8 +2356,6 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll, break; // we cannot return here, we need to restore "arena". } } - if (arena) - thd->restore_active_arena(arena, &backup); return res; } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 436f753557e..674f6db8358 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4961,6 +4961,24 @@ static void mark_real_tables_as_free_for_reuse(TABLE_LIST *table_list) } } +int TABLE::fix_vcol_exprs(THD *thd) +{ + for (Field **vf= vfield; vf && *vf; vf++) + if (fix_session_vcol_expr(thd, (*vf)->vcol_info)) + return 1; + + for (Field **df= default_field; df && *df; df++) + if ((*df)->default_value && + fix_session_vcol_expr(thd, (*df)->default_value)) + return 1; + + for (Virtual_column_info **cc= check_constraints; cc && *cc; cc++) + if (fix_session_vcol_expr(thd, (*cc))) + return 1; + + return 0; +} + static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables) { @@ -4968,36 +4986,27 @@ static bool fix_all_session_vcol_exprs(THD *thd, TABLE_LIST *tables) TABLE_LIST *first_not_own= thd->lex->first_not_own_table(); DBUG_ENTER("fix_session_vcol_expr"); - for (TABLE_LIST *table= tables; table && table != first_not_own; + int error= 0; + for (TABLE_LIST *table= tables; table && table != first_not_own && !error; table= table->next_global) { TABLE *t= table->table; if (!table->placeholder() && t->s->vcols_need_refixing && table->lock_type >= TL_WRITE_ALLOW_WRITE) { + Query_arena *stmt_backup= thd->stmt_arena; + if (thd->stmt_arena->is_conventional()) + thd->stmt_arena= t->expr_arena; if (table->security_ctx) thd->security_ctx= table->security_ctx; - for (Field **vf= t->vfield; vf && *vf; vf++) - if (fix_session_vcol_expr(thd, (*vf)->vcol_info)) - goto err; - - for (Field **df= t->default_field; df && *df; df++) - if ((*df)->default_value && - fix_session_vcol_expr(thd, (*df)->default_value)) - goto err; - - for (Virtual_column_info **cc= t->check_constraints; cc && *cc; cc++) - if (fix_session_vcol_expr(thd, (*cc))) - goto err; + error= t->fix_vcol_exprs(thd); thd->security_ctx= save_security_ctx; + thd->stmt_arena= stmt_backup; } } - DBUG_RETURN(0); -err: - thd->security_ctx= save_security_ctx; - DBUG_RETURN(1); + DBUG_RETURN(error); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 655824d93fe..69bfbac6920 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3482,7 +3482,7 @@ void select_dumpvar::cleanup() Query_arena::Type Query_arena::type() const { DBUG_ASSERT(0); /* Should never be called */ - return STATEMENT; + return Type::STATEMENT; } @@ -3535,7 +3535,7 @@ Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, Query_arena::Type Statement::type() const { - return STATEMENT; + return Type::STATEMENT; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 838998af94f..c606e3ddca0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -951,9 +951,9 @@ public: enum_state state; /* We build without RTTI, so dynamic_cast can't be used. */ - enum Type + enum class Type { - STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE + STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE, TABLE }; Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) : @@ -3654,13 +3654,20 @@ public: return 0; } + + bool is_item_tree_change_register_required() + { + return !stmt_arena->is_conventional() + || stmt_arena->type() == Query_arena::Type::TABLE; + } + void change_item_tree(Item **place, Item *new_value) { DBUG_ENTER("THD::change_item_tree"); DBUG_PRINT("enter", ("Register: %p (%p) <- %p", *place, place, new_value)); /* TODO: check for OOM condition here */ - if (!stmt_arena->is_conventional()) + if (is_item_tree_change_register_required()) nocheck_register_item_tree_change(place, *place, mem_root); *place= new_value; DBUG_VOID_RETURN; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 2879e394877..543c877b7f1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7751,8 +7751,8 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, sp_cache_enforce_limit(thd->sp_proc_cache, stored_program_cache_size); sp_cache_enforce_limit(thd->sp_func_cache, stored_program_cache_size); thd->end_statement(); + thd->Item_change_list::rollback_item_tree_changes(); thd->cleanup_after_query(); - DBUG_ASSERT(thd->Item_change_list::is_empty()); } else { diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index f0c9f818f87..b2ee5abd8b6 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -338,7 +338,7 @@ find_prepared_statement(THD *thd, ulong id) thd->last_stmt : thd->stmt_map.find(id)); - if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT) + if (stmt == 0 || stmt->type() != Query_arena::Type::PREPARED_STATEMENT) return NULL; return (Prepared_statement *) stmt; @@ -3893,7 +3893,7 @@ Prepared_statement::~Prepared_statement() Query_arena::Type Prepared_statement::type() const { - return PREPARED_STATEMENT; + return Type::PREPARED_STATEMENT; } diff --git a/sql/table.cc b/sql/table.cc index 5ba996b746d..6e8c9aab12e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -47,6 +47,17 @@ #define MYSQL57_GENERATED_FIELD 128 #define MYSQL57_GCOL_HEADER_SIZE 4 +class Table_arena: public Query_arena +{ +public: + Table_arena(MEM_ROOT *mem_root, enum enum_state state_arg) : + Query_arena(mem_root, state_arg){} + virtual Type type() const + { + return Type::TABLE; + } +}; + static Virtual_column_info * unpack_vcol_info_from_frm(THD *, MEM_ROOT *, TABLE *, String *, Virtual_column_info **, bool *); static bool check_vcol_forward_refs(Field *, Virtual_column_info *); @@ -1020,8 +1031,9 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, We need to use CONVENTIONAL_EXECUTION here to ensure that any new items created by fix_fields() are not reverted. */ - table->expr_arena= new (alloc_root(mem_root, sizeof(Query_arena))) - Query_arena(mem_root, Query_arena::STMT_CONVENTIONAL_EXECUTION); + table->expr_arena= new (alloc_root(mem_root, sizeof(Table_arena))) + Table_arena(mem_root, + Query_arena::STMT_CONVENTIONAL_EXECUTION); if (!table->expr_arena) DBUG_RETURN(1); diff --git a/sql/table.h b/sql/table.h index 90a85b9b07e..f3a7f278604 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1559,6 +1559,7 @@ public: TABLE *tmp_table, TMP_TABLE_PARAM *tmp_table_param, bool with_cleanup); + int fix_vcol_exprs(THD *thd); }; From ebca70ead3604df9f64480941ac63119a90bd270 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Tue, 21 Jul 2020 23:12:32 +1000 Subject: [PATCH 02/30] fix c++98 build --- sql/sql_class.cc | 4 ++-- sql/sql_class.h | 6 +++--- sql/sql_prepare.cc | 4 ++-- sql/table.cc | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 69bfbac6920..655824d93fe 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3482,7 +3482,7 @@ void select_dumpvar::cleanup() Query_arena::Type Query_arena::type() const { DBUG_ASSERT(0); /* Should never be called */ - return Type::STATEMENT; + return STATEMENT; } @@ -3535,7 +3535,7 @@ Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, Query_arena::Type Statement::type() const { - return Type::STATEMENT; + return STATEMENT; } diff --git a/sql/sql_class.h b/sql/sql_class.h index c606e3ddca0..8d8ab779d56 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -951,9 +951,9 @@ public: enum_state state; /* We build without RTTI, so dynamic_cast can't be used. */ - enum class Type + enum Type { - STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE, TABLE + STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE, TABLE_ARENA }; Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) : @@ -3658,7 +3658,7 @@ public: bool is_item_tree_change_register_required() { return !stmt_arena->is_conventional() - || stmt_arena->type() == Query_arena::Type::TABLE; + || stmt_arena->type() == Query_arena::TABLE_ARENA; } void change_item_tree(Item **place, Item *new_value) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index b2ee5abd8b6..f0c9f818f87 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -338,7 +338,7 @@ find_prepared_statement(THD *thd, ulong id) thd->last_stmt : thd->stmt_map.find(id)); - if (stmt == 0 || stmt->type() != Query_arena::Type::PREPARED_STATEMENT) + if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT) return NULL; return (Prepared_statement *) stmt; @@ -3893,7 +3893,7 @@ Prepared_statement::~Prepared_statement() Query_arena::Type Prepared_statement::type() const { - return Type::PREPARED_STATEMENT; + return PREPARED_STATEMENT; } diff --git a/sql/table.cc b/sql/table.cc index 6e8c9aab12e..e4492f21a30 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -54,7 +54,7 @@ public: Query_arena(mem_root, state_arg){} virtual Type type() const { - return Type::TABLE; + return TABLE_ARENA; } }; From 6898eae7f8ef3f0b773687c0308520f072da0bc9 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 22 Jul 2020 11:17:43 +1000 Subject: [PATCH 03/30] fix assertion --- sql/sql_class.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 655824d93fe..0a8c136e556 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3481,7 +3481,6 @@ void select_dumpvar::cleanup() Query_arena::Type Query_arena::type() const { - DBUG_ASSERT(0); /* Should never be called */ return STATEMENT; } From 2a3bc0b9cdd7f4bd3ed57ddec6cc1fd7ca5b35d9 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 21 Jul 2020 12:49:27 +0530 Subject: [PATCH 04/30] MDEV-13830 Assertion failed: recv_sys->mlog_checkpoint_lsn <= recv_sys->recovered_lsn There can be multiple MLOG_CHECKPOINT record for the same checkpoint. During recovery, InnoDB could encounter the previous MLOG_CHECKPOINT for the checkpoint lsn. So the assertion mlog_checkpoint_lsn <= recovered_lsn is wrong. --- storage/innobase/log/log0recv.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 16980582c14..c2eb1fe7659 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -2917,8 +2917,9 @@ loop: if (lsn == checkpoint_lsn) { if (recv_sys->mlog_checkpoint_lsn) { - ut_ad(recv_sys->mlog_checkpoint_lsn - <= recv_sys->recovered_lsn); + /* There can be multiple + MLOG_CHECKPOINT lsn for the + same checkpoint. */ break; } recv_sys->mlog_checkpoint_lsn From 3a8943ae7317ad48127387855ab5258a9bb2147a Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 21 Jul 2020 13:17:53 +0530 Subject: [PATCH 05/30] MDEV-17481 mariadb service won't shutdown when it's running and the OS datetime updated backwards __pthread_cond_timedwait() in page cleaner hangs if os time moved backwards.Workaround could be waking up the page cleaner thread in logs_empty_and_mark_files_at_shutdown(). But there is possibility that server could hang when server is running. So InnoDB should wake up page cleaner thread periodically in srv_master_do_idle_tasks(). --- storage/innobase/log/log0log.cc | 3 +++ storage/innobase/srv/srv0srv.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index ea657e49d07..972bbe7c6c0 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -1936,6 +1936,9 @@ wait_suspend_loop: "Waiting for page cleaner"); ib::info() << "Waiting for page_cleaner to " "finish flushing of buffer pool"; + /* This is a workaround to avoid the InnoDB hang + when OS datetime changed backwards */ + os_event_set(buf_flush_event); count = 0; } } diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 6388f84cdea..f1216dcd51e 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -2365,6 +2365,10 @@ srv_master_do_idle_tasks(void) log_checkpoint(true); MONITOR_INC_TIME_IN_MICRO_SECS(MONITOR_SRV_CHECKPOINT_MICROSECOND, counter_time); + + /* This is a workaround to avoid the InnoDB hang when OS datetime + changed backwards.*/ + os_event_set(buf_flush_event); } /** Perform shutdown tasks. From b3dd95e035c10ad30c52f582ce519b1713c37262 Mon Sep 17 00:00:00 2001 From: Sujatha Date: Thu, 23 Jul 2020 12:54:13 +0530 Subject: [PATCH 06/30] MDEV-14203: rpl.rpl_extra_col_master_myisam, rpl.rpl_slave_load_tmpdir_not_exist failed in buildbot with a warning Problem: ======= rpl.rpl_slave_load_tmpdir_not_exist 'stmt' w3 [ fail ] Found warnings/errors in server log file! Test ended at 2017-09-27 20:34:55 [Warning] Master is configured to log replication events with checksum, but will not send such events to slaves that cannot process them ^ Found warnings in /mnt/buildbot/build/mariadb-10.2.10/mysql-test/var/3/log/mysqld.1.err ok Analysis: ======== When slave tries to connect to master 'get_master_version_and_clock' function is invoked to perform elaborated slave-master handshake. During this process slave server queries master server, to know if it is checksum aware and at the same time master is notified about its CRC-awareness. The master's side instant value of @@global.binlog_checksum is stored in the dump thread's uservar area as well as cached locally to become known in consensus by master and slave. Post hand-shake slave requests master for binlog dump. It sends 'COM_BINLOG_DUMP'. This command is sent to master by 'cli_advanced_command' call. If there is some temporary network failure during this request_dump call, 'end_server' is invoked to close the current connection between master and slave. Upon connection close the dump thread on the master gets terminated and it clears the 'uservar' data it got through master-slave handshake. The 'COM_BINLOG_DUMP' command is sent once again without master-slave handshake. Since the checksum data is not available with new dump thread a warning gets reported. Fix: === Upon network write error donot attempt reconnect, proceed to master-slave handshake. This ensures that master is aware of slave's capability to use checksums. --- .../r/rpl_dump_request_retry_warning.result | 22 +++++++ .../rpl/t/rpl_dump_request_retry_warning.test | 60 +++++++++++++++++++ sql-common/client.c | 2 + sql/net_serv.cc | 12 ++++ sql/slave.cc | 3 +- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/rpl/r/rpl_dump_request_retry_warning.result create mode 100644 mysql-test/suite/rpl/t/rpl_dump_request_retry_warning.test diff --git a/mysql-test/suite/rpl/r/rpl_dump_request_retry_warning.result b/mysql-test/suite/rpl/r/rpl_dump_request_retry_warning.result new file mode 100644 index 00000000000..3a80d5b5f31 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_dump_request_retry_warning.result @@ -0,0 +1,22 @@ +include/master-slave.inc +[connection master] +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES(1); +connection slave; +SET @saved_dbug = @@GLOBAL.debug_dbug; +SET @@global.debug_dbug= 'd,simulate_error_on_packet_write'; +START SLAVE; +SET DEBUG_SYNC= 'now WAIT_FOR parked'; +SET @@GLOBAL.debug_dbug = @saved_dbug; +SET DEBUG_SYNC= 'now SIGNAL continue'; +SET DEBUG_SYNC= 'RESET'; +include/wait_for_slave_io_to_start.inc +include/wait_for_slave_sql_to_start.inc +connection master; +include/sync_slave_sql_with_master.inc +SELECT * FROM t1; +a +1 +connection master; +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_dump_request_retry_warning.test b/mysql-test/suite/rpl/t/rpl_dump_request_retry_warning.test new file mode 100644 index 00000000000..d750d44ae71 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_dump_request_retry_warning.test @@ -0,0 +1,60 @@ +# ==== Purpose ==== +# +# Test verifies that, due to a temporary network error, if request dump +# command specific packet write operation fails then the write error gets +# handled appropriately. Further retry will be initiated with appropriate +# slave registration on master. This will ensure that master has all the +# details of slave and no warnings are reported on the master side. +# +# ==== Implementation ==== +# +# Steps: +# 0 - Skip the slave start. +# 1 - Enable debug simulation which will simulate packet write error during +# dump request command execution. +# 2 - Start the slave. Observe that slave is able to reconnect post +# temporary network write error. +# +# ==== References ==== +# +# MDEV-14203: rpl.rpl_extra_col_master_myisam, +# rpl.rpl_slave_load_tmpdir_not_exist failed in buildbot with a +# warning +# +# MDEV-13258: rpl.rpl_skip_replication, rpl.rpl_set_statement_default_master +# failed in buildbot +# + +--source include/have_debug.inc +--source include/have_debug_sync.inc +--let $rpl_skip_start_slave=1 +--source include/master-slave.inc + +# Do an insert on master +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES(1); + +# Add a debug point and start the slave so that dump request fails. +connection slave; +SET @saved_dbug = @@GLOBAL.debug_dbug; +SET @@global.debug_dbug= 'd,simulate_error_on_packet_write'; + +START SLAVE; +SET DEBUG_SYNC= 'now WAIT_FOR parked'; +SET @@GLOBAL.debug_dbug = @saved_dbug; +SET DEBUG_SYNC= 'now SIGNAL continue'; +SET DEBUG_SYNC= 'RESET'; + +--source include/wait_for_slave_io_to_start.inc +--source include/wait_for_slave_sql_to_start.inc + +# Sync the slave and verify that slave has caught up with the master. +connection master; +--source include/sync_slave_sql_with_master.inc +SELECT * FROM t1; + +# Cleanup +connection master; +DROP TABLE t1; + +--source include/rpl_end.inc diff --git a/sql-common/client.c b/sql-common/client.c index 227759f4163..b66eee2a508 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -721,6 +721,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate); goto end; } + if (net->last_errno == ER_NET_ERROR_ON_WRITE && command == COM_BINLOG_DUMP) + goto end; end_server(mysql); if (mysql_reconnect(mysql) || stmt_skip) goto end; diff --git a/sql/net_serv.cc b/sql/net_serv.cc index f39eaaadf46..dc24360851e 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -45,6 +45,7 @@ #include #include #include "probes_mysql.h" +#include #ifdef EMBEDDED_LIBRARY #undef MYSQL_SERVER @@ -486,6 +487,17 @@ net_write_command(NET *net,uchar command, DBUG_ENTER("net_write_command"); DBUG_PRINT("enter",("length: %lu", (ulong) len)); + DBUG_EXECUTE_IF("simulate_error_on_packet_write", + { + if (command == COM_BINLOG_DUMP) + { + net->last_errno = ER_NET_ERROR_ON_WRITE; + DBUG_ASSERT(!debug_sync_set_action( + (THD *)net->thd, + STRING_WITH_LEN("now SIGNAL parked WAIT_FOR continue"))); + DBUG_RETURN(true); + } + };); MYSQL_NET_WRITE_START(length); buff[4]=command; /* For first packet */ diff --git a/sql/slave.cc b/sql/slave.cc index 1bf83aa9652..87eacfcfd0a 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3297,7 +3297,8 @@ static int request_dump(THD *thd, MYSQL* mysql, Master_info* mi, in the future, we should do a better error analysis, but for now we just fill up the error log :-) */ - if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) + if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED || + mysql_errno(mysql) == ER_NET_ERROR_ON_WRITE) *suppress_warnings= TRUE; // Suppress reconnect warning else sql_print_error("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs", From fe39d02f51b96536dccca7ff89faf05e13548877 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 23 Jul 2020 16:23:20 +0530 Subject: [PATCH 07/30] MDEV-20638 Remove the deadcode from srv_master_thread() and srv_active_wake_master_thread_low() - Due to commit fe95cb2e40d73adbbe88efa0e7f48c055ccd042f (MDEV-16125), InnoDB master thread does not need to call srv_resume_thread() and therefore there is no need to wake up the thread. Due to the above patch, InnoDB should remove the following dead code. srv_check_activity(): Makes the parameter as in,out and returns the recent activity value innobase_active_small(): Removed srv_active_wake_master_thread(): Removed srv_wake_master_thread(): Removed srv_active_wake_master_thread_low(): Removed Simplify srv_master_thread() and remove switch cases, added the assert. Replace srv_wake_master_thread() with srv_inc_activity_count() INNOBASE_WAKE_INTERVAL: Removed --- extra/mariabackup/xtrabackup.cc | 6 -- storage/innobase/buf/buf0flu.cc | 4 +- storage/innobase/handler/ha_innodb.cc | 48 ----------- storage/innobase/handler/handler0alter.cc | 5 -- storage/innobase/include/srv0srv.h | 25 ++---- storage/innobase/row/row0mysql.cc | 2 +- storage/innobase/row/row0trunc.cc | 2 +- storage/innobase/srv/srv0srv.cc | 100 +++++----------------- storage/innobase/srv/srv0start.cc | 4 +- storage/innobase/trx/trx0roll.cc | 3 - storage/innobase/trx/trx0trx.cc | 6 -- 11 files changed, 35 insertions(+), 170 deletions(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index b1120ba29f7..02d232b59d6 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -254,12 +254,6 @@ my_bool innobase_locks_unsafe_for_binlog; my_bool innobase_rollback_on_timeout; my_bool innobase_create_status_file; -/* The following counter is used to convey information to InnoDB -about server activity: in selects it is not sensible to call -srv_active_wake_master_thread after each fetch or search, we only do -it every INNOBASE_WAKE_INTERVAL'th step. */ - -#define INNOBASE_WAKE_INTERVAL 32 ulong innobase_active_counter = 0; diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 26610337d0d..84f95f4b5ec 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -3141,7 +3141,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_coordinator)(void*) /* The page_cleaner skips sleep if the server is idle and there are no pending IOs in the buffer pool and there is work to do. */ - if (srv_check_activity(last_activity) + if (srv_check_activity(&last_activity) || buf_get_n_pending_read_ios() || n_flushed == 0) { @@ -3233,7 +3233,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_coordinator)(void*) n_flushed = n_flushed_lru + n_flushed_list; - } else if (srv_check_activity(last_activity)) { + } else if (srv_check_activity(&last_activity)) { ulint n_to_flush; lsn_t lsn_limit = 0; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index bb648d99777..3d303889a53 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -446,14 +446,6 @@ static TYPELIB innodb_lock_schedule_algorithm_typelib = { NULL }; -/* The following counter is used to convey information to InnoDB -about server activity: in case of normal DML ops it is not -sensible to call srv_active_wake_master_thread after each -operation, we only do it every INNOBASE_WAKE_INTERVAL'th step. */ - -#define INNOBASE_WAKE_INTERVAL 32 -static ulong innobase_active_counter = 0; - /** Allowed values of innodb_change_buffering */ static const char* innobase_change_buffering_values[IBUF_USE_COUNT] = { "none", /* IBUF_USE_NONE */ @@ -1893,23 +1885,6 @@ thd_to_trx_id( } #endif /* WITH_WSREP */ -/********************************************************************//** -Increments innobase_active_counter and every INNOBASE_WAKE_INTERVALth -time calls srv_active_wake_master_thread. This function should be used -when a single database operation may introduce a small need for -server utility activity, like checkpointing. */ -inline -void -innobase_active_small(void) -/*=======================*/ -{ - innobase_active_counter++; - - if ((innobase_active_counter % INNOBASE_WAKE_INTERVAL) == 0) { - srv_active_wake_master_thread(); - } -} - /********************************************************************//** Converts an InnoDB error code to a MySQL error code and also tells to MySQL about a possible transaction rollback inside InnoDB caused by a lock wait @@ -6655,11 +6630,6 @@ ha_innobase::close() MONITOR_INC(MONITOR_TABLE_CLOSE); - /* Tell InnoDB server that there might be work for - utility threads: */ - - srv_active_wake_master_thread(); - DBUG_RETURN(0); } @@ -8374,8 +8344,6 @@ report_error: } func_exit: - innobase_active_small(); - DBUG_RETURN(error_result); } @@ -9046,11 +9014,6 @@ func_exit: error, m_prebuilt->table->flags, m_user_thd); } - /* Tell InnoDB server that there might be work for - utility threads: */ - - innobase_active_small(); - #ifdef WITH_WSREP if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(m_user_thd) == LOCAL_STATE && @@ -9106,11 +9069,6 @@ ha_innobase::delete_row( innobase_srv_conc_exit_innodb(m_prebuilt); - /* Tell the InnoDB server that there might be work for - utility threads: */ - - innobase_active_small(); - #ifdef WITH_WSREP if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(m_user_thd) == LOCAL_STATE @@ -12998,7 +12956,6 @@ create_table_info_t::create_table_update_dict() if (m_flags2 & DICT_TF2_FTS) { if (!innobase_fts_load_stopword(innobase_table, NULL, m_thd)) { dict_table_close(innobase_table, FALSE, FALSE); - srv_active_wake_master_thread(); trx_free_for_mysql(m_trx); DBUG_RETURN(-1); } @@ -13144,11 +13101,6 @@ ha_innobase::create( error = info.create_table_update_dict(); - /* Tell the InnoDB server that there might be work for - utility threads: */ - - srv_active_wake_master_thread(); - DBUG_RETURN(error); } diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index db161ba50d8..782b0d9efb2 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -8637,11 +8637,6 @@ foreign_fail: log_append_on_checkpoint(NULL); - /* Tell the InnoDB server that there might be work for - utility threads: */ - - srv_active_wake_master_thread(); - if (fail) { for (inplace_alter_handler_ctx** pctx = ctx_array; *pctx; pctx++) { diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index 5214953f308..20130541d60 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -809,19 +809,6 @@ srv_reset_io_thread_op_info(); /** Wake up the purge threads if there is work to do. */ void srv_wake_purge_thread_if_not_active(); -/** Wake up the InnoDB master thread if it was suspended (not sleeping). */ -void -srv_active_wake_master_thread_low(); - -#define srv_active_wake_master_thread() \ - do { \ - if (!srv_read_only_mode) { \ - srv_active_wake_master_thread_low(); \ - } \ - } while (0) -/** Wake up the master thread if it is suspended or being suspended. */ -void -srv_wake_master_thread(); /******************************************************************//** Outputs to a file the output of the InnoDB Monitor. @@ -850,13 +837,13 @@ reading this value as it is only used in heuristics. ulint srv_get_activity_count(void); /*========================*/ -/*******************************************************************//** -Check if there has been any activity. + +/** Check if there has been any activity. +@param[in,out] activity_count recent activity count to be returned +if there is a change @return FALSE if no change in activity counter. */ -ibool -srv_check_activity( -/*===============*/ - ulint old_activity_count); /*!< old activity count */ +bool srv_check_activity(ulint *activity_count); + /******************************************************************//** Increment the server activity counter. */ void diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index b304c03f7ed..7c61ad9b45b 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -3820,7 +3820,7 @@ funct_exit: trx->op_info = ""; - srv_wake_master_thread(); + srv_inc_activity_count(); DBUG_RETURN(err); } diff --git a/storage/innobase/row/row0trunc.cc b/storage/innobase/row/row0trunc.cc index 618e161bee4..209767d0fe1 100644 --- a/storage/innobase/row/row0trunc.cc +++ b/storage/innobase/row/row0trunc.cc @@ -1249,7 +1249,7 @@ row_truncate_complete( ut_ad(!trx_is_started(trx)); - srv_wake_master_thread(); + srv_inc_activity_count(); DBUG_EXECUTE_IF("ib_trunc_crash_after_truncate_done", DBUG_SUICIDE();); diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index f1216dcd51e..6bf8e3dd8f6 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -1982,33 +1982,6 @@ srv_get_active_thread_type(void) return(ret); } -/** Wake up the InnoDB master thread if it was suspended (not sleeping). */ -void -srv_active_wake_master_thread_low() -{ - ut_ad(!srv_read_only_mode); - ut_ad(!srv_sys_mutex_own()); - - srv_inc_activity_count(); - - if (my_atomic_loadlint(&srv_sys.n_threads_active[SRV_MASTER]) == 0) { - srv_slot_t* slot; - - srv_sys_mutex_enter(); - - slot = &srv_sys.sys_threads[SRV_MASTER_SLOT]; - - /* Only if the master thread has been started. */ - - if (slot->in_use) { - ut_a(srv_slot_get_type(slot) == SRV_MASTER); - os_event_set(slot->event); - } - - srv_sys_mutex_exit(); - } -} - /** Wake up the purge threads if there is work to do. */ void srv_wake_purge_thread_if_not_active() @@ -2023,14 +1996,6 @@ srv_wake_purge_thread_if_not_active() } } -/** Wake up the master thread if it is suspended or being suspended. */ -void -srv_wake_master_thread() -{ - srv_inc_activity_count(); - srv_release_threads(SRV_MASTER, 1); -} - /*******************************************************************//** Get current server activity count. We don't hold srv_sys::mutex while reading this value as it is only used in heuristics. @@ -2042,15 +2007,20 @@ srv_get_activity_count(void) return(srv_sys.activity_count); } -/*******************************************************************//** -Check if there has been any activity. +/** Check if there has been any activity. +@param[in,out] activity_count recent activity count to be returned +if there is a change @return FALSE if no change in activity counter. */ -ibool -srv_check_activity( -/*===============*/ - ulint old_activity_count) /*!< in: old activity count */ +bool srv_check_activity(ulint *activity_count) { - return(srv_sys.activity_count != old_activity_count); + ulint new_activity_count= srv_sys.activity_count; + if (new_activity_count != *activity_count) + { + *activity_count= new_activity_count; + return true; + } + + return false; } /********************************************************************//** @@ -2457,52 +2427,30 @@ DECLARE_THREAD(srv_master_thread)( slot = srv_reserve_slot(SRV_MASTER); ut_a(slot == srv_sys.sys_threads); -loop: while (srv_shutdown_state <= SRV_SHUTDOWN_INITIATED) { srv_master_sleep(); MONITOR_INC(MONITOR_MASTER_THREAD_SLEEP); - if (srv_check_activity(old_activity_count)) { - old_activity_count = srv_get_activity_count(); + if (srv_check_activity(&old_activity_count)) { srv_master_do_active_tasks(); } else { srv_master_do_idle_tasks(); } } - switch (srv_shutdown_state) { - case SRV_SHUTDOWN_NONE: - case SRV_SHUTDOWN_INITIATED: - break; - case SRV_SHUTDOWN_FLUSH_PHASE: - case SRV_SHUTDOWN_LAST_PHASE: - ut_ad(0); - /* fall through */ - case SRV_SHUTDOWN_EXIT_THREADS: - /* srv_init_abort() must have been invoked */ - case SRV_SHUTDOWN_CLEANUP: - if (srv_shutdown_state == SRV_SHUTDOWN_CLEANUP - && srv_fast_shutdown < 2) { - srv_shutdown(srv_fast_shutdown == 0); - } - srv_suspend_thread(slot); - my_thread_end(); - os_thread_exit(); + ut_ad(srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS + || srv_shutdown_state == SRV_SHUTDOWN_CLEANUP); + + if (srv_shutdown_state == SRV_SHUTDOWN_CLEANUP + && srv_fast_shutdown < 2) { + srv_shutdown(srv_fast_shutdown == 0); } - srv_main_thread_op_info = "suspending"; - srv_suspend_thread(slot); - - /* DO NOT CHANGE THIS STRING. innobase_start_or_create_for_mysql() - waits for database activity to die down when converting < 4.1.x - databases, and relies on this string being exactly as it is. InnoDB - manual also mentions this string in several places. */ - srv_main_thread_op_info = "waiting for server activity"; - - srv_resume_thread(slot); - goto loop; + my_thread_end(); + os_thread_exit(); + OS_THREAD_DUMMY_RETURN; } /** Check if purge should stop. @@ -2699,15 +2647,13 @@ srv_do_purge(ulint* n_total_purged ++n_use_threads; } - } else if (srv_check_activity(old_activity_count) + } else if (srv_check_activity(&old_activity_count) && n_use_threads > 1) { /* History length same or smaller since last snapshot, use fewer threads. */ --n_use_threads; - - old_activity_count = srv_get_activity_count(); } /* Ensure that the purge threads are less than what diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 0d8ebbe98cd..a8f2b78d0a8 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1238,7 +1238,7 @@ srv_shutdown_all_bg_threads() if (srv_start_state_is_set(SRV_START_STATE_MASTER)) { /* c. We wake the master thread so that it exits */ - srv_wake_master_thread(); + srv_inc_activity_count(); } if (srv_start_state_is_set(SRV_START_STATE_PURGE)) { @@ -2762,7 +2762,7 @@ srv_shutdown_bg_undo_sources() fts_optimize_shutdown(); dict_stats_shutdown(); while (row_get_background_drop_list_len_low()) { - srv_wake_master_thread(); + srv_inc_activity_count(); os_thread_yield(); } srv_undo_sources = false; diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index 127cfc9b07d..de749f993e7 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -124,9 +124,6 @@ trx_rollback_to_savepoint_low( mem_heap_free(heap); - /* There might be work for utility threads.*/ - srv_active_wake_master_thread(); - MONITOR_DEC(MONITOR_TRX_ACTIVE); } diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index d4cd020b321..0dbd985b6c3 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -1804,12 +1804,6 @@ trx_commit_in_memory( } trx->commit_lsn = lsn; - - /* Tell server some activity has happened, since the trx - does changes something. Background utility threads like - master thread, purge thread or page_cleaner thread might - have some work to do. */ - srv_active_wake_master_thread(); } ut_ad(!trx->rsegs.m_noredo.undo); From b3b1c51e4de0866bd1baae888eacb86c2d3b3698 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 23 Jul 2020 20:43:09 +0530 Subject: [PATCH 08/30] MDEV-23134 SEGV in dict_load_table_one during restart after server crash Problem: ======== dict_load_table_one() doesn't handle the scenario where clustered index page is FIL_NULL when DICT_ERR_IGNORE_INDEX_ROOT mode is set. Fix: ==== InnoDB should set the file_unreadable when it can't find the clustered index root page. --- storage/innobase/dict/dict0dict.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 5fb6f676e80..84478d7528b 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -5804,6 +5804,7 @@ dict_set_corrupted_index_cache_only( is corrupted */ if (dict_index_is_clust(index)) { index->table->corrupted = TRUE; + index->table->file_unreadable = true; } index->type |= DICT_CORRUPT; From ba23e6d76fde4abdb6666e8d78af98ce6d2414e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 23 Jul 2020 08:59:18 +0300 Subject: [PATCH 09/30] MDEV-18177 : Galera test failure on galera_autoinc_sst_mariabackup Add wait_condition --- mysql-test/suite/galera/include/galera_st_clean_slave.inc | 6 ++++++ .../suite/galera/include/galera_st_disconnect_slave.inc | 6 ++++++ mysql-test/suite/galera/include/galera_st_kill_slave.inc | 6 ++++++ .../suite/galera/include/galera_st_kill_slave_ddl.inc | 5 +++++ .../suite/galera/include/galera_st_shutdown_slave.inc | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/mysql-test/suite/galera/include/galera_st_clean_slave.inc b/mysql-test/suite/galera/include/galera_st_clean_slave.inc index 3a49f4f6ad2..44cbf67fd12 100644 --- a/mysql-test/suite/galera/include/galera_st_clean_slave.inc +++ b/mysql-test/suite/galera/include/galera_st_clean_slave.inc @@ -102,12 +102,18 @@ INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); ROLLBACK; +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; COMMIT; SET AUTOCOMMIT=ON; --connection node_1 +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; DROP TABLE t1; diff --git a/mysql-test/suite/galera/include/galera_st_disconnect_slave.inc b/mysql-test/suite/galera/include/galera_st_disconnect_slave.inc index c8869746bd1..4674fc7867f 100644 --- a/mysql-test/suite/galera/include/galera_st_disconnect_slave.inc +++ b/mysql-test/suite/galera/include/galera_st_disconnect_slave.inc @@ -92,12 +92,18 @@ INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); ROLLBACK; +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; COMMIT; SET AUTOCOMMIT=ON; --connection node_1 +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; DROP TABLE t1; diff --git a/mysql-test/suite/galera/include/galera_st_kill_slave.inc b/mysql-test/suite/galera/include/galera_st_kill_slave.inc index 0b96de55a32..a4d9e91e8be 100644 --- a/mysql-test/suite/galera/include/galera_st_kill_slave.inc +++ b/mysql-test/suite/galera/include/galera_st_kill_slave.inc @@ -96,12 +96,18 @@ INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); ROLLBACK; +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; COMMIT; SET AUTOCOMMIT=ON; --connection node_1 +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; DROP TABLE t1; diff --git a/mysql-test/suite/galera/include/galera_st_kill_slave_ddl.inc b/mysql-test/suite/galera/include/galera_st_kill_slave_ddl.inc index 44a1513fa6e..bb8c68bd181 100644 --- a/mysql-test/suite/galera/include/galera_st_kill_slave_ddl.inc +++ b/mysql-test/suite/galera/include/galera_st_kill_slave_ddl.inc @@ -110,6 +110,9 @@ INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); INSERT INTO t1 (f1) VALUES ('node1_to_be_rollbacked_after'); ROLLBACK; +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 2 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't1'; SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; @@ -117,6 +120,8 @@ COMMIT; SET AUTOCOMMIT=ON; --connection node_1 +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc SELECT COUNT(*) = 2 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't1'; SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; diff --git a/mysql-test/suite/galera/include/galera_st_shutdown_slave.inc b/mysql-test/suite/galera/include/galera_st_shutdown_slave.inc index 207282c8237..eeb6a15e0a3 100644 --- a/mysql-test/suite/galera/include/galera_st_shutdown_slave.inc +++ b/mysql-test/suite/galera/include/galera_st_shutdown_slave.inc @@ -97,12 +97,18 @@ INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); INSERT INTO t1 VALUES ('node1_to_be_rollbacked_after'); ROLLBACK; +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; COMMIT; SET AUTOCOMMIT=ON; --connection node_1 +--let $wait_condition = SELECT COUNT(*)=35 FROM t1 +--source include/wait_condition.inc + SELECT COUNT(*) = 35 FROM t1; SELECT COUNT(*) = 0 FROM (SELECT COUNT(*) AS c, f1 FROM t1 GROUP BY f1 HAVING c NOT IN (5, 10)) AS a1; DROP TABLE t1; From c9928cc0fb1ddbe9253105f8cd2db0104e739ede Mon Sep 17 00:00:00 2001 From: sjaakola Date: Tue, 23 Jun 2020 10:23:40 +0300 Subject: [PATCH 10/30] MDEV-20928 mtr test galera.galera_var_innodb_disallow_writes test failure The sporadic test hangs happen because of mutex dealock between innodb background threads and two test connection executions. The test sets variable innodb_disallow_writes, which blocks all writes to filesyste. The test logic is to execute an INSERT, which should hang because of filesytstem writes are blocked, and through another session verify by SELECT that this hanging happens. The SELECT session will then release innodb_disallow_writes blocking. However, filesystem write blocking affects also innodb background threads and they may hang while keeping some other resources locked. As an example, in one test hang situation, buffer pool access was blocked. And, if buffer pool is blocked, the test connections will be blocked as well, and the SELECT session will not be able to continue to release the innodb_disallow_writes. The fix in this commit is refactoring of the test logic. The test will now set first innodb_disallow_writes blocking, and then record a hash of data directory's filesystem contents. This works as checksum of the state of data on the datadirectory. Then some SQL load is tried on both nodes, these sessions will be blocking due to frozen file system state. The test will have a short sleep to allow innodb background threads to loop and possibly encounter innodb_disallow_writes blocking as well. After the sleep, the test will record file system checksun for the second time, and then release the innodb_disallow-writes blocking. Finally, the two checksums are compared, they should be identical to verify that nothing was written on datadirectory during the test execution. The checksum is implemented by md5sum hash over all files found in datadirectory by find command. all these file hashes are hashed together by one more md5sum. The test therefore depends on md5sum and find. find may work differently with some OS distributions, e.g. freebsd may be problematic. --- .../galera_var_innodb_disallow_writes.result | 33 ++++++----- .../t/galera_var_innodb_disallow_writes.test | 58 ++++++++++++++----- 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_var_innodb_disallow_writes.result b/mysql-test/suite/galera/r/galera_var_innodb_disallow_writes.result index 54cebbee40c..8750651612d 100644 --- a/mysql-test/suite/galera/r/galera_var_innodb_disallow_writes.result +++ b/mysql-test/suite/galera/r/galera_var_innodb_disallow_writes.result @@ -1,25 +1,28 @@ -connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; connection node_1a; SET SESSION wsrep_sync_wait = 0; connection node_1; -CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB; +CREATE TABLE t1 (f1 INTEGER, f2 varchar(1024)) Engine=InnoDB; +CREATE TABLE ten (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO ten VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); SET GLOBAL innodb_disallow_writes=ON; -INSERT INTO t1 VALUES (1);; +INSERT INTO t1 (f2) SELECT 'abcde ' FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4;; +connection node_2; +INSERT INTO t1 (f2) SELECT 'fghij ' FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 connection node_1a; -SELECT COUNT(*) AS EXPECT_0 FROM t1; -EXPECT_0 -0 -SELECT COUNT(*) AS EXPECT_0 FROM t1; -EXPECT_0 -0 SET GLOBAL innodb_disallow_writes=OFF; connection node_1; -SELECT COUNT(*) AS EXPECT_1 FROM t1; -EXPECT_1 -1 +SELECT COUNT(*) AS EXPECT_20000 FROM t1; +EXPECT_20000 +20000 +connection node_2; +SELECT COUNT(*) AS EXPECT_20000 FROM t1; +EXPECT_20000 +20000 +connection node_1; connection node_2; -SELECT COUNT(*) AS EXPECT_1 FROM t1; -EXPECT_1 -1 DROP TABLE t1; +DROP TABLE ten; disconnect node_1a; diff --git a/mysql-test/suite/galera/t/galera_var_innodb_disallow_writes.test b/mysql-test/suite/galera/t/galera_var_innodb_disallow_writes.test index 3754cff0123..0d2a6effd92 100644 --- a/mysql-test/suite/galera/t/galera_var_innodb_disallow_writes.test +++ b/mysql-test/suite/galera/t/galera_var_innodb_disallow_writes.test @@ -1,41 +1,71 @@ # # This test checks that innodb_disallow_writes works as expected # +# Note that we need to enable binlog for this test: If the commit +# to InnoDB is done in one phase, the transaction is committed in +# memory before it is persisted to disk. This means that the +# innodb_disallow_writes=ON may not prevent transaction to +# become visible to other readers. On the other hand, if the +# commit is two phase (as it is with binlog), the transaction +# will be blocked in prepare phase. +# --source include/galera_cluster.inc +--source include/have_innodb.inc + +--let $datadir= `SELECT @@datadir` + # Open a separate connection to be used to run SHOW PROCESSLIST ---connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--let $galera_connection_name = node_1a +--let $galera_server_number = 1 +--source include/galera_connect.inc --connection node_1a SET SESSION wsrep_sync_wait = 0; --connection node_1 -CREATE TABLE t1 (f1 INTEGER) Engine=InnoDB; +CREATE TABLE t1 (f1 INTEGER, f2 varchar(1024)) Engine=InnoDB; +CREATE TABLE ten (f1 INTEGER) ENGINE=InnoDB; +INSERT INTO ten VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); + SET GLOBAL innodb_disallow_writes=ON; ---send INSERT INTO t1 VALUES (1); +--exec find $datadir -type f-exec md5sum {} \; | md5sum >$MYSQLTEST_VARDIR/tmp/innodb_before + +# +# This insert has no effect before innodb_disallow_writes is OFF +# +--send INSERT INTO t1 (f2) SELECT 'abcde ' FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4; + +--connection node_2 +INSERT INTO t1 (f2) SELECT 'fghij ' FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_1a ---let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'test/t1'; ---source include/wait_condition.inc -SELECT COUNT(*) AS EXPECT_0 FROM t1; -let $wait_condition = SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO = 'INSERT INTO t1 VALUES (1)'; ---source include/wait_condition.inc -SELECT COUNT(*) AS EXPECT_0 FROM t1; +--sleep 5 + +--exec find $datadir -type f-exec md5sum {} \; | md5sum >$MYSQLTEST_VARDIR/tmp/innodb_after SET GLOBAL innodb_disallow_writes=OFF; --connection node_1 --reap -SELECT COUNT(*) AS EXPECT_1 FROM t1; +--let $wait_condition = SELECT COUNT(*) = 20000 FROM t1; +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_20000 FROM t1; --connection node_2 ---let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'test/t1'; +--let $wait_condition = SELECT COUNT(*) = 20000 FROM t1; --source include/wait_condition.inc ---let $wait_condition = SELECT COUNT(*) = 1 FROM t1; ---source include/wait_condition.inc -SELECT COUNT(*) AS EXPECT_1 FROM t1; +SELECT COUNT(*) AS EXPECT_20000 FROM t1; + +--connection node_1 +--diff_files $MYSQLTEST_VARDIR/tmp/innodb_before $MYSQLTEST_VARDIR/tmp/innodb_after + +--connection node_2 DROP TABLE t1; +DROP TABLE ten; --disconnect node_1a From a3a249c72f07bf3270c059f60f68df030179f104 Mon Sep 17 00:00:00 2001 From: mkaruza Date: Mon, 20 Jul 2020 14:16:19 +0200 Subject: [PATCH 11/30] MDEV-15236: galera_ist_progress fails when trying to read transfer status Fixed by new recording test recording --- mysql-test/suite/galera/disabled.def | 1 - mysql-test/suite/galera/r/galera_ist_progress.result | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 125ea03474f..331260ef84e 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -17,7 +17,6 @@ galera_as_slave_replication_bundle : MDEV-15785 OPTION_GTID_BEGIN is set in Gtid galera_autoinc_sst_mariabackup : Known issue, may require porting MDEV-17458 from later versions galera_binlog_stmt_autoinc : MDEV-19959 Galera test failure on galera_binlog_stmt_autoinc galera_gcache_recover_manytrx : MDEV-18834 Galera test failure -galera_ist_progress : MDEV-15236 fails when trying to read transfer status galera_load_data : MDEV-19968 galera.galera_load_data galera_parallel_simple : MDEV-20318 galera.galera_parallel_simple fails galera_shutdown_nonprim : MDEV-21493 galera.galera_shutdown_nonprim diff --git a/mysql-test/suite/galera/r/galera_ist_progress.result b/mysql-test/suite/galera/r/galera_ist_progress.result index 9fc7febbea5..ed36a217624 100644 --- a/mysql-test/suite/galera/r/galera_ist_progress.result +++ b/mysql-test/suite/galera/r/galera_ist_progress.result @@ -1,6 +1,10 @@ +connection node_2; SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 1'; +connection node_1; +connection node_2; SET SESSION wsrep_on = OFF; SET SESSION wsrep_on = ON; +connection node_1; CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (2); @@ -12,8 +16,13 @@ INSERT INTO t1 VALUES (7); INSERT INTO t1 VALUES (8); INSERT INTO t1 VALUES (9); INSERT INTO t1 VALUES (10); +connection node_2; SET GLOBAL wsrep_provider_options = 'gmcast.isolate = 0'; +connection node_1; +connection node_2; +connection node_1; include/assert_grep.inc [Receiving IST: 11 writesets, seqnos] include/assert_grep.inc [Receiving IST\.\.\. 0\.0% \( 0/11 events\) complete] include/assert_grep.inc [Receiving IST\.\.\.100\.0% \(11/11 events\) complete] +connection node_1; DROP TABLE t1; From 5f1ec5cbb78a427ff260888bef5e19daa36b10e2 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 23 Jul 2020 16:59:30 +0530 Subject: [PATCH 12/30] MDEV-14711 Assertion `mode == 16 || mode == 12 || !fix_block->page.file_page_was_freed' failed in buf_page_get_gen (rollback requesting a freed undo page) Problem: ======= In buf_cur_optimistic_latch_leaves(), requesting a left block with BTR_GET after releasing current block. But there is no guarantee that left block could be still available. Fix: ==== (1) In btr_cur_optimistic_latch_leaves(), replace the BUF_GET with BUF_GET_POSSIBLY_FREED for fetching left block. (2) Once InnoDB acquires left block, it should check FIL_PAGE_NEXT with current block page number. If not, release cursor->left_block and return false. --- storage/innobase/btr/btr0cur.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 35e578e1a5c..bacc05686e9 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -415,6 +415,7 @@ btr_cur_optimistic_latch_leaves( { ulint mode; ulint left_page_no; + ulint curr_page_no; switch (*latch_mode) { case BTR_SEARCH_LEAF: @@ -441,6 +442,8 @@ btr_cur_optimistic_latch_leaves( goto unpin_failed; } + + curr_page_no = block->page.id.page_no(); left_page_no = btr_page_get_prev( buf_block_get_frame(block)); rw_lock_s_unlock(&block->lock); @@ -449,11 +452,26 @@ btr_cur_optimistic_latch_leaves( const page_id_t page_id( dict_index_get_space(cursor->index), left_page_no); + dberr_t err = DB_SUCCESS; - cursor->left_block = btr_block_get( + cursor->left_block = buf_page_get_gen( page_id, dict_table_page_size(cursor->index->table), - mode, cursor->index, mtr); + mode, NULL, BUF_GET_POSSIBLY_FREED, + __FILE__, __LINE__, mtr, &err); + + if (err == DB_DECRYPTION_FAILED) { + cursor->index->table->file_unreadable = true; + } + + if (btr_page_get_next(buf_block_get_frame( + cursor->left_block)) + != curr_page_no) { + /* release the left block */ + btr_leaf_page_release( + cursor->left_block, mode, mtr); + return false; + } } else { cursor->left_block = NULL; } From a6410deba99d5060a8c3fc0d5f267100125dc6ac Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 27 Jul 2020 13:53:33 +0530 Subject: [PATCH 13/30] MDEV-18916: crash in Window_spec::print_partition() with decimals Removed an unnecessary ifndef which was printing the window name for a named window only in the case of debug build. The print() for the window function should behave in the same way on both release and debug builds. --- mysql-test/r/win.result | 7 +++++++ mysql-test/t/win.test | 9 +++++++++ sql/item_windowfunc.cc | 6 ++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 019cfd6115d..081aaedd323 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3843,5 +3843,12 @@ ROW_NUMBER() OVER w2 5 DROP TABLE t1; # +# MDEV-18916: crash in Window_spec::print_partition() with decimals +# +SELECT cast((rank() over w1) as decimal (53,56)); +ERROR 42000: Too big scale 56 specified for 'rank() over w1'. Maximum is 38 +SELECT cast((rank() over w1) as decimal (53,30)); +ERROR HY000: Window specification with name 'w1' is not defined +# # End of 10.2 tests # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index deed7de2d23..b749b235082 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2497,6 +2497,15 @@ SELECT a,b FROM t1 WINDOW w2 AS (PARTITION BY -1,1,0,2,3,4); SELECT ROW_NUMBER() OVER w2 FROM t1 WINDOW w2 AS (PARTITION BY -1,0,1,2,3,4,5,6); DROP TABLE t1; +--echo # +--echo # MDEV-18916: crash in Window_spec::print_partition() with decimals +--echo # + +--error ER_TOO_BIG_SCALE +SELECT cast((rank() over w1) as decimal (53,56)); +--error ER_WRONG_WINDOW_SPEC_NAME +SELECT cast((rank() over w1) as decimal (53,30)); + --echo # --echo # End of 10.2 tests --echo # diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index a3edacd880e..87dddbfb439 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -443,10 +443,8 @@ void Item_window_func::print(String *str, enum_query_type query_type) { window_func()->print(str, query_type); str->append(" over "); -#ifndef DBUG_OFF - if (!window_spec) // one can call dbug_print_item() anytime in gdb + if (!window_spec) str->append(window_name); else -#endif - window_spec->print(str, query_type); + window_spec->print(str, query_type); } From b4c742108f8cd2d2ebe70a98d8c621a34a8b891a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 27 Jul 2020 14:34:24 +0300 Subject: [PATCH 14/30] Enable fixed test case. --- mysql-test/suite/galera/disabled.def | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 331260ef84e..453bbb139f5 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -14,7 +14,6 @@ MW-286 : MDEV-18464 Killing thread can cause mutex deadlock if done concurrently MW-329 : MDEV-19962 Galera test failure on MW-329 galera.galera_defaults : MDEV-21494 Galera test sporadic failure on galera.galera_defaults galera_as_slave_replication_bundle : MDEV-15785 OPTION_GTID_BEGIN is set in Gtid_log_event::do_apply_event() -galera_autoinc_sst_mariabackup : Known issue, may require porting MDEV-17458 from later versions galera_binlog_stmt_autoinc : MDEV-19959 Galera test failure on galera_binlog_stmt_autoinc galera_gcache_recover_manytrx : MDEV-18834 Galera test failure galera_load_data : MDEV-19968 galera.galera_load_data From a1f899a8abb6bb0b046db28d6da9dd4b7fc3c8c4 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 24 Jul 2020 16:52:42 +0530 Subject: [PATCH 15/30] MDEV-23233: Race condition for btr_search_drop_page_hash_index() in buf_page_create() commit ad6171b91cac33e70bb28fa6865488b2c65e858c (MDEV-22456) introduced code to buf_page_create() that would lazily drop adaptive hash index entries for an index that has been evicted from the data dictionary cache. Unfortunately, that call was missing adequate protection. While the btr_search_drop_page_hash_index(block) was executing, the block could be reused for something else. buf_page_create(): If btr_search_drop_page_hash_index() must be invoked, pin the block before releasing the buf_pool->page_hash lock, so that the block cannot be grabbed by other threads. --- storage/innobase/buf/buf0buf.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 2456b9aeb5f..ad53a11ea66 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -5584,15 +5584,30 @@ buf_page_create( && !buf_pool_watch_is_sentinel(buf_pool, &block->page)) { ut_d(block->page.file_page_was_freed = FALSE); +#ifdef BTR_CUR_HASH_ADAPT + bool drop_hash_entry = + (block->page.state == BUF_BLOCK_FILE_PAGE + && block->index); + + if (drop_hash_entry) { + mutex_enter(&block->mutex); + buf_page_set_sticky(&block->page); + mutex_exit(&block->mutex); + } +#endif /* Page can be found in buf_pool */ buf_pool_mutex_exit(buf_pool); rw_lock_x_unlock(hash_lock); buf_block_free(free_block); #ifdef BTR_CUR_HASH_ADAPT - if (block->page.state == BUF_BLOCK_FILE_PAGE - && UNIV_LIKELY_NULL(block->index)) { + if (drop_hash_entry) { btr_search_drop_page_hash_index(block); + buf_pool_mutex_enter(buf_pool); + mutex_enter(&block->mutex); + buf_page_unset_sticky(&block->page); + mutex_exit(&block->mutex); + buf_pool_mutex_exit(buf_pool); } #endif /* BTR_CUR_HASH_ADAPT */ From 186d9d0d7210a74d24a7d7c7651ab1bdf364dcca Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 22 Jun 2020 14:24:31 +1000 Subject: [PATCH 16/30] MDEV-12474: rocksdb: mtr - rocksdb.concurrent_alter use sh FreeBSD doesn't have bash installed by default and sh has sufficient job control for this test. $ mysql-test/mtr --mem --max-test-fail=30 --force --parallel=1 rocksdb.concurrent_alter Logging: /home/dan/mariadb-server-10.5/mysql-test/mysql-test-run.pl --mem --max-test-fail=30 --force --parallel=1 rocksdb.concurrent_alter vardir: /usr/home/dan/build-mariadb-server-10.5/mysql-test/var Checking leftover processes... Removing old var directory... Creating var directory '/usr/home/dan/build-mariadb-server-10.5/mysql-test/var'... - symlinking 'var' to '/tmp/var_auto_P81m' Checking supported features... MariaDB Version 10.5.4-MariaDB - SSL connections supported - binaries built with wsrep patch Collecting tests... Installing system database... ============================================================================== TEST RESULT TIME (ms) or COMMENT -------------------------------------------------------------------------- worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019 rocksdb.concurrent_alter 'write_committed' [ pass ] 16348 rocksdb.concurrent_alter 'write_prepared' [ pass ] 16771 -------------------------------------------------------------------------- The servers were restarted 1 times Spent 33.119 of 41 seconds executing testcases Completed: All 2 tests were successful. $ uname -a FreeBSD freebsd 12.1-RELEASE-p6 FreeBSD 12.1-RELEASE-p6 GENERIC amd64 --- storage/rocksdb/mysql-test/rocksdb/t/concurrent_alter.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/rocksdb/mysql-test/rocksdb/t/concurrent_alter.test b/storage/rocksdb/mysql-test/rocksdb/t/concurrent_alter.test index 3ebdd67a1a6..aee653830e2 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/concurrent_alter.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/concurrent_alter.test @@ -30,7 +30,7 @@ $MYSQL_SLAP --silent --delimiter=";" --query="select * from a1 where b=1" --conc wait EOF ---exec bash $MYSQL_TMP_DIR/concurrent_alter.sh +--exec sh $MYSQL_TMP_DIR/concurrent_alter.sh let $server_charset=`select @@character_set_server`; --replace_result $server_charset DEFAULT_CHARSET From d88ea260882ca414e940cd6af225617f00503f71 Mon Sep 17 00:00:00 2001 From: Krunal Bauskar Date: Mon, 27 Jul 2020 18:38:10 +0800 Subject: [PATCH 17/30] MDEV-23137: RocksDB: undefined reference to crc32c_arm64 RocksDB fails to build on arm64: undefined reference to `crc32c_arm64(unsigned int, unsigned char const*, unsigned int)' MariaDB uses storage/rocksdb/build_rocksdb.cmake to compile RocksDB. Said cmake missed adding crc32c_arm64 compilation target so if machine native architecture supported crc32 then complier would enable usage of function defined in crc32c_arm64 causing the listed error. Added crc32c_arm64 complition target. closes #1642 --- storage/rocksdb/build_rocksdb.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 3f3dca7e990..7d2252c5f77 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -442,6 +442,16 @@ else() util/crc32c_ppc.c util/crc32c_ppc_asm.S) endif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") + # aarch + if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") + CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crc+crypto" HAS_ARMV8_CRC) + if(HAS_ARMV8_CRC) + message(STATUS " HAS_ARMV8_CRC yes") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc+crypto -Wno-unused-function") + list(APPEND ROCKSDB_SOURCES + util/crc32c_arm64.cc) + endif(HAS_ARMV8_CRC) + endif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") endif() SET(SOURCES) FOREACH(s ${ROCKSDB_SOURCES}) From 715beee46abb4c29bffd6f9c5fd5ee95da55bf4f Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 2 Jul 2020 09:39:13 +1000 Subject: [PATCH 18/30] MDEV-23051: riscv64 fails build (atomics) riscv64 fails to build because the use of #include needs to link with -latomic. per https://github.com/riscv/riscv-gnu-toolchain/issues/183#issuecomment-253721765 --- storage/rocksdb/CMakeLists.txt | 7 +++++++ storage/rocksdb/build_rocksdb.cmake | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index cef5a8b2517..506dead7a6e 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -108,9 +108,15 @@ SET(ROCKSDB_SE_SOURCES # This is a strong requirement coming from RocksDB. No conditional checks here. #ADD_DEFINITIONS(-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX #) +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + SET(ATOMIC_EXTRA_LIBS -latomic) +else() + SET(ATOMIC_EXTRA_LIBS) +endif() MYSQL_ADD_PLUGIN(rocksdb ${ROCKSDB_SE_SOURCES} MODULE_ONLY STORAGE_ENGINE MODULE_OUTPUT_NAME ha_rocksdb + LINK_LIBRARIES ${ATOMIC_EXTRA_LIBS} COMPONENT rocksdb-engine) IF(NOT TARGET rocksdb) @@ -161,6 +167,7 @@ TARGET_LINK_LIBRARIES(rocksdb_aux_lib rocksdblib ${ZLIB_LIBRARY}) if (UNIX AND NOT APPLE) TARGET_LINK_LIBRARIES(rocksdb_aux_lib -lrt) endif() +TARGET_LINK_LIBRARIES(rocksdb_aux_lib ${ATOMIC_EXTRA_LIBS}) # IF (WITH_JEMALLOC) # FIND_LIBRARY(JEMALLOC_LIBRARY diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 7d2252c5f77..adad1314594 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -132,6 +132,10 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") ADD_DEFINITIONS(-DHAVE_POWER8 -DHAS_ALTIVEC) endif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set(SYSTEM_LIBS ${SYSTEM_LIBS} -latomic) +endif() + option(WITH_FALLOCATE "build with fallocate" ON) if(WITH_FALLOCATE AND UNIX) From cae4b3f8113f266b7b6636e222e9cd9df6080327 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 22 Jun 2020 14:39:15 +1000 Subject: [PATCH 19/30] rocksdb: FreeBSD disable jemalloc search FreeBSD's inbuilt default jemalloc means its pointless to do a package search on it. The paths are already set by the system defaults. --- storage/rocksdb/build_rocksdb.cmake | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index adad1314594..6911b636996 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -18,17 +18,16 @@ if(WIN32) # include(${ROCKSDB_SOURCE_DIR}/thirdparty.inc) else() option(WITH_ROCKSDB_JEMALLOC "build RocksDB with JeMalloc" OFF) - if(WITH_ROCKSDB_JEMALLOC) - find_package(JeMalloc REQUIRED) - add_definitions(-DROCKSDB_JEMALLOC) - ADD_DEFINITIONS(-DROCKSDB_MALLOC_USABLE_SIZE) - include_directories(${JEMALLOC_INCLUDE_DIR}) - endif() if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD has jemaloc as default malloc add_definitions(-DROCKSDB_JEMALLOC) ADD_DEFINITIONS(-DROCKSDB_MALLOC_USABLE_SIZE) set(WITH_JEMALLOC ON) + elseif(WITH_ROCKSDB_JEMALLOC) + find_package(JeMalloc REQUIRED) + add_definitions(-DROCKSDB_JEMALLOC) + ADD_DEFINITIONS(-DROCKSDB_MALLOC_USABLE_SIZE) + include_directories(${JEMALLOC_INCLUDE_DIR}) endif() endif() From 459b87f6b4ae9633f831e245e6a345bbab55cf27 Mon Sep 17 00:00:00 2001 From: Dan Solodko Date: Thu, 18 Jun 2020 11:02:19 +0300 Subject: [PATCH 20/30] MDEV-9911: NTILE must return an error when parameter is not stable --- mysql-test/r/win_ntile.result | 78 +++++++++++++++++++++++++++++++++++ mysql-test/t/win_ntile.test | 43 +++++++++++++++++++ sql/item_windowfunc.h | 11 +++-- 3 files changed, 129 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/win_ntile.result b/mysql-test/r/win_ntile.result index 41cb1a594bf..4d02a230e13 100644 --- a/mysql-test/r/win_ntile.result +++ b/mysql-test/r/win_ntile.result @@ -433,3 +433,81 @@ ntile((select a from t1)) over (partition by b order by pk) from t1; ERROR 21000: Subquery returns more than 1 row drop table t1; +# +# MDEV-9911 NTILE must return an error when parameter is not stable +# +create table t1 ( +pk int primary key, +c1 nvarchar(10), +c2 nvarchar(10), +c3 int +); +insert into t1 values +(1, 'Mark', 'Male', 5), +(2, 'John', 'Male', 5), +(3, 'Pam', 'Female', 6), +(4, 'Sara', 'Female', 6), +(5, 'Todd', 'Male', 5), +(6, 'Mary', 'Female', 6), +(7, 'Ben', 'Male', 5), +(8, 'Jodi', 'Female', 6), +(9, 'Tom', 'Male', 5), +(10, 'Lucky', 'Male', 5), +(11, 'Mark', 'Male', 5), +(12, 'John', 'Male', 5), +(13, 'Pam', 'Female', 6), +(14, 'Sara', 'Female', 6), +(15, 'Todd', 'Male', 5), +(16, 'Mary', 'Female', 6), +(17, 'Ben', 'Male', 5), +(18, 'Jodi', 'Female', 6), +(19, 'Tom', 'Male', 5), +(20, 'Lucky', 'Male', 5); +select c1, c2, c3, ntile(6) over (partition by c2 order by pk) from t1; +c1 c2 c3 ntile(6) over (partition by c2 order by pk) +Pam Female 6 1 +Sara Female 6 1 +Mary Female 6 2 +Jodi Female 6 2 +Pam Female 6 3 +Sara Female 6 4 +Mary Female 6 5 +Jodi Female 6 6 +Mark Male 5 1 +John Male 5 1 +Todd Male 5 2 +Ben Male 5 2 +Tom Male 5 3 +Lucky Male 5 3 +Mark Male 5 4 +John Male 5 4 +Todd Male 5 5 +Ben Male 5 5 +Tom Male 5 6 +Lucky Male 5 6 +select c1, c2, c3, ntile(c3) over (partition by c2 order by pk) from t1; +c1 c2 c3 ntile(c3) over (partition by c2 order by pk) +Pam Female 6 1 +Sara Female 6 1 +Mary Female 6 2 +Jodi Female 6 2 +Pam Female 6 3 +Sara Female 6 4 +Mary Female 6 5 +Jodi Female 6 6 +Mark Male 5 1 +John Male 5 1 +Todd Male 5 1 +Ben Male 5 2 +Tom Male 5 2 +Lucky Male 5 2 +Mark Male 5 3 +John Male 5 3 +Todd Male 5 4 +Ben Male 5 4 +Tom Male 5 5 +Lucky Male 5 5 +update t1 set c3= 1 where pk = 1; +select c1, c2, c3, ntile(c3) over (partition by c2 order by pk) from t1; +ERROR HY000: Argument of NTILE must be greater than 0 +drop table t1; diff --git a/mysql-test/t/win_ntile.test b/mysql-test/t/win_ntile.test index 6f12e1f4005..c65ba7e1521 100644 --- a/mysql-test/t/win_ntile.test +++ b/mysql-test/t/win_ntile.test @@ -168,4 +168,47 @@ select pk, a, b, from t1; +drop table t1; + +--echo # +--echo # MDEV-9911 NTILE must return an error when parameter is not stable +--echo # + +create table t1 ( + pk int primary key, + c1 nvarchar(10), + c2 nvarchar(10), + c3 int +); + +insert into t1 values + (1, 'Mark', 'Male', 5), + (2, 'John', 'Male', 5), + (3, 'Pam', 'Female', 6), + (4, 'Sara', 'Female', 6), + (5, 'Todd', 'Male', 5), + (6, 'Mary', 'Female', 6), + (7, 'Ben', 'Male', 5), + (8, 'Jodi', 'Female', 6), + (9, 'Tom', 'Male', 5), + (10, 'Lucky', 'Male', 5), + (11, 'Mark', 'Male', 5), + (12, 'John', 'Male', 5), + (13, 'Pam', 'Female', 6), + (14, 'Sara', 'Female', 6), + (15, 'Todd', 'Male', 5), + (16, 'Mary', 'Female', 6), + (17, 'Ben', 'Male', 5), + (18, 'Jodi', 'Female', 6), + (19, 'Tom', 'Male', 5), + (20, 'Lucky', 'Male', 5); +# Correct usage of NTILE with a fix argument NTILE(6). +select c1, c2, c3, ntile(6) over (partition by c2 order by pk) from t1; +# Correct usage - constant NTILE (argument) in each partition. +select c1, c2, c3, ntile(c3) over (partition by c2 order by pk) from t1; + +update t1 set c3= 1 where pk = 1; +--error ER_INVALID_NTILE_ARGUMENT +select c1, c2, c3, ntile(c3) over (partition by c2 order by pk) from t1; + drop table t1; diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 85957949053..36b0d087f12 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -618,7 +618,8 @@ class Item_sum_ntile : public Item_sum_window_with_row_count public: Item_sum_ntile(THD* thd, Item* num_quantiles_expr) : Item_sum_window_with_row_count(thd, num_quantiles_expr), - current_row_count_(0) {}; + current_row_count_(0), + n_old_val_(0) {}; double val_real() { @@ -635,11 +636,13 @@ class Item_sum_ntile : public Item_sum_window_with_row_count longlong num_quantiles= get_num_quantiles(); - if (num_quantiles <= 0) { + if (num_quantiles <= 0 || + (static_cast(num_quantiles) != n_old_val_ && n_old_val_ > 0)) + { my_error(ER_INVALID_NTILE_ARGUMENT, MYF(0)); return true; } - + n_old_val_= static_cast(num_quantiles); null_value= false; ulonglong quantile_size = get_row_count() / num_quantiles; ulonglong extra_rows = get_row_count() - quantile_size * num_quantiles; @@ -665,6 +668,7 @@ class Item_sum_ntile : public Item_sum_window_with_row_count { current_row_count_= 0; set_row_count(0); + n_old_val_= 0; } const char*func_name() const @@ -683,6 +687,7 @@ class Item_sum_ntile : public Item_sum_window_with_row_count private: longlong get_num_quantiles() { return args[0]->val_int(); } ulong current_row_count_; + ulonglong n_old_val_; }; From 940668f5cb2ebe411d795927e05038f3d9936aea Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 28 Jul 2020 19:53:19 +1000 Subject: [PATCH 21/30] MDEV-23137: aarch64, postfix - cmake include --- storage/rocksdb/build_rocksdb.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 6911b636996..883ee15f74c 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -447,6 +447,7 @@ else() endif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") # aarch if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") + INCLUDE(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crc+crypto" HAS_ARMV8_CRC) if(HAS_ARMV8_CRC) message(STATUS " HAS_ARMV8_CRC yes") From 6307b17aa11fb6179ed04f16abfa7ed9d5228e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 28 Jul 2020 11:17:20 +0300 Subject: [PATCH 22/30] MDEV-20142 encryption.innodb_encrypt_temporary_tables failed in buildbot with wrong result Let us read both encrypted temporary tables to increase the changes of page flushing and eviction. --- .../suite/encryption/r/innodb_encrypt_temporary_tables.result | 3 +++ .../suite/encryption/t/innodb_encrypt_temporary_tables.test | 2 ++ 2 files changed, 5 insertions(+) diff --git a/mysql-test/suite/encryption/r/innodb_encrypt_temporary_tables.result b/mysql-test/suite/encryption/r/innodb_encrypt_temporary_tables.result index 9a291ae1354..541680ae862 100644 --- a/mysql-test/suite/encryption/r/innodb_encrypt_temporary_tables.result +++ b/mysql-test/suite/encryption/r/innodb_encrypt_temporary_tables.result @@ -9,6 +9,9 @@ INSERT INTO t2 (f1,f2,f3) SELECT '', '', '' FROM seq_1_to_8192; SELECT COUNT(*) FROM t1; COUNT(*) 8192 +SELECT COUNT(*) FROM t2; +COUNT(*) +8192 SELECT variable_value > @old_encrypted FROM information_schema.global_status WHERE variable_name = 'innodb_encryption_n_temp_blocks_encrypted'; variable_value > @old_encrypted diff --git a/mysql-test/suite/encryption/t/innodb_encrypt_temporary_tables.test b/mysql-test/suite/encryption/t/innodb_encrypt_temporary_tables.test index 6c16afa28f4..c1a6ad38456 100644 --- a/mysql-test/suite/encryption/t/innodb_encrypt_temporary_tables.test +++ b/mysql-test/suite/encryption/t/innodb_encrypt_temporary_tables.test @@ -15,6 +15,8 @@ CREATE TEMPORARY TABLE t2(f1 CHAR(100), f2 CHAR(200), f3 CHAR(200))ENGINE=InnoDB INSERT INTO t2 (f1,f2,f3) SELECT '', '', '' FROM seq_1_to_8192; SELECT COUNT(*) FROM t1; +SELECT COUNT(*) FROM t2; + SELECT variable_value > @old_encrypted FROM information_schema.global_status WHERE variable_name = 'innodb_encryption_n_temp_blocks_encrypted'; From 3c3f172f17de217389bc51053c555a5d7e91ddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 28 Jul 2020 11:24:07 +0300 Subject: [PATCH 23/30] MDEV-23308 CHECK TABLE attempts to access parent_right_page_no=FIL_NULL mysql/mysql-server@e00ad49edc8b07317b52c9efd0810f2cbc57877a which introduced WL#6326 to MySQL 5.7.2 added a buffer page acquisition to CHECK TABLE code (solely for the purpose of obeying the changed latching order), but failed to check that a parent page actually exists. It would not necessarily exist in a corrupted index where a parent page is missing pointer records to child pages. --- storage/innobase/btr/btr0btr.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 5f38e623985..313790f1db3 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -5028,11 +5028,13 @@ loop: mtr_release_block_at_savepoint( &mtr, savepoint, right_block); - btr_block_get( - page_id_t(index->space, - parent_right_page_no), - table_page_size, - RW_SX_LATCH, index, &mtr); + if (parent_right_page_no != FIL_NULL) { + btr_block_get( + page_id_t(index->space, + parent_right_page_no), + table_page_size, + RW_SX_LATCH, index, &mtr); + } right_block = btr_block_get( page_id_t(index->space, From 8ec877f40a0e8e7432f1ef2cbd1d744c793eab2d Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 29 Jul 2020 08:17:57 +0300 Subject: [PATCH 24/30] speed up my_timer_init() I run perf top during ./mtr testing and constantly see times() function there. It's so slow, that it has no sense to run it in a loop too many times. This patch speeds up -suite=innodb for me from 218s to 208s. 9s of times() function! --- mysys/my_rdtsc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c index afb97553dd7..b020e224a59 100644 --- a/mysys/my_rdtsc.c +++ b/mysys/my_rdtsc.c @@ -812,7 +812,11 @@ void my_timer_init(MY_TIMER_INFO *mti) time1= my_timer_cycles(); time2= my_timer_ticks(); time3= time2; /* Avoids a Microsoft/IBM compiler warning */ +#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES) + for (i= 0; i < 1000; ++i) +#else for (i= 0; i < MY_TIMER_ITERATIONS * 1000; ++i) +#endif { time3= my_timer_ticks(); if (time3 - time2 > 10) break; From 2107e3bb9c0d2e039c371a36fe7b3d7dcb2b6c5f Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 28 Jul 2020 10:39:05 +0200 Subject: [PATCH 25/30] MDEV-21258: Can't uninstall plugin if the library file doesn't exist Removing plugin from the mysql.plugin even if the plugin is not loaded --- mysql-test/r/plugin.result | 13 ++++++ .../suite/plugins/r/audit_null_debug.result | 1 + .../suite/plugins/t/audit_null_debug.test | 3 +- mysql-test/t/plugin.test | 20 +++++++++ sql/sql_plugin.cc | 45 +++++++++++-------- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result index 93a150ae424..04931001901 100644 --- a/mysql-test/r/plugin.result +++ b/mysql-test/r/plugin.result @@ -341,3 +341,16 @@ RENAME TABLE t1 TO t2; ERROR 42S02: Table 'test.t1' doesn't exist DROP TABLE t1; # End of 10.1 test +# +# MDEV-21258: Can't uninstall plugin if the library file doesn't exist +# +insert into mysql.plugin values ("unexisting_plugin", "soname"); +select * from mysql.plugin WHERE name='unexisting_plugin'; +name dl +unexisting_plugin soname +UNINSTALL PLUGIN unexisting_plugin; +select * from mysql.plugin WHERE name='unexisting_plugin'; +name dl +UNINSTALL PLUGIN unexisting_plugin; +ERROR 42000: PLUGIN unexisting_plugin does not exist +# End of 10.2 tests diff --git a/mysql-test/suite/plugins/r/audit_null_debug.result b/mysql-test/suite/plugins/r/audit_null_debug.result index 9d5c7c4a02c..e70de36a2ec 100644 --- a/mysql-test/suite/plugins/r/audit_null_debug.result +++ b/mysql-test/suite/plugins/r/audit_null_debug.result @@ -11,5 +11,6 @@ uninstall plugin audit_null; ERROR HY000: Index for table './mysql/plugin.MYI' is corrupt; try to repair it SET debug_dbug=@old_dbug; uninstall plugin audit_null; +uninstall plugin audit_null; ERROR 42000: PLUGIN audit_null does not exist delete from mysql.plugin where name='audit_null'; diff --git a/mysql-test/suite/plugins/t/audit_null_debug.test b/mysql-test/suite/plugins/t/audit_null_debug.test index 0534108b107..f3c88d24c0c 100644 --- a/mysql-test/suite/plugins/t/audit_null_debug.test +++ b/mysql-test/suite/plugins/t/audit_null_debug.test @@ -26,7 +26,8 @@ SET debug_dbug='+d,myisam_pretend_crashed_table_on_usage'; uninstall plugin audit_null; SET debug_dbug=@old_dbug; ---error 1305 +uninstall plugin audit_null; +--error ER_SP_DOES_NOT_EXIST uninstall plugin audit_null; delete from mysql.plugin where name='audit_null'; diff --git a/mysql-test/t/plugin.test b/mysql-test/t/plugin.test index e1a17d49174..d2e828b2589 100644 --- a/mysql-test/t/plugin.test +++ b/mysql-test/t/plugin.test @@ -276,3 +276,23 @@ RENAME TABLE t1 TO t2; DROP TABLE t1; --echo # End of 10.1 test + +--echo # +--echo # MDEV-21258: Can't uninstall plugin if the library file doesn't exist +--echo # + +insert into mysql.plugin values ("unexisting_plugin", "soname"); + +# check that we have the plugin installed +select * from mysql.plugin WHERE name='unexisting_plugin'; + +# make attempt to uninstall the plugin +UNINSTALL PLUGIN unexisting_plugin; + +# check that we have the plugin uninstalled +select * from mysql.plugin WHERE name='unexisting_plugin'; + +--error ER_SP_DOES_NOT_EXIST +UNINSTALL PLUGIN unexisting_plugin; + +--echo # End of 10.2 tests diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 42d2d110f2b..968ec6ac7d4 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -2216,26 +2216,30 @@ static bool do_uninstall(THD *thd, TABLE *table, const LEX_STRING *name) if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)) || plugin->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_DYING)) { - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); - return 1; - } - if (!plugin->plugin_dl) - { - my_error(ER_PLUGIN_DELETE_BUILTIN, MYF(0)); - return 1; - } - if (plugin->load_option == PLUGIN_FORCE_PLUS_PERMANENT) - { - my_error(ER_PLUGIN_IS_PERMANENT, MYF(0), name->str); - return 1; + // maybe plugin is in mysql.plugin present so postpond the error + plugin= NULL; } - plugin->state= PLUGIN_IS_DELETED; - if (plugin->ref_count) - push_warning(thd, Sql_condition::WARN_LEVEL_WARN, - WARN_PLUGIN_BUSY, ER_THD(thd, WARN_PLUGIN_BUSY)); - else - reap_needed= true; + if (plugin) + { + if (!plugin->plugin_dl) + { + my_error(ER_PLUGIN_DELETE_BUILTIN, MYF(0)); + return 1; + } + if (plugin->load_option == PLUGIN_FORCE_PLUS_PERMANENT) + { + my_error(ER_PLUGIN_IS_PERMANENT, MYF(0), name->str); + return 1; + } + + plugin->state= PLUGIN_IS_DELETED; + if (plugin->ref_count) + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, + WARN_PLUGIN_BUSY, ER_THD(thd, WARN_PLUGIN_BUSY)); + else + reap_needed= true; + } uchar user_key[MAX_KEY_LENGTH]; table->use_all_columns(); @@ -2260,6 +2264,11 @@ static bool do_uninstall(THD *thd, TABLE *table, const LEX_STRING *name) return 1; } } + else if (!plugin) + { + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); + return 1; + } return 0; } From c5d4dd253348655a663d37985a3e61b20d17ed20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 30 Jul 2020 09:24:36 +0300 Subject: [PATCH 26/30] MDEV-23339 innodb_force_recovery=2 may still abort the rollback of recovered transactions trx_rollback_active(), trx_rollback_resurrected(): Replace an incorrect condition that we failed to replace in commit b68f1d847f1fc00eed795e20162effc8fbc4119b (MDEV-21217). --- mysql-test/suite/innodb/disabled.def | 1 - .../suite/innodb/r/innodb_force_recovery_rollback.result | 2 +- mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test | 3 ++- storage/innobase/trx/trx0roll.cc | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/innodb/disabled.def b/mysql-test/suite/innodb/disabled.def index 4484417afce..35c941f8af7 100644 --- a/mysql-test/suite/innodb/disabled.def +++ b/mysql-test/suite/innodb/disabled.def @@ -11,4 +11,3 @@ ############################################################################## create-index-debug : MDEV-13680 InnoDB may crash when btr_page_alloc() fails -innodb_force_recovery_rollback : MDEV-22889 InnoDB occasionally breaks ACID diff --git a/mysql-test/suite/innodb/r/innodb_force_recovery_rollback.result b/mysql-test/suite/innodb/r/innodb_force_recovery_rollback.result index dc037fd6c97..42cf8adfc13 100644 --- a/mysql-test/suite/innodb/r/innodb_force_recovery_rollback.result +++ b/mysql-test/suite/innodb/r/innodb_force_recovery_rollback.result @@ -12,6 +12,6 @@ SET GLOBAL innodb_flush_log_at_trx_commit=1; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; disconnect con0; connection default; -SELECT * FROM t0 LOCK IN SHARE MODE; +SELECT * FROM t0 LIMIT 0 LOCK IN SHARE MODE; a DROP TABLE t0,t1; diff --git a/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test b/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test index ad234eba72e..f1d14c45aaf 100644 --- a/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test +++ b/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test @@ -30,5 +30,6 @@ CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; disconnect con0; connection default; # If the rollback was aborted, we would end up in a lock wait here. -SELECT * FROM t0 LOCK IN SHARE MODE; +# The LIMIT 0 works around MDEV-22889 InnoDB occasionally breaks ACID +SELECT * FROM t0 LIMIT 0 LOCK IN SHARE MODE; DROP TABLE t0,t1; diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index de749f993e7..ef3d93cd65e 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -611,7 +611,7 @@ trx_rollback_active( if (trx->error_state != DB_SUCCESS) { ut_ad(trx->error_state == DB_INTERRUPTED); - ut_ad(!srv_is_being_started); + ut_ad(srv_shutdown_state != SRV_SHUTDOWN_NONE); ut_ad(!srv_undo_sources); ut_ad(srv_fast_shutdown); ut_ad(!dictionary_locked); @@ -701,7 +701,7 @@ func_exit: trx_free_resurrected(trx); return(TRUE); case TRX_STATE_ACTIVE: - if (!srv_is_being_started + if (srv_shutdown_state != SRV_SHUTDOWN_NONE && !srv_undo_sources && srv_fast_shutdown) { fake_prepared: trx->state = TRX_STATE_PREPARED; From 8a612314d0c9bc5b1db6f3998f26c28967915949 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 30 Jul 2020 13:38:43 +0530 Subject: [PATCH 27/30] MDEV-23332 Index online status assert failure in btr_search_drop_page_hash_index Problem: ======== In row_merge_drop_indexes(), InnoDB drops only the index from dictionary and frees the index pages but it maintains the index object if the table is being used by other DML threads. It sets the online status of the index to ONLINE_INDEX_ABORTED_DROPPED. Removing the index from dictionary doesn't remove the corressponding ahi entries of the index. When block is being reused, InnoDB tries to remove ahi entries for the block and it fails if index online status is ONLINE_INDEX_ABORTED_DROPPED. Fix: ==== MDEV-22456 allows the index ahi entries to be dropped lazily. so checking online status in btr_search_drop_page_hash_index() is meaningless and should be removed. --- storage/innobase/btr/btr0sea.cc | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 491a3e375d3..ea34b4034e4 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -1160,26 +1160,6 @@ retry: || block->page.id.space() == index->space); ut_a(index_id == index->id); ut_ad(!dict_index_is_ibuf(index)); -#ifdef UNIV_DEBUG - switch (dict_index_get_online_status(index)) { - case ONLINE_INDEX_CREATION: - /* The index is being created (bulk loaded). */ - case ONLINE_INDEX_COMPLETE: - /* The index has been published. */ - case ONLINE_INDEX_ABORTED: - /* Either the index creation was aborted due to an - error observed by InnoDB (in which case there should - not be any adaptive hash index entries), or it was - completed and then flagged aborted in - rollback_inplace_alter_table(). */ - break; - case ONLINE_INDEX_ABORTED_DROPPED: - /* The index should have been dropped from the tablespace - already, and the adaptive hash index entries should have - been dropped as well. */ - ut_error; - } -#endif /* UNIV_DEBUG */ n_fields = block->curr_n_fields; n_bytes = block->curr_n_bytes; From 91ebf1844f4fbc36edb66023332a045895d07cf5 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Tue, 28 Jul 2020 23:45:51 +1000 Subject: [PATCH 28/30] MDEV-19338 InnoDB: Failing assertion: !cursor->index->is_committed() Call mark_columns_per_binlog_row_image before find_row() to set up table->vcol_set early, so the virtual column value will be updated after record read (ha_rnd_pos/ha_index_next/etc) by table->update_virtual_fields() call --- mysql-test/suite/rpl/r/rpl_row_virt.result | 20 ++++++++++++++++ mysql-test/suite/rpl/t/rpl_row_virt.test | 27 ++++++++++++++++++++++ sql/log_event.cc | 14 +++++------ 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_row_virt.result create mode 100644 mysql-test/suite/rpl/t/rpl_row_virt.test diff --git a/mysql-test/suite/rpl/r/rpl_row_virt.result b/mysql-test/suite/rpl/r/rpl_row_virt.result new file mode 100644 index 00000000000..b670c63d9f1 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_row_virt.result @@ -0,0 +1,20 @@ +include/master-slave.inc +[connection master] +connection master; +create table t1 ( +id int auto_increment, +data varchar(32), +virt tinyint as (1), +primary key (id), +key virt (virt) +) engine=innodb default charset=utf8mb4; +insert into t1 (data) values ('broken'); +update t1 set data='more broken'; +connection slave; +select * from t1; +id data virt +1 more broken 1 +connection master; +drop table t1; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_row_virt.test b/mysql-test/suite/rpl/t/rpl_row_virt.test new file mode 100644 index 00000000000..e79869cd8e4 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_row_virt.test @@ -0,0 +1,27 @@ +--source include/have_binlog_format_row.inc +--source include/master-slave.inc +--source include/have_innodb.inc +connection master; + +create table t1 ( + id int auto_increment, + data varchar(32), + virt tinyint as (1), + primary key (id), + key virt (virt) +) engine=innodb default charset=utf8mb4; + +insert into t1 (data) values ('broken'); + +update t1 set data='more broken'; + +--sync_slave_with_master + +select * from t1; + +--connection master +drop table t1; + +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/sql/log_event.cc b/sql/log_event.cc index f9e4365ff94..1c59cca8e83 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -13614,7 +13614,6 @@ end: if (is_table_scan || is_index_scan) issue_long_find_row_warning(get_general_type_code(), m_table->alias.c_ptr(), is_index_scan, rgi); - table->default_column_bitmaps(); DBUG_RETURN(error); } @@ -13928,6 +13927,12 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) #endif /* WSREP_PROC_INFO */ thd_proc_info(thd, message); + // Temporary fix to find out why it fails [/Matz] + memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8); + memcpy(m_table->write_set->bitmap, m_cols_ai.bitmap, (m_table->write_set->n_bits + 7) / 8); + + m_table->mark_columns_per_binlog_row_image(); + int error= find_row(rgi); if (error) { @@ -13997,12 +14002,7 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) error= HA_ERR_GENERIC; // in case if error is not set yet goto err; } - - // Temporary fix to find out why it fails [/Matz] - memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8); - memcpy(m_table->write_set->bitmap, m_cols_ai.bitmap, (m_table->write_set->n_bits + 7) / 8); - - m_table->mark_columns_per_binlog_row_image(); + error= m_table->file->ha_update_row(m_table->record[1], m_table->record[0]); if (error == HA_ERR_RECORD_IS_THE_SAME) error= 0; From fd0abc890f99e2b5ca1b8ae4cb0dc3968eef1208 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 29 Jul 2020 01:01:24 +1000 Subject: [PATCH 29/30] MDEV-18042 Server crashes upon adding a non-null date column under NO_ZERO_DATE with ALGORITHM=INPLACE accept table_name and db_name instead of table_share in make_truncated_value_warning --- mysql-test/suite/innodb/r/innodb-alter.result | 17 ++++++++++++++ mysql-test/suite/innodb/t/innodb-alter.test | 22 +++++++++++++++++++ sql/field.cc | 2 +- sql/item.cc | 2 +- sql/item_create.cc | 2 +- sql/item_timefunc.cc | 8 +++---- sql/sql_table.cc | 3 ++- sql/sql_time.cc | 21 +++++++++--------- sql/sql_time.h | 9 +++++--- 9 files changed, 64 insertions(+), 22 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-alter.result b/mysql-test/suite/innodb/r/innodb-alter.result index a5361f720ce..80cf14c1725 100644 --- a/mysql-test/suite/innodb/r/innodb-alter.result +++ b/mysql-test/suite/innodb/r/innodb-alter.result @@ -1055,3 +1055,20 @@ SELECT * FROM t1; a b 10 10:20:30 DROP TABLE t1; +# +# MDEV-18042 Server crashes in mysql_alter_table upon adding a non-null +# date column under NO_ZERO_DATE with ALGORITHM=INPLACE +# +SET @OLD_SQL_MODE= @@SQL_MODE; +SET @@SQL_MODE= 'NO_ZERO_DATE'; +CREATE OR REPLACE TABLE t1 (i INT) ENGINE=MyISAM; +ALTER TABLE t1 ADD COLUMN d DATE NOT NULL, ALGORITHM=INPLACE; +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY +CREATE OR REPLACE TABLE t1 (i INT) ENGINE=InnoDB; +ALTER TABLE t1 ADD d DATETIME NOT NULL CHECK (f <= 0), ALGORITHM=COPY; +ERROR 42S22: Unknown column 'f' in 'CHECK' +CREATE OR REPLACE TABLE t1 (a int) ENGINE=InnoDB; +ALTER TABLE t1 ADD COLUMN b DATETIME NOT NULL, LOCK=NONE; +# Cleanup +SET @@SQL_MODE= @OLD_SQL_MODE; +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb-alter.test b/mysql-test/suite/innodb/t/innodb-alter.test index 9bfc1262a1b..aae3f3960a2 100644 --- a/mysql-test/suite/innodb/t/innodb-alter.test +++ b/mysql-test/suite/innodb/t/innodb-alter.test @@ -646,6 +646,28 @@ ALTER TABLE t1 ADD b TIME NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001- SELECT * FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-18042 Server crashes in mysql_alter_table upon adding a non-null +--echo # date column under NO_ZERO_DATE with ALGORITHM=INPLACE +--echo # + +SET @OLD_SQL_MODE= @@SQL_MODE; +SET @@SQL_MODE= 'NO_ZERO_DATE'; +CREATE OR REPLACE TABLE t1 (i INT) ENGINE=MyISAM; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER TABLE t1 ADD COLUMN d DATE NOT NULL, ALGORITHM=INPLACE; + +CREATE OR REPLACE TABLE t1 (i INT) ENGINE=InnoDB; +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 ADD d DATETIME NOT NULL CHECK (f <= 0), ALGORITHM=COPY; + +CREATE OR REPLACE TABLE t1 (a int) ENGINE=InnoDB; +ALTER TABLE t1 ADD COLUMN b DATETIME NOT NULL, LOCK=NONE; + +--echo # Cleanup +SET @@SQL_MODE= @OLD_SQL_MODE; +DROP TABLE t1; + # # End of 10.2 tests # diff --git a/sql/field.cc b/sql/field.cc index 65bd9d22857..9a1779dea5f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11059,7 +11059,7 @@ void Field::set_datetime_warning(Sql_condition::enum_warning_level level, THD *thd= get_thd(); if (thd->really_abort_on_warning() && level >= Sql_condition::WARN_LEVEL_WARN) make_truncated_value_warning(thd, level, str, ts_type, - table->s, field_name); + table->s->db.str, table->s->table_name.str, field_name); else set_warning(level, code, cuted_increment); } diff --git a/sql/item.cc b/sql/item.cc index 644bef7524a..2915b0cfb4d 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3669,7 +3669,7 @@ void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type, { ErrConvTime str(&value.time); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, time_type, 0, 0); + &str, time_type, NULL, NULL, NULL); set_zero_time(&value.time, time_type); } maybe_null= 0; diff --git a/sql/item_create.cc b/sql/item_create.cc index 4b7400eb0c0..1cf5a06a3a4 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -7338,7 +7338,7 @@ Item *create_temporal_literal(THD *thd, ErrConvString err(str, length, cs); make_truncated_value_warning(thd, Sql_condition::time_warn_level(status.warnings), - &err, ltime.time_type, 0, 0); + &err, ltime.time_type, NULL, NULL, NULL); } return item; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index b7455f36d1b..f2f3fdaafe3 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -430,7 +430,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, val_begin, length, - cached_timestamp_type, 0, NullS); + cached_timestamp_type, NULL, NULL, NULL); break; } } while (++val != val_end); @@ -1870,13 +1870,13 @@ overflow: { ErrConvInteger err2(sec, unsigned_flag); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &err2, MYSQL_TIMESTAMP_TIME, 0, NullS); + &err2, MYSQL_TIMESTAMP_TIME, NULL, NULL, NULL); } else { ErrConvString err2(err); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &err2, MYSQL_TIMESTAMP_TIME, 0, NullS); + &err2, MYSQL_TIMESTAMP_TIME, NULL, NULL, NULL); } return 0; } @@ -2894,7 +2894,7 @@ bool Item_func_maketime::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) int len = (int)(ptr - buf) + sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, buf, len, MYSQL_TIMESTAMP_TIME, - 0, NullS); + NULL, NULL, NULL); } return (null_value= 0); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b3a600eec36..57284272316 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9952,7 +9952,8 @@ err_new_table_cleanup: thd->abort_on_warning= true; make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, f_val, strlength(f_val), t_type, - new_table->s, + alter_ctx.new_db, + alter_ctx.new_name, alter_ctx.datetime_field->field_name); thd->abort_on_warning= save_abort_on_warning; } diff --git a/sql/sql_time.cc b/sql/sql_time.cc index a6fe937df4b..7f5919007e8 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -18,7 +18,6 @@ /* Functions to handle date and time */ #include -#include "sql_priv.h" #include "sql_time.h" #include "tztime.h" // struct Time_zone #include "sql_class.h" // THD @@ -223,7 +222,7 @@ check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, { ErrConvTime str(ltime); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, ts_type, 0, 0); + &str, ts_type, NULL, NULL, NULL); return true; } return false; @@ -240,7 +239,7 @@ adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec) return true; if (warnings) make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, MYSQL_TIMESTAMP_TIME, 0, NullS); + &str, MYSQL_TIMESTAMP_TIME, NULL, NULL, NULL); return false; } @@ -329,7 +328,8 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, ret_val ? Sql_condition::WARN_LEVEL_WARN : Sql_condition::time_warn_level(status.warnings), str, length, flags & TIME_TIME_ONLY ? - MYSQL_TIMESTAMP_TIME : l_time->time_type, 0, NullS); + MYSQL_TIMESTAMP_TIME : l_time->time_type, + NULL, NULL, NULL); DBUG_EXECUTE_IF("str_to_datetime_warn", push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_YES, str);); @@ -387,7 +387,8 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part, Sql_condition::WARN_LEVEL_WARN, str, res < 0 ? MYSQL_TIMESTAMP_ERROR : mysql_type_to_time_type(f_type), - s, field_name); + s ? s->db.str : NULL, + s ? s->table_name.str : NULL, field_name); } return res < 0; } @@ -859,7 +860,8 @@ void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const ErrConv *sval, timestamp_type time_type, - const TABLE_SHARE *s, const char *field_name) + const char *db_name, const char *table_name, + const char *field_name) { char warn_buff[MYSQL_ERRMSG_SIZE]; const char *type_str; @@ -879,9 +881,6 @@ void make_truncated_value_warning(THD *thd, } if (field_name) { - const char *db_name= s->db.str; - const char *table_name= s->table_name.str; - if (!db_name) db_name= ""; if (!table_name) @@ -1219,7 +1218,7 @@ make_date_with_warn(MYSQL_TIME *ltime, ulonglong fuzzy_date, /* e.g. negative time */ ErrConvTime str(ltime); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, ts_type, 0, 0); + &str, ts_type, NULL, NULL, NULL); return true; } if ((ltime->time_type= ts_type) == MYSQL_TIMESTAMP_DATE) @@ -1383,7 +1382,7 @@ time_to_datetime_with_warn(THD *thd, { ErrConvTime str(from); make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, - &str, MYSQL_TIMESTAMP_DATETIME, 0, 0); + &str, MYSQL_TIMESTAMP_DATETIME, NULL, NULL, NULL); return true; } return false; diff --git a/sql/sql_time.h b/sql/sql_time.h index 1dafb9b783b..ebfb86cde61 100644 --- a/sql/sql_time.h +++ b/sql/sql_time.h @@ -120,15 +120,18 @@ void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const ErrConv *str_val, timestamp_type time_type, - const TABLE_SHARE *s, const char *field_name); + const char *db_name, const char *table_name, + const char *field_name); static inline void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const char *str_val, uint str_length, timestamp_type time_type, - const TABLE_SHARE *s, const char *field_name) + const char *db_name, const char *table_name, + const char *field_name) { const ErrConvString str(str_val, str_length, &my_charset_bin); - make_truncated_value_warning(thd, level, &str, time_type, s, field_name); + make_truncated_value_warning(thd, level, &str, time_type, db_name, table_name, + field_name); } extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type, From f35d1721039f8f115fc55e8f4b4d2bb4012161d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 31 Jul 2020 11:38:23 +0300 Subject: [PATCH 30/30] MDEV-23198 Crash in REPLACE row_vers_impl_x_locked_low(): clust_offsets may point to memory that is allocated by mem_heap_alloc() and may have been freed. For initializing clust_offsets, try to use the stack-allocated buffer instead of a pointer that may point to freed memory. This fixes a regression that was introduced in commit f0aa073f2bf3d8d85b3d028df89cdb4cdfc4002d (MDEV-20950). --- mysql-test/suite/innodb/r/mvcc.result | 14 ++++++++++++++ mysql-test/suite/innodb/t/mvcc.test | 20 ++++++++++++++++++++ storage/innobase/row/row0vers.cc | 8 ++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/innodb/r/mvcc.result b/mysql-test/suite/innodb/r/mvcc.result index 6826978d6a7..b0b834c91a4 100644 --- a/mysql-test/suite/innodb/r/mvcc.result +++ b/mysql-test/suite/innodb/r/mvcc.result @@ -28,4 +28,18 @@ SELECT * FROM t1; a 0 DROP TABLE t1; +# +# MDEV-23198 Crash in REPLACE +# +BEGIN NOT ATOMIC +DECLARE c TEXT DEFAULT(SELECT CONCAT('CREATE TABLE t1(id INT PRIMARY KEY, c', +GROUP_CONCAT(seq SEPARATOR ' INT, c'), +' INT NOT NULL UNIQUE) ENGINE=InnoDB') +FROM seq_1_to_294); +EXECUTE IMMEDIATE c; +END; +$$ +INSERT INTO t1 SET id=1,c294=1; +REPLACE t1 SET id=1,c294=1; +DROP TABLE t1; SET GLOBAL innodb_file_per_table= @save_per_table; diff --git a/mysql-test/suite/innodb/t/mvcc.test b/mysql-test/suite/innodb/t/mvcc.test index bf76a5de798..7c37718c28a 100644 --- a/mysql-test/suite/innodb/t/mvcc.test +++ b/mysql-test/suite/innodb/t/mvcc.test @@ -1,4 +1,5 @@ --source include/have_innodb.inc +--source include/have_sequence.inc SET @save_per_table= @@GLOBAL.innodb_file_per_table; SET GLOBAL innodb_file_per_table= 1; @@ -49,4 +50,23 @@ SELECT * FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-23198 Crash in REPLACE +--echo # + +DELIMITER $$; +BEGIN NOT ATOMIC + DECLARE c TEXT DEFAULT(SELECT CONCAT('CREATE TABLE t1(id INT PRIMARY KEY, c', + GROUP_CONCAT(seq SEPARATOR ' INT, c'), + ' INT NOT NULL UNIQUE) ENGINE=InnoDB') + FROM seq_1_to_294); + EXECUTE IMMEDIATE c; +END; +$$ +DELIMITER ;$$ + +INSERT INTO t1 SET id=1,c294=1; +REPLACE t1 SET id=1,c294=1; +DROP TABLE t1; + SET GLOBAL innodb_file_per_table= @save_per_table; diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 09509444ea4..77bbb1b3459 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -91,7 +91,7 @@ row_vers_impl_x_locked_low( { rec_t* prev_version = NULL; rec_offs clust_offsets_[REC_OFFS_NORMAL_SIZE]; - rec_offs* clust_offsets = clust_offsets_; + rec_offs* clust_offsets; mem_heap_t* heap; dtuple_t* ientry = NULL; mem_heap_t* v_heap = NULL; @@ -105,7 +105,7 @@ row_vers_impl_x_locked_low( heap = mem_heap_create(1024); - clust_offsets = rec_get_offsets(clust_rec, clust_index, clust_offsets, + clust_offsets = rec_get_offsets(clust_rec, clust_index, clust_offsets_, true, ULINT_UNDEFINED, &heap); const trx_id_t trx_id = row_get_rec_trx_id( @@ -187,7 +187,7 @@ row_vers_impl_x_locked_low( ut_ad(committed || prev_version || !rec_get_deleted_flag(version, comp)); - /* Free version. */ + /* Free version and clust_offsets. */ mem_heap_free(old_heap); if (committed) { @@ -222,7 +222,7 @@ not_locked: } clust_offsets = rec_get_offsets( - prev_version, clust_index, clust_offsets, true, + prev_version, clust_index, clust_offsets_, true, ULINT_UNDEFINED, &heap); vers_del = rec_get_deleted_flag(prev_version, comp);