From 1eb364f8b3d623fdeca96a7ecf4a315282c83716 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Wed, 10 Oct 2018 17:16:34 +0200 Subject: [PATCH 1/9] MDEV-17421: mtr does not restart the server whose parameters were changed If a mtr test runs multiple servers and only some of them get restarted on whatever reason with new command-line parameters, then subsequent mtr test may fail, because no cleanup is performed. Replication and Galera test suites are affected. In the mtr script, there is a server_need_restart function that decides whether we need to start a new mysqld process before the new (next) test. If the mysqld parameters were changed in the previous test - not necessarily the parameters of the primary mysqld server, maybe even the secondary server parameters - this function decides to start a new mysqld process. But since it does not remove the old (changed) parameters, the new process starts with the parameters changed by the *previous* test. To correct this error, we must delete the modified process parameters after checking that they have been changed during the previous test. This patch also simplifies and makes more stable the galera_drop_database test, during debugging of which this problem was detected. https://jira.mariadb.org/browse/MDEV-17421 --- mysql-test/mysql-test-run.pl | 1 + mysql-test/suite/galera/disabled.def | 1 - .../galera/r/galera_mtr_restart_t1.result | 1 + .../galera/r/galera_mtr_restart_t2.result | 1 + .../suite/galera/t/galera_drop_database.test | 26 +++----------- .../suite/galera/t/galera_mtr_restart_t1.test | 35 +++++++++++++++++++ .../suite/galera/t/galera_mtr_restart_t2.test | 13 +++++++ mysql-test/suite/rpl/r/mtr_restart_t1.result | 5 +++ mysql-test/suite/rpl/r/mtr_restart_t2.result | 4 +++ mysql-test/suite/rpl/t/mtr_restart_t1.test | 31 ++++++++++++++++ mysql-test/suite/rpl/t/mtr_restart_t2.test | 18 ++++++++++ 11 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_mtr_restart_t1.result create mode 100644 mysql-test/suite/galera/r/galera_mtr_restart_t2.result create mode 100644 mysql-test/suite/galera/t/galera_mtr_restart_t1.test create mode 100644 mysql-test/suite/galera/t/galera_mtr_restart_t2.test create mode 100644 mysql-test/suite/rpl/r/mtr_restart_t1.result create mode 100644 mysql-test/suite/rpl/r/mtr_restart_t2.result create mode 100644 mysql-test/suite/rpl/t/mtr_restart_t1.test create mode 100644 mysql-test/suite/rpl/t/mtr_restart_t2.test diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index d969d7bf9f6..d3ffd16987d 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -5282,6 +5282,7 @@ sub server_need_restart { exists $server->{'restart_opts'}) { my $use_dynamic_option_switch= 0; + delete $server->{'restart_opts'}; if (!$use_dynamic_option_switch) { mtr_verbose_restart($server, "running with different options '" . diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 603031f52b7..464ed6444f9 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -34,4 +34,3 @@ partition : MDEV-13881 galera.partition failed in buildbot with wrong result galera_as_slave_replication_budle : MDEV-15785 Test case galera_as_slave_replication_bundle caused debug assertion galera_wan : MDEV-17259: Test failure on galera.galera_wan galera_pc_ignore_sb : MDEV-17357 Test failure on galera.galera_pc_ignore_sb -galera_drop_database : test diff --git a/mysql-test/suite/galera/r/galera_mtr_restart_t1.result b/mysql-test/suite/galera/r/galera_mtr_restart_t1.result new file mode 100644 index 00000000000..c628a99f1e8 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_mtr_restart_t1.result @@ -0,0 +1 @@ +weight=111 diff --git a/mysql-test/suite/galera/r/galera_mtr_restart_t2.result b/mysql-test/suite/galera/r/galera_mtr_restart_t2.result new file mode 100644 index 00000000000..0d488f3d174 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_mtr_restart_t2.result @@ -0,0 +1 @@ +weight=1 diff --git a/mysql-test/suite/galera/t/galera_drop_database.test b/mysql-test/suite/galera/t/galera_drop_database.test index 47fe8315198..12d9efea2f9 100644 --- a/mysql-test/suite/galera/t/galera_drop_database.test +++ b/mysql-test/suite/galera/t/galera_drop_database.test @@ -9,6 +9,7 @@ --let $node_2=node_2 --source include/auto_increment_offset_save.inc +# Create test database with two sets of the FTS indexes: CREATE DATABASE fts; USE fts; CREATE TABLE fts_t1 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 VARCHAR(100), FULLTEXT (f2)) ENGINE=InnoDB; @@ -23,34 +24,19 @@ DROP TABLE ten; UPDATE fts_t1 SET f2 = 'abcd'; UPDATE fts_t2 SET f2 = 'efjh'; +# Restart the second node: --connection node_2 -let $wsrep_cluster_address = `SELECT @@global.wsrep_node_incoming_address`; --source include/restart_mysqld.inc --connection node_1 --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc ---let $galera_connection_name = node_2a ---let $galera_server_number = 2 ---source include/galera_connect.inc ---connection node_2a +--connection node_2 --source include/wait_until_ready.inc +# Drop the tables and database after nodes restarted: --connection node_1 ---let $restart_parameters = --wsrep-cluster-address=gcomm://$wsrep_cluster_address ---source include/restart_mysqld.inc - ---connection node_2a ---let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc - ---let $galera_connection_name = node_1a ---let $galera_server_number = 1 ---source include/galera_connect.inc ---connection node_1a ---source include/wait_until_ready.inc - USE fts; DROP TABLE fts_t1; DROP TABLE fts_t2; @@ -58,8 +44,4 @@ SHOW TABLES; DROP DATABASE fts; # Restore original auto_increment_offset values. ---let $node_1=node_1a ---let $node_2=node_2a --source include/auto_increment_offset_restore.inc - ---source include/galera_end.inc diff --git a/mysql-test/suite/galera/t/galera_mtr_restart_t1.test b/mysql-test/suite/galera/t/galera_mtr_restart_t1.test new file mode 100644 index 00000000000..563d199625a --- /dev/null +++ b/mysql-test/suite/galera/t/galera_mtr_restart_t1.test @@ -0,0 +1,35 @@ +# This test verifies that mtr will restart the mysqld process, +# whose parameters were changed during the test. The verification +# itself is carried out in the following galera_mtr_restart_t2 +# test. If mtr restart the mysqld process, then the pc.weight +# value will be reset to the default ("1"), but if there is no +# restart, then we will see the changed value ("111") during +# the next test. +# +--source include/galera_cluster.inc +--source include/have_innodb.inc + +# Save original auto_increment_offset values. +--let $node_1=node_1 +--let $node_2=node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 +--let $restart_parameters = --wsrep_provider_options=pc.weight=111;repl.causal_read_timeout=PT90S;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S +--source include/restart_mysqld.inc + +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc + +--connection node_2 +--source include/wait_until_ready.inc + +# Check that the parameter value really changed: +--let $gp = `SELECT SUBSTR(@@wsrep_provider_options, LOCATE('pc.weight =', @@wsrep_provider_options) + LENGTH('pc.weight = '))` +--let $weight = `SELECT SUBSTR('$gp', 1, LOCATE(';', '$gp') - 1)` +--echo weight=$weight + +# Restore original auto_increment_offset values. +--connection node_1 +--source include/auto_increment_offset_restore.inc diff --git a/mysql-test/suite/galera/t/galera_mtr_restart_t2.test b/mysql-test/suite/galera/t/galera_mtr_restart_t2.test new file mode 100644 index 00000000000..fcc1d0515a6 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_mtr_restart_t2.test @@ -0,0 +1,13 @@ +# This test verifies that mtr will restart the mysqld process, +# whose parameters were changed during the previous test. If mtr +# restart the mysqld process, then the pc.weight value will be +# reset to the default ("1"), but if there is no restart, then +# we will see the changed value ("111") in this test. +# +--source include/galera_cluster.inc +--source include/have_innodb.inc + +--connection node_2 +--let $gp = `SELECT SUBSTR(@@wsrep_provider_options, LOCATE('pc.weight =', @@wsrep_provider_options) + LENGTH('pc.weight = '))` +--let $weight = `SELECT SUBSTR('$gp', 1, LOCATE(';', '$gp') - 1)` +--echo weight=$weight diff --git a/mysql-test/suite/rpl/r/mtr_restart_t1.result b/mysql-test/suite/rpl/r/mtr_restart_t1.result new file mode 100644 index 00000000000..56b64a2fc70 --- /dev/null +++ b/mysql-test/suite/rpl/r/mtr_restart_t1.result @@ -0,0 +1,5 @@ +include/master-slave.inc +[connection master] +include/rpl_stop_server.inc [server_number=1] +new auto_increment_offset=111 +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/mtr_restart_t2.result b/mysql-test/suite/rpl/r/mtr_restart_t2.result new file mode 100644 index 00000000000..3c8fe59d607 --- /dev/null +++ b/mysql-test/suite/rpl/r/mtr_restart_t2.result @@ -0,0 +1,4 @@ +include/master-slave.inc +[connection master] +auto_increment_offset=1 +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/mtr_restart_t1.test b/mysql-test/suite/rpl/t/mtr_restart_t1.test new file mode 100644 index 00000000000..3003a49c424 --- /dev/null +++ b/mysql-test/suite/rpl/t/mtr_restart_t1.test @@ -0,0 +1,31 @@ +# This test verifies that mtr will restart the mysqld process, +# whose parameters were changed during the test. The verification +# itself is carried out in the following mtr_restart_t2 test. +# If mtr restart the mysqld process, then the auto_increment_offset +# parameter value will be reset to the default ("1"), but if there +# is no restart, then we will see the changed value ("111") during +# the next test. +# +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +connection master; + +let $auto_increment_offset = `SELECT @@global.auto_increment_offset`; + +--let $rpl_server_number=1 +source include/rpl_stop_server.inc; +--let $rpl_server_parameters=--auto-increment-offset=111 +--let $keep_include_silent=1 +source include/rpl_start_server.inc; +--let $keep_include_silent=0 + +let $auto_increment_offset_new = `SELECT @@global.auto_increment_offset`; +--echo new auto_increment_offset=$auto_increment_offset_new + +--disable_query_log +--eval SET @@global.auto_increment_offset = $auto_increment_offset; +--enable_query_log + +--connection master +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/mtr_restart_t2.test b/mysql-test/suite/rpl/t/mtr_restart_t2.test new file mode 100644 index 00000000000..ab246af6b44 --- /dev/null +++ b/mysql-test/suite/rpl/t/mtr_restart_t2.test @@ -0,0 +1,18 @@ +# This test verifies that mtr will restart the mysqld process, +# whose parameters were changed during the previous test. If mtr +# restart the mysqld process, then the auto_increment_offsert +# parameter value will be reset to the default ("1"), but if there +# is no restart, then we will see the changed value ("111") in +# this test. +# +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +connection master; + +let $auto_increment_offset = `SELECT @@global.auto_increment_offset`; + +--echo auto_increment_offset=$auto_increment_offset + +--connection master +--source include/rpl_end.inc From cce2b45c8f5b3245d2e63d2763aeec59153d2c6f Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 10 Jan 2019 16:32:56 +0200 Subject: [PATCH 2/9] MDEV-17803 Row-based event is not applied when table map id is greater 32 bit int Row-based slave applier could not parse correctly the table id when the value exceeded the max of 32 bit unsigned int. The reason turns out in that the being parsed value placeholder was sized as 4 bytes. The type is fixed to ulonglong. Additionally the patch works around Rows_log_event::m_table_id 4 bytes size on 32 bits platforms. In case of last_table_id value overflows the 4 byte max, there won't be the zero value for m_table_id generated and the first wrapped-around value is one, this is thanks to excluding UINT_MAX32 + 1 from TABLE_SHARE::table_map_id. --- .../rpl/r/rpl_row_big_table_id_32bit.result | 38 +++++++++++++ .../rpl/r/rpl_row_big_table_id_64bit.result | 38 +++++++++++++ .../suite/rpl/t/rpl_row_big_table_id.inc | 56 +++++++++++++++++++ .../rpl/t/rpl_row_big_table_id_32bit.test | 11 ++++ .../rpl/t/rpl_row_big_table_id_64bit.test | 11 ++++ sql/table.h | 2 +- sql/table_cache.cc | 5 +- 7 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_row_big_table_id_32bit.result create mode 100644 mysql-test/suite/rpl/r/rpl_row_big_table_id_64bit.result create mode 100644 mysql-test/suite/rpl/t/rpl_row_big_table_id.inc create mode 100644 mysql-test/suite/rpl/t/rpl_row_big_table_id_32bit.test create mode 100644 mysql-test/suite/rpl/t/rpl_row_big_table_id_64bit.test diff --git a/mysql-test/suite/rpl/r/rpl_row_big_table_id_32bit.result b/mysql-test/suite/rpl/r/rpl_row_big_table_id_32bit.result new file mode 100644 index 00000000000..f84f02cc416 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_row_big_table_id_32bit.result @@ -0,0 +1,38 @@ +include/master-slave.inc +[connection master] +include/rpl_restart_server.inc [server_number=1] +SET @@debug_dbug="d,simulate_big_table_id"; +CREATE TABLE t (a int); +INSERT INTO t SET a= 0; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 1; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 2; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 3; +show binlog events in from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967294 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967294 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 1 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 1 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 2 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 2 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 3 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 3 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +DROP TABLE t; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_row_big_table_id_64bit.result b/mysql-test/suite/rpl/r/rpl_row_big_table_id_64bit.result new file mode 100644 index 00000000000..d8ecadc61d1 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_row_big_table_id_64bit.result @@ -0,0 +1,38 @@ +include/master-slave.inc +[connection master] +include/rpl_restart_server.inc [server_number=1] +SET @@debug_dbug="d,simulate_big_table_id"; +CREATE TABLE t (a int); +INSERT INTO t SET a= 0; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 1; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 2; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 3; +show binlog events in from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967294 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967294 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967295 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967295 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967296 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967296 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967297 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967297 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +DROP TABLE t; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_row_big_table_id.inc b/mysql-test/suite/rpl/t/rpl_row_big_table_id.inc new file mode 100644 index 00000000000..926b6e8b0ac --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_row_big_table_id.inc @@ -0,0 +1,56 @@ +################################################################## +# rpl_row_big_table_id +# +# MDEV-17803 Row-based event is not applied when +# table map id is greater 32 bit int +# +# Verify row-based events applying when table map id value is about and greater +# than 1 << 32. +################################################################## +--source include/have_debug.inc +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +--connection master +# To reset last table id +--let $rpl_server_number= 1 +--source include/rpl_restart_server.inc + +SET @@debug_dbug="d,simulate_big_table_id"; +CREATE TABLE t (a int); + +--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_pos= query_get_value(SHOW MASTER STATUS, Position, 1) +INSERT INTO t SET a= 0; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 1; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 2; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 3; + +# display simulated big table_id +--let $_in_from=in '$binlog_file' from $binlog_pos +--replace_result "$_in_from" "in from " +--replace_column 2 # 5 # +--replace_regex /\/\* xid=.* \*\//\/* XID *\// /file_id=[0-9]+/file_id=#/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ +--eval show binlog events in '$binlog_file' from $binlog_pos + + +--sync_slave_with_master + +if (`SELECT sum(a) != 6 FROM t`) +{ + --echo *** unexpected result; check slave applier *** + --die +} + + +# Cleanup + +--connection master +DROP TABLE t; + +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_row_big_table_id_32bit.test b/mysql-test/suite/rpl/t/rpl_row_big_table_id_32bit.test new file mode 100644 index 00000000000..08e1827c4c6 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_row_big_table_id_32bit.test @@ -0,0 +1,11 @@ +################################################################## +# rpl_row_big_table_id +# +# MDEV-17803 Row-based event is not applied when +# table map id is greater 32 bit int +# +# Verify row-based events applying when table map id value is about and greater +# than 1 << 32. +################################################################## +--source include/have_32bit.inc +--source rpl_row_big_table_id.inc diff --git a/mysql-test/suite/rpl/t/rpl_row_big_table_id_64bit.test b/mysql-test/suite/rpl/t/rpl_row_big_table_id_64bit.test new file mode 100644 index 00000000000..f9e021cdd2c --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_row_big_table_id_64bit.test @@ -0,0 +1,11 @@ +################################################################## +# rpl_row_big_table_id +# +# MDEV-17803 Row-based event is not applied when +# table map id is greater 32 bit int +# +# Verify row-based events applying when table map id value is about and greater +# than 1 << 32. +################################################################## +--source include/have_64bit.inc +--source rpl_row_big_table_id.inc diff --git a/sql/table.h b/sql/table.h index 4a1552f8c0d..10c1d1bc68e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1816,7 +1816,7 @@ struct TABLE_LIST /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */ List *index_hints; TABLE *table; /* opened table */ - uint table_id; /* table id (from binlog) for opened table */ + ulonglong table_id; /* table id (from binlog) for opened table */ /* select_result for derived table to pass it from table creation to table filling procedure diff --git a/sql/table_cache.cc b/sql/table_cache.cc index f13d7183a99..1154017d8d5 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -1206,6 +1206,9 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) DBUG_ASSERT(share); DBUG_ASSERT(tdc_inited); + DBUG_EXECUTE_IF("simulate_big_table_id", + if (last_table_id < UINT_MAX32) + last_table_id= UINT_MAX32 - 1;); /* There is one reserved number that cannot be used. Remember to change this when 6-byte global table id's are introduced. @@ -1215,7 +1218,7 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) my_atomic_rwlock_wrlock(&LOCK_tdc_atomics); tid= my_atomic_add64(&last_table_id, 1); my_atomic_rwlock_wrunlock(&LOCK_tdc_atomics); - } while (unlikely(tid == ~0UL)); + } while (unlikely(tid == ~0UL || tid == 0)); share->table_map_id= tid; DBUG_PRINT("info", ("table_id= %lu", share->table_map_id)); From 7886a70ef9d8a0fe8f8c0d8ef5c524187e58eaf0 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Jan 2019 17:18:57 +0100 Subject: [PATCH 3/9] MDEV-17421: mtr does not restart the server whose parameters were changed remove tests that rely on specific execution order --- mysql-test/suite/rpl/r/mtr_restart_t1.result | 5 ---- mysql-test/suite/rpl/r/mtr_restart_t2.result | 4 --- mysql-test/suite/rpl/t/mtr_restart_t1.test | 31 -------------------- mysql-test/suite/rpl/t/mtr_restart_t2.test | 18 ------------ 4 files changed, 58 deletions(-) delete mode 100644 mysql-test/suite/rpl/r/mtr_restart_t1.result delete mode 100644 mysql-test/suite/rpl/r/mtr_restart_t2.result delete mode 100644 mysql-test/suite/rpl/t/mtr_restart_t1.test delete mode 100644 mysql-test/suite/rpl/t/mtr_restart_t2.test diff --git a/mysql-test/suite/rpl/r/mtr_restart_t1.result b/mysql-test/suite/rpl/r/mtr_restart_t1.result deleted file mode 100644 index 56b64a2fc70..00000000000 --- a/mysql-test/suite/rpl/r/mtr_restart_t1.result +++ /dev/null @@ -1,5 +0,0 @@ -include/master-slave.inc -[connection master] -include/rpl_stop_server.inc [server_number=1] -new auto_increment_offset=111 -include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/mtr_restart_t2.result b/mysql-test/suite/rpl/r/mtr_restart_t2.result deleted file mode 100644 index 3c8fe59d607..00000000000 --- a/mysql-test/suite/rpl/r/mtr_restart_t2.result +++ /dev/null @@ -1,4 +0,0 @@ -include/master-slave.inc -[connection master] -auto_increment_offset=1 -include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/mtr_restart_t1.test b/mysql-test/suite/rpl/t/mtr_restart_t1.test deleted file mode 100644 index 3003a49c424..00000000000 --- a/mysql-test/suite/rpl/t/mtr_restart_t1.test +++ /dev/null @@ -1,31 +0,0 @@ -# This test verifies that mtr will restart the mysqld process, -# whose parameters were changed during the test. The verification -# itself is carried out in the following mtr_restart_t2 test. -# If mtr restart the mysqld process, then the auto_increment_offset -# parameter value will be reset to the default ("1"), but if there -# is no restart, then we will see the changed value ("111") during -# the next test. -# ---source include/have_binlog_format_row.inc ---source include/master-slave.inc - -connection master; - -let $auto_increment_offset = `SELECT @@global.auto_increment_offset`; - ---let $rpl_server_number=1 -source include/rpl_stop_server.inc; ---let $rpl_server_parameters=--auto-increment-offset=111 ---let $keep_include_silent=1 -source include/rpl_start_server.inc; ---let $keep_include_silent=0 - -let $auto_increment_offset_new = `SELECT @@global.auto_increment_offset`; ---echo new auto_increment_offset=$auto_increment_offset_new - ---disable_query_log ---eval SET @@global.auto_increment_offset = $auto_increment_offset; ---enable_query_log - ---connection master ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/mtr_restart_t2.test b/mysql-test/suite/rpl/t/mtr_restart_t2.test deleted file mode 100644 index ab246af6b44..00000000000 --- a/mysql-test/suite/rpl/t/mtr_restart_t2.test +++ /dev/null @@ -1,18 +0,0 @@ -# This test verifies that mtr will restart the mysqld process, -# whose parameters were changed during the previous test. If mtr -# restart the mysqld process, then the auto_increment_offsert -# parameter value will be reset to the default ("1"), but if there -# is no restart, then we will see the changed value ("111") in -# this test. -# ---source include/have_binlog_format_row.inc ---source include/master-slave.inc - -connection master; - -let $auto_increment_offset = `SELECT @@global.auto_increment_offset`; - ---echo auto_increment_offset=$auto_increment_offset - ---connection master ---source include/rpl_end.inc From d24060b1796bac5b11aee49f1c157dfc2c8200c1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Jan 2019 17:20:41 +0100 Subject: [PATCH 4/9] MDEV-17421: mtr does not restart the server whose parameters were changed remove tests that rely on specific execution order --- .../galera/r/galera_mtr_restart_t1.result | 1 - .../galera/r/galera_mtr_restart_t2.result | 1 - .../suite/galera/t/galera_mtr_restart_t1.test | 35 ------------------- .../suite/galera/t/galera_mtr_restart_t2.test | 13 ------- 4 files changed, 50 deletions(-) delete mode 100644 mysql-test/suite/galera/r/galera_mtr_restart_t1.result delete mode 100644 mysql-test/suite/galera/r/galera_mtr_restart_t2.result delete mode 100644 mysql-test/suite/galera/t/galera_mtr_restart_t1.test delete mode 100644 mysql-test/suite/galera/t/galera_mtr_restart_t2.test diff --git a/mysql-test/suite/galera/r/galera_mtr_restart_t1.result b/mysql-test/suite/galera/r/galera_mtr_restart_t1.result deleted file mode 100644 index c628a99f1e8..00000000000 --- a/mysql-test/suite/galera/r/galera_mtr_restart_t1.result +++ /dev/null @@ -1 +0,0 @@ -weight=111 diff --git a/mysql-test/suite/galera/r/galera_mtr_restart_t2.result b/mysql-test/suite/galera/r/galera_mtr_restart_t2.result deleted file mode 100644 index 0d488f3d174..00000000000 --- a/mysql-test/suite/galera/r/galera_mtr_restart_t2.result +++ /dev/null @@ -1 +0,0 @@ -weight=1 diff --git a/mysql-test/suite/galera/t/galera_mtr_restart_t1.test b/mysql-test/suite/galera/t/galera_mtr_restart_t1.test deleted file mode 100644 index 563d199625a..00000000000 --- a/mysql-test/suite/galera/t/galera_mtr_restart_t1.test +++ /dev/null @@ -1,35 +0,0 @@ -# This test verifies that mtr will restart the mysqld process, -# whose parameters were changed during the test. The verification -# itself is carried out in the following galera_mtr_restart_t2 -# test. If mtr restart the mysqld process, then the pc.weight -# value will be reset to the default ("1"), but if there is no -# restart, then we will see the changed value ("111") during -# the next test. -# ---source include/galera_cluster.inc ---source include/have_innodb.inc - -# Save original auto_increment_offset values. ---let $node_1=node_1 ---let $node_2=node_2 ---source include/auto_increment_offset_save.inc - ---connection node_2 ---let $restart_parameters = --wsrep_provider_options=pc.weight=111;repl.causal_read_timeout=PT90S;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S ---source include/restart_mysqld.inc - ---connection node_1 ---let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc - ---connection node_2 ---source include/wait_until_ready.inc - -# Check that the parameter value really changed: ---let $gp = `SELECT SUBSTR(@@wsrep_provider_options, LOCATE('pc.weight =', @@wsrep_provider_options) + LENGTH('pc.weight = '))` ---let $weight = `SELECT SUBSTR('$gp', 1, LOCATE(';', '$gp') - 1)` ---echo weight=$weight - -# Restore original auto_increment_offset values. ---connection node_1 ---source include/auto_increment_offset_restore.inc diff --git a/mysql-test/suite/galera/t/galera_mtr_restart_t2.test b/mysql-test/suite/galera/t/galera_mtr_restart_t2.test deleted file mode 100644 index fcc1d0515a6..00000000000 --- a/mysql-test/suite/galera/t/galera_mtr_restart_t2.test +++ /dev/null @@ -1,13 +0,0 @@ -# This test verifies that mtr will restart the mysqld process, -# whose parameters were changed during the previous test. If mtr -# restart the mysqld process, then the pc.weight value will be -# reset to the default ("1"), but if there is no restart, then -# we will see the changed value ("111") in this test. -# ---source include/galera_cluster.inc ---source include/have_innodb.inc - ---connection node_2 ---let $gp = `SELECT SUBSTR(@@wsrep_provider_options, LOCATE('pc.weight =', @@wsrep_provider_options) + LENGTH('pc.weight = '))` ---let $weight = `SELECT SUBSTR('$gp', 1, LOCATE(';', '$gp') - 1)` ---echo weight=$weight From c2a4bfad223903931171c473c42646e93dd0e728 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 9 Jan 2019 19:17:06 +0100 Subject: [PATCH 5/9] MDEV-18119 upgrading from 10.3 to 10.4 can result in the password for a user to be wiped out 10.1 part: SHOW CREATE USER didn't show the password, if plugin was set, but authentication_string was not --- mysql-test/r/connect.result | 12 ++++++++++++ mysql-test/t/connect.test | 5 +++++ sql/sql_acl.cc | 8 ++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index cb66ff483e1..d3c19fd1f9d 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -82,8 +82,20 @@ connect(localhost,test,zorro,test2,MASTER_PORT,MASTER_SOCKET); ERROR 28000: Access denied for user 'test'@'localhost' (using password: YES) connect(localhost,test,zorro,test,MASTER_PORT,MASTER_SOCKET); ERROR 28000: Access denied for user 'test'@'localhost' (using password: YES) +select user,host,password,plugin,authentication_string from mysql.user where user='test'; +user host password plugin authentication_string +test localhost *5FDFF3268A50F41C5D18D2CA2F754D7BDB9B3E59 +test 127.0.0.1 *5FDFF3268A50F41C5D18D2CA2F754D7BDB9B3E59 update mysql.user set password=old_password("gambling2") where user=_binary"test"; flush privileges; +show grants for test@localhost; +Grants for test@localhost +GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' IDENTIFIED BY PASSWORD '2f27438961437573' +update mysql.user set plugin='mysql_old_password' where user='test'; +flush privileges; +show grants for test@localhost; +Grants for test@localhost +GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' IDENTIFIED BY PASSWORD '2f27438961437573' set password=""; set password='gambling3'; ERROR HY000: Password hash should be a 41-digit hexadecimal number diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 3a38ad88462..560f29e840d 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -66,8 +66,13 @@ connect (fail_con,localhost,test,zorro,test2); connect (fail_con,localhost,test,zorro,); # check if old password version also works +select user,host,password,plugin,authentication_string from mysql.user where user='test'; update mysql.user set password=old_password("gambling2") where user=_binary"test"; flush privileges; +show grants for test@localhost; +update mysql.user set plugin='mysql_old_password' where user='test'; +flush privileges; +show grants for test@localhost; connect (con10,localhost,test,gambling2,); connect (con5,localhost,test,gambling2,mysql); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 784f2338a55..9d6e6c51fb6 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -986,8 +986,7 @@ static bool fix_user_plugin_ptr(ACL_USER *user) else return true; - if (user->auth_string.length) - set_user_salt(user, user->auth_string.str, user->auth_string.length); + set_user_salt(user, user->auth_string.str, user->auth_string.length); return false; } @@ -1457,6 +1456,11 @@ static bool acl_load(THD *thd, TABLE_LIST *tables) safe_str(user.user.str), safe_str(user.host.hostname)); } + else if (password_len) + { + user.auth_string.str= password; + user.auth_string.length= password_len; + } fix_user_plugin_ptr(&user); } From b22354680ef9c5ffeda91cba284ed236fbf3c31e Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Wed, 23 Jan 2019 20:16:21 +0200 Subject: [PATCH 6/9] merge 10.0 -> 10.1 to resolve MDEV-17803 conflicts. --- .../rpl/r/rpl_row_big_table_id,32bit.rdiff | 29 ++++++++++ .../suite/rpl/r/rpl_row_big_table_id.result | 38 +++++++++++++ .../suite/rpl/t/rpl_row_big_table_id.test | 57 +++++++++++++++++++ sql/table.h | 2 +- sql/table_cache.cc | 5 +- 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_row_big_table_id,32bit.rdiff create mode 100644 mysql-test/suite/rpl/r/rpl_row_big_table_id.result create mode 100644 mysql-test/suite/rpl/t/rpl_row_big_table_id.test diff --git a/mysql-test/suite/rpl/r/rpl_row_big_table_id,32bit.rdiff b/mysql-test/suite/rpl/r/rpl_row_big_table_id,32bit.rdiff new file mode 100644 index 00000000000..1dbbfa9252f --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_row_big_table_id,32bit.rdiff @@ -0,0 +1,29 @@ +--- r/rpl_row_big_table_id.result 2019-01-23 19:58:07.204914873 +0200 ++++ r/rpl_row_big_table_id_32bit.result 2019-01-23 19:43:54.590640934 +0200 +@@ -19,20 +19,20 @@ + master-bin.000002 # Gtid 1 # GTID #-#-# + master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' + master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +-master-bin.000002 # Table_map 1 # table_id: 4294967295 (test.t) +-master-bin.000002 # Write_rows_v1 1 # table_id: 4294967295 flags: STMT_END_F ++master-bin.000002 # Table_map 1 # table_id: 1 (test.t) ++master-bin.000002 # Write_rows_v1 1 # table_id: 1 flags: STMT_END_F + master-bin.000002 # Query 1 # COMMIT + master-bin.000002 # Gtid 1 # GTID #-#-# + master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' + master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +-master-bin.000002 # Table_map 1 # table_id: 4294967296 (test.t) +-master-bin.000002 # Write_rows_v1 1 # table_id: 4294967296 flags: STMT_END_F ++master-bin.000002 # Table_map 1 # table_id: 2 (test.t) ++master-bin.000002 # Write_rows_v1 1 # table_id: 2 flags: STMT_END_F + master-bin.000002 # Query 1 # COMMIT + master-bin.000002 # Gtid 1 # GTID #-#-# + master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' + master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +-master-bin.000002 # Table_map 1 # table_id: 4294967297 (test.t) +-master-bin.000002 # Write_rows_v1 1 # table_id: 4294967297 flags: STMT_END_F ++master-bin.000002 # Table_map 1 # table_id: 3 (test.t) ++master-bin.000002 # Write_rows_v1 1 # table_id: 3 flags: STMT_END_F + master-bin.000002 # Query 1 # COMMIT + DROP TABLE t; + include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_row_big_table_id.result b/mysql-test/suite/rpl/r/rpl_row_big_table_id.result new file mode 100644 index 00000000000..d8ecadc61d1 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_row_big_table_id.result @@ -0,0 +1,38 @@ +include/master-slave.inc +[connection master] +include/rpl_restart_server.inc [server_number=1] +SET @@debug_dbug="d,simulate_big_table_id"; +CREATE TABLE t (a int); +INSERT INTO t SET a= 0; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 1; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 2; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 3; +show binlog events in from ; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967294 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967294 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967295 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967295 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967296 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967296 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +master-bin.000002 # Gtid 1 # GTID #-#-# +master-bin.000002 # Query 1 # use `test`; ALTER TABLE t comment '' +master-bin.000002 # Gtid 1 # BEGIN GTID #-#-# +master-bin.000002 # Table_map 1 # table_id: 4294967297 (test.t) +master-bin.000002 # Write_rows_v1 1 # table_id: 4294967297 flags: STMT_END_F +master-bin.000002 # Query 1 # COMMIT +DROP TABLE t; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_row_big_table_id.test b/mysql-test/suite/rpl/t/rpl_row_big_table_id.test new file mode 100644 index 00000000000..0c6f9d5e862 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_row_big_table_id.test @@ -0,0 +1,57 @@ +################################################################## +# rpl_row_big_table_id +# +# MDEV-17803 Row-based event is not applied when +# table map id is greater 32 bit int +# +# Verify row-based events applying when table map id value is about and greater +# than 1 << 32. +################################################################## +--source include/word_size.inc +--source include/have_debug.inc +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +--connection master +# To reset last table id +--let $rpl_server_number= 1 +--source include/rpl_restart_server.inc + +SET @@debug_dbug="d,simulate_big_table_id"; +CREATE TABLE t (a int); + +--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_pos= query_get_value(SHOW MASTER STATUS, Position, 1) +INSERT INTO t SET a= 0; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 1; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 2; +ALTER TABLE t comment ''; +INSERT INTO t SET a= 3; + +# display simulated big table_id +--let $_in_from=in '$binlog_file' from $binlog_pos +--replace_result "$_in_from" "in from " +--replace_column 2 # 5 # +--replace_regex /\/\* xid=.* \*\//\/* XID *\// /file_id=[0-9]+/file_id=#/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ +--eval show binlog events in '$binlog_file' from $binlog_pos + + +--sync_slave_with_master + +if (`SELECT sum(a) != 6 FROM t`) +{ + --echo *** unexpected result; check slave applier *** + --die +} + + +# Cleanup + +--connection master +DROP TABLE t; + +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/sql/table.h b/sql/table.h index ca32234579f..1a24d786d82 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1887,7 +1887,7 @@ struct TABLE_LIST /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */ List *index_hints; TABLE *table; /* opened table */ - uint table_id; /* table id (from binlog) for opened table */ + ulonglong table_id; /* table id (from binlog) for opened table */ /* select_result for derived table to pass it from table creation to table filling procedure diff --git a/sql/table_cache.cc b/sql/table_cache.cc index 6d190400217..b3cf6cd2892 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -1134,6 +1134,9 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) DBUG_ASSERT(share); DBUG_ASSERT(tdc_inited); + DBUG_EXECUTE_IF("simulate_big_table_id", + if (last_table_id < UINT_MAX32) + last_table_id= UINT_MAX32 - 1;); /* There is one reserved number that cannot be used. Remember to change this when 6-byte global table id's are introduced. @@ -1141,7 +1144,7 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) do { tid= my_atomic_add64_explicit(&last_table_id, 1, MY_MEMORY_ORDER_RELAXED); - } while (unlikely(tid == ~0UL)); + } while (unlikely(tid == ~0UL || tid == 0)); share->table_map_id= tid; DBUG_PRINT("info", ("table_id= %lu", share->table_map_id)); From a0f3b9f94f3094ccb9ce75c53b25d36c4c78e922 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 24 Jan 2019 13:52:51 +0530 Subject: [PATCH 7/9] MDEV-17376 Server fails to set ADD_PK_INDEX, DROP_PK_INDEX if unique index nominated as PK Problem: ======== Server fails to notify the engine by not setting the ADD_PK_INDEX and DROP_PK_INDEX When there is a i) Change in candidate for primary key. ii) New candidate for primary key. Fix: ==== Server sets the ADD_PK_INDEX and DROP_PK_INDEX while doing alter for the above problematic case. --- .../suite/innodb/r/alter_candidate_key.result | 107 ++++++++++++++++++ .../suite/innodb/r/innodb-table-online.result | 11 -- .../suite/innodb/t/alter_candidate_key.test | 72 ++++++++++++ .../suite/innodb/t/innodb-table-online.test | 4 - sql/sql_table.cc | 17 +++ 5 files changed, 196 insertions(+), 15 deletions(-) create mode 100644 mysql-test/suite/innodb/r/alter_candidate_key.result create mode 100644 mysql-test/suite/innodb/t/alter_candidate_key.test diff --git a/mysql-test/suite/innodb/r/alter_candidate_key.result b/mysql-test/suite/innodb/r/alter_candidate_key.result new file mode 100644 index 00000000000..b0b8e390c7e --- /dev/null +++ b/mysql-test/suite/innodb/r/alter_candidate_key.result @@ -0,0 +1,107 @@ +CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL, +UNIQUE KEY uidx2(f1,f2), +UNIQUE KEY uidx1(f2)) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + `f2` int(11) NOT NULL, + UNIQUE KEY `uidx2` (`f1`,`f2`), + UNIQUE KEY `uidx1` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter + SIGNAL conc_dml WAIT_FOR go_ahead'; +ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE; +SET DEBUG_SYNC = 'now WAIT_FOR conc_dml'; +DELETE FROM t1; +SET DEBUG_SYNC = 'now SIGNAL go_ahead'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f11` int(11) DEFAULT NULL, + `f2` int(11) NOT NULL, + UNIQUE KEY `uidx1` (`f2`), + UNIQUE KEY `uidx2` (`f11`,`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; +CREATE TABLE t1(f1 INT, f2 INT, +PRIMARY KEY(f1, f2), +UNIQUE INDEX uidx2 (f1, f2), +UNIQUE INDEX uidx1 (f2))ENGINE=InnoDB; +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL DEFAULT '0', + `f2` int(11) NOT NULL DEFAULT '0', + UNIQUE KEY `uidx2` (`f1`,`f2`), + UNIQUE KEY `uidx1` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter + SIGNAL conc_dml WAIT_FOR go_ahead'; +ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE; +SET DEBUG_SYNC = 'now WAIT_FOR conc_dml'; +INSERT INTO t1 VALUES(1, 1), (1, 1); +ERROR 23000: Duplicate entry '1-1' for key 'uidx2' +SET DEBUG_SYNC = 'now SIGNAL go_ahead'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f11` int(11) DEFAULT NULL, + `f2` int(11) NOT NULL DEFAULT '0', + UNIQUE KEY `uidx1` (`f2`), + UNIQUE KEY `uidx2` (`f11`,`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; +SET SQL_MODE= strict_trans_tables; +CREATE TABLE t1(a INT UNIQUE) ENGINE=InnoDB; +SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done'; +ALTER TABLE t1 MODIFY COLUMN a INT NOT NULL; +SET DEBUG_SYNC='now WAIT_FOR dml'; +BEGIN; +INSERT INTO t1 SET a=NULL; +ROLLBACK; +set DEBUG_SYNC='now SIGNAL dml_done'; +ERROR 22004: Invalid use of NULL value +DROP TABLE t1; +SET DEBUG_SYNC="RESET"; +SET SQL_MODE=DEFAULT; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, PRIMARY KEY(f1, f2), +UNIQUE KEY(f2))ENGINE=InnoDB; +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + `f2` int(11) NOT NULL, + UNIQUE KEY `f2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, +UNIQUE KEY(f2), UNIQUE KEY(f2))ENGINE=InnoDB; +Warnings: +Note 1831 Duplicate index `f2_2`. This is deprecated and will be disallowed in a future release. +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + `f2` int(11) NOT NULL, + UNIQUE KEY `f2` (`f2`), + UNIQUE KEY `f2_2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +ALTER TABLE t1 DROP INDEX f2, ALGORITHM=INPLACE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) NOT NULL, + `f2` int(11) NOT NULL, + UNIQUE KEY `f2_2` (`f2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/innodb-table-online.result b/mysql-test/suite/innodb/r/innodb-table-online.result index eb55ba57e36..0a8d1c2fefb 100644 --- a/mysql-test/suite/innodb/r/innodb-table-online.result +++ b/mysql-test/suite/innodb/r/innodb-table-online.result @@ -85,17 +85,6 @@ t1 CREATE TABLE `t1` ( UNIQUE KEY `c2` (`c2`), UNIQUE KEY `c2_2` (`c2`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT -ALTER TABLE t1 DROP INDEX c2, ALGORITHM = INPLACE; -ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Dropping a primary key is not allowed without also adding a new primary key. Try ALGORITHM=COPY. -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `c1` int(11) NOT NULL, - `c2` int(11) NOT NULL, - `c3` text NOT NULL, - UNIQUE KEY `c2` (`c2`), - UNIQUE KEY `c2_2` (`c2`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT ALTER TABLE t1 DROP INDEX c2, ADD PRIMARY KEY(c1); # session default SET DEBUG_SYNC = 'now WAIT_FOR scanned'; diff --git a/mysql-test/suite/innodb/t/alter_candidate_key.test b/mysql-test/suite/innodb/t/alter_candidate_key.test new file mode 100644 index 00000000000..7429cd89a1a --- /dev/null +++ b/mysql-test/suite/innodb/t/alter_candidate_key.test @@ -0,0 +1,72 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL, + UNIQUE KEY uidx2(f1,f2), + UNIQUE KEY uidx1(f2)) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1, 1); +SHOW CREATE TABLE t1; +SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter + SIGNAL conc_dml WAIT_FOR go_ahead'; +--send ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE +connect (con1,localhost,root,,); +SET DEBUG_SYNC = 'now WAIT_FOR conc_dml'; +DELETE FROM t1; +SET DEBUG_SYNC = 'now SIGNAL go_ahead'; +connection default; +reap; +SHOW CREATE TABLE t1; +CHECK TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1(f1 INT, f2 INT, + PRIMARY KEY(f1, f2), + UNIQUE INDEX uidx2 (f1, f2), + UNIQUE INDEX uidx1 (f2))ENGINE=InnoDB; +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter + SIGNAL conc_dml WAIT_FOR go_ahead'; +--send ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE +connection con1; +SET DEBUG_SYNC = 'now WAIT_FOR conc_dml'; +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES(1, 1), (1, 1); +SET DEBUG_SYNC = 'now SIGNAL go_ahead'; +connection default; +reap; +SHOW CREATE TABLE t1; +CHECK TABLE t1; +DROP TABLE t1; + +SET SQL_MODE= strict_trans_tables; +CREATE TABLE t1(a INT UNIQUE) ENGINE=InnoDB; +SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done'; +--send ALTER TABLE t1 MODIFY COLUMN a INT NOT NULL +connection con1; +SET DEBUG_SYNC='now WAIT_FOR dml'; +BEGIN; +INSERT INTO t1 SET a=NULL; +ROLLBACK; +set DEBUG_SYNC='now SIGNAL dml_done'; +connection default; +--error ER_INVALID_USE_OF_NULL +reap; +DROP TABLE t1; +disconnect con1; +SET DEBUG_SYNC="RESET"; +SET SQL_MODE=DEFAULT; + +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, PRIMARY KEY(f1, f2), + UNIQUE KEY(f2))ENGINE=InnoDB; +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, + UNIQUE KEY(f2), UNIQUE KEY(f2))ENGINE=InnoDB; +SHOW CREATE TABLE t1; +ALTER TABLE t1 DROP INDEX f2, ALGORITHM=INPLACE; +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb-table-online.test b/mysql-test/suite/innodb/t/innodb-table-online.test index 4e9f2f13344..b0711412a52 100644 --- a/mysql-test/suite/innodb/t/innodb-table-online.test +++ b/mysql-test/suite/innodb/t/innodb-table-online.test @@ -100,10 +100,6 @@ LOCK = SHARED, ALGORITHM = INPLACE; ALTER TABLE t1 ADD UNIQUE INDEX(c2), LOCK = EXCLUSIVE, ALGORITHM = INPLACE; -SHOW CREATE TABLE t1; -# We do not support plain DROP_PK_INDEX without ADD_PK_INDEX. ---error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON -ALTER TABLE t1 DROP INDEX c2, ALGORITHM = INPLACE; SHOW CREATE TABLE t1; # Now the previous DEBUG_SYNC should kick in. --send diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2302026b18b..df1ff8eaf5d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6439,6 +6439,12 @@ static bool fill_alter_inplace_info(THD *thd, KEY *new_key; KEY *new_key_end= ha_alter_info->key_info_buffer + ha_alter_info->key_count; + /* + Primary key index for the new table + */ + const KEY* const new_pk= (ha_alter_info->key_count > 0 && + is_candidate_key(ha_alter_info->key_info_buffer)) ? + ha_alter_info->key_info_buffer : NULL; DBUG_PRINT("info", ("index count old: %d new: %d", table->s->keys, ha_alter_info->key_count)); @@ -6513,6 +6519,17 @@ static bool fill_alter_inplace_info(THD *thd, new_field->field->field_index != key_part->fieldnr - 1) goto index_changed; } + + /* + Rebuild the index if following condition get satisfied: + + (i) Old table doesn't have primary key, new table has it and vice-versa + (ii) Primary key changed to another existing index + */ + if ((new_key == new_pk) != + ((uint) (table_key - table->key_info) == table->s->primary_key)) + goto index_changed; + continue; index_changed: From edeba0c8733409865c3abcab881af0d48b7be94f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Jan 2019 18:50:47 +0100 Subject: [PATCH 8/9] MDEV-17868 mysqltest fails to link with system PCRE libraries pcre needs symbols from pcreposix (but this is only an issue when linking with system static libraries) --- client/CMakeLists.txt | 2 +- libmysqld/examples/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index c75abd4956d..c760a9dbf14 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -41,7 +41,7 @@ ENDIF(UNIX) MYSQL_ADD_EXECUTABLE(mysqltest mysqltest.cc COMPONENT Test) SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS") -TARGET_LINK_LIBRARIES(mysqltest mysqlclient pcre pcreposix) +TARGET_LINK_LIBRARIES(mysqltest mysqlclient pcreposix pcre) SET_TARGET_PROPERTIES(mysqltest PROPERTIES ENABLE_EXPORTS TRUE) diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt index d47638ad2f9..1eb07a2adf8 100644 --- a/libmysqld/examples/CMakeLists.txt +++ b/libmysqld/examples/CMakeLists.txt @@ -34,7 +34,7 @@ ENDIF(UNIX) MYSQL_ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc COMPONENT Test) -TARGET_LINK_LIBRARIES(mysqltest_embedded mysqlserver pcre pcreposix) +TARGET_LINK_LIBRARIES(mysqltest_embedded mysqlserver pcreposix pcre) IF(CMAKE_GENERATOR MATCHES "Xcode") # It does not seem possible to tell Xcode the resulting target might need From ba1ce3aeae49b6c8055d673e6dafff741f1a9713 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 24 Jan 2019 12:01:43 +0200 Subject: [PATCH 9/9] MDEV-17803 side effect resulted in table id advance. A test result file is updated. --- mysql-test/r/mysqlbinlog_row_minimal.result | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mysql-test/r/mysqlbinlog_row_minimal.result b/mysql-test/r/mysqlbinlog_row_minimal.result index 6ffaeeafc53..34bafd6301a 100644 --- a/mysql-test/r/mysqlbinlog_row_minimal.result +++ b/mysql-test/r/mysqlbinlog_row_minimal.result @@ -54,9 +54,9 @@ CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 INT, f4 INT, f5 MEDIUMIN BEGIN /*!*/; # at 781 -# server id 1 end_log_pos 833 Table_map: `test`.`t1` mapped to number 30 +# server id 1 end_log_pos 833 Table_map: `test`.`t1` mapped to number 31 # at 833 -# server id 1 end_log_pos 898 Write_rows: table id 30 flags: STMT_END_F +# server id 1 end_log_pos 898 Write_rows: table id 31 flags: STMT_END_F ### INSERT INTO `test`.`t1` ### SET ### @1=10 /* INT meta=0 nullable=0 is_null=0 */ @@ -79,9 +79,9 @@ COMMIT BEGIN /*!*/; # at 1005 -# server id 1 end_log_pos 1057 Table_map: `test`.`t1` mapped to number 30 +# server id 1 end_log_pos 1057 Table_map: `test`.`t1` mapped to number 31 # at 1057 -# server id 1 end_log_pos 1121 Write_rows: table id 30 flags: STMT_END_F +# server id 1 end_log_pos 1121 Write_rows: table id 31 flags: STMT_END_F ### INSERT INTO `test`.`t1` ### SET ### @1=11 /* INT meta=0 nullable=0 is_null=0 */ @@ -104,9 +104,9 @@ COMMIT BEGIN /*!*/; # at 1228 -# server id 1 end_log_pos 1280 Table_map: `test`.`t1` mapped to number 30 +# server id 1 end_log_pos 1280 Table_map: `test`.`t1` mapped to number 31 # at 1280 -# server id 1 end_log_pos 1343 Write_rows: table id 30 flags: STMT_END_F +# server id 1 end_log_pos 1343 Write_rows: table id 31 flags: STMT_END_F ### INSERT INTO `test`.`t1` ### SET ### @1=12 /* INT meta=0 nullable=0 is_null=0 */ @@ -129,9 +129,9 @@ COMMIT BEGIN /*!*/; # at 1450 -# server id 1 end_log_pos 1502 Table_map: `test`.`t1` mapped to number 30 +# server id 1 end_log_pos 1502 Table_map: `test`.`t1` mapped to number 31 # at 1502 -# server id 1 end_log_pos 1568 Write_rows: table id 30 flags: STMT_END_F +# server id 1 end_log_pos 1568 Write_rows: table id 31 flags: STMT_END_F ### INSERT INTO `test`.`t1` ### SET ### @1=13 /* INT meta=0 nullable=0 is_null=0 */ @@ -154,9 +154,9 @@ COMMIT BEGIN /*!*/; # at 1675 -# server id 1 end_log_pos 1727 Table_map: `test`.`t2` mapped to number 31 +# server id 1 end_log_pos 1727 Table_map: `test`.`t2` mapped to number 32 # at 1727 -# server id 1 end_log_pos 1890 Write_rows: table id 31 flags: STMT_END_F +# server id 1 end_log_pos 1890 Write_rows: table id 32 flags: STMT_END_F ### INSERT INTO `test`.`t2` ### SET ### @1=10 /* INT meta=0 nullable=0 is_null=0 */ @@ -212,9 +212,9 @@ COMMIT BEGIN /*!*/; # at 1997 -# server id 1 end_log_pos 2049 Table_map: `test`.`t2` mapped to number 31 +# server id 1 end_log_pos 2049 Table_map: `test`.`t2` mapped to number 32 # at 2049 -# server id 1 end_log_pos 2119 Update_rows: table id 31 flags: STMT_END_F +# server id 1 end_log_pos 2119 Update_rows: table id 32 flags: STMT_END_F ### UPDATE `test`.`t2` ### WHERE ### @1=10 /* INT meta=0 nullable=0 is_null=0 */ @@ -244,9 +244,9 @@ COMMIT BEGIN /*!*/; # at 2226 -# server id 1 end_log_pos 2278 Table_map: `test`.`t1` mapped to number 30 +# server id 1 end_log_pos 2278 Table_map: `test`.`t1` mapped to number 31 # at 2278 -# server id 1 end_log_pos 2328 Delete_rows: table id 30 flags: STMT_END_F +# server id 1 end_log_pos 2328 Delete_rows: table id 31 flags: STMT_END_F ### DELETE FROM `test`.`t1` ### WHERE ### @1=10 /* INT meta=0 nullable=0 is_null=0 */ @@ -270,9 +270,9 @@ COMMIT BEGIN /*!*/; # at 2435 -# server id 1 end_log_pos 2487 Table_map: `test`.`t2` mapped to number 31 +# server id 1 end_log_pos 2487 Table_map: `test`.`t2` mapped to number 32 # at 2487 -# server id 1 end_log_pos 2537 Delete_rows: table id 31 flags: STMT_END_F +# server id 1 end_log_pos 2537 Delete_rows: table id 32 flags: STMT_END_F ### DELETE FROM `test`.`t2` ### WHERE ### @1=10 /* INT meta=0 nullable=0 is_null=0 */