From 8ea08505a159566848a8dd267d152cb74645d903 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 8 Mar 2022 09:35:03 +1100 Subject: [PATCH 1/4] MDEV-28022: Debian stretch has zstd too old zstd-1.1.3 is needed however stretch has only 1.1.2. Move to distro version based checks as checks against the apt-cache are unreliable if there is no cache. --- debian/autobake-deb.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/debian/autobake-deb.sh b/debian/autobake-deb.sh index ae9b77a382b..c0153f0d805 100755 --- a/debian/autobake-deb.sh +++ b/debian/autobake-deb.sh @@ -42,6 +42,14 @@ GCCVERSION=$(gcc -dumpfullversion -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g # Debian policy and targeting Debian Sid. Then case-by-case run in autobake-deb.sh # tests for backwards compatibility and strip away parts on older builders. +CODENAME="$(lsb_release -sc)" +case "${CODENAME}" in + stretch) + # MDEV-28022 libzstd-dev-1.1.3 minimum version + sed -i -e '/libzstd-dev/d' debian/control + ;; +esac + # If libcrack2 (>= 2.9.0) is not available (before Debian Jessie and Ubuntu Trusty) # clean away the cracklib stanzas so the package can build without them. if ! apt-cache madison libcrack2-dev | grep 'libcrack2-dev *| *2\.9' >/dev/null 2>&1 @@ -72,13 +80,6 @@ then sed '/mariadb-service-convert/d' -i debian/mariadb-server-10.3.install fi -# If libzstd-dev is not available (before Debian Stretch and Ubuntu Xenial) -# remove the dependency from server and rocksdb so it can build properly -if ! apt-cache madison libzstd-dev | grep 'libzstd-dev' >/dev/null 2>&1 -then - sed '/libzstd-dev/d' -i debian/control -fi - # The binaries should be fully hardened by default. However TokuDB compilation seems to fail on # Debian Jessie and older and on Ubuntu Xenial and older with the following error message: # /usr/bin/ld.bfd.real: /tmp/ccOIwjFo.ltrans0.ltrans.o: relocation R_X86_64_PC32 against symbol @@ -139,7 +140,6 @@ source ./VERSION UPSTREAM="${MYSQL_VERSION_MAJOR}.${MYSQL_VERSION_MINOR}.${MYSQL_VERSION_PATCH}${MYSQL_VERSION_EXTRA}" PATCHLEVEL="+maria" LOGSTRING="MariaDB build" -CODENAME="$(lsb_release -sc)" EPOCH="1:" dch -b -D ${CODENAME} -v "${EPOCH}${UPSTREAM}${PATCHLEVEL}~${CODENAME}" "Automatic build with ${LOGSTRING}." From e7cf871dda59ad39c9125288149a4ec38518d41c Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 3 Mar 2022 17:47:54 +0200 Subject: [PATCH 2/4] MDEV-24617 OPTIMIZE on a sequence causes unexpected ER_BINLOG_UNSAFE_STATEMENT The warning out of OPTIMIZE Statement is unsafe because it uses a system function was indeed counterfactual and was resulted by checking an insufficiently strict property of lex' sql_command_flags. Fixed with deploying an additional checking of weather the current sql command that modifes a share->non_determinstic_insert table is capable of generating ROW format events. The extra check rules out the unsafety to OPTIMIZE et al, while the existing check continues to do so to CREATE TABLE (which is perculiarly tagged as ROW-event generative sql command). As a side effect sql_sequence.binlog test gets corrected and binlog_stm_unsafe_warning.test is reinforced to add up an unsafe CREATE..SELECT test. --- .../binlog/r/binlog_stm_unsafe_warning.result | 13 +++++++++- .../binlog/t/binlog_stm_unsafe_warning.test | 14 ++++++++++- mysql-test/suite/sql_sequence/binlog.result | 24 +++++++++++++++++++ mysql-test/suite/sql_sequence/binlog.test | 15 ++++++++++-- sql/sql_class.cc | 3 ++- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result index 135271d325e..971fae6208f 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result +++ b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result @@ -104,6 +104,17 @@ Note 1592 Unsafe statement written to the binary log using statement format sinc SHOW WARNINGS; Level Code Message Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly +CREATE TABLE t3 (a INT(11) DEFAULT NULL); +INSERT INTO t3 VALUES (1); +CREATE TABLE t4 (a INT(11) DEFAULT NULL, b BIGINT(20) DEFAULT uuid_short()) SELECT * FROM t3; +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave +SHOW WARNINGS; +Level Code Message +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave +CREATE OR REPLACE TABLE t4 (a INT(11) DEFAULT NULL) SELECT * FROM t3; +SHOW WARNINGS; +Level Code Message DROP FUNCTION sf_bug50192; DROP TRIGGER tr_bug50192; -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3, t4; diff --git a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test index 70566da4cfa..578f0ff5fc8 100644 --- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test +++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test @@ -189,8 +189,20 @@ SHOW WARNINGS; SELECT sf_bug50192(); SHOW WARNINGS; +# The test proves MDEV-24617 fixes leave in force +# unsafe warnings in non-deterministic CREATE..SELECT cases. +# Below an inserted default value to `b` of the target table is replication +# unsafe. A warning must be out. +CREATE TABLE t3 (a INT(11) DEFAULT NULL); +INSERT INTO t3 VALUES (1); +CREATE TABLE t4 (a INT(11) DEFAULT NULL, b BIGINT(20) DEFAULT uuid_short()) SELECT * FROM t3; +SHOW WARNINGS; +# no warning out of a deterministic "rhs" of SELECT +CREATE OR REPLACE TABLE t4 (a INT(11) DEFAULT NULL) SELECT * FROM t3; +SHOW WARNINGS; + # cleanup DROP FUNCTION sf_bug50192; DROP TRIGGER tr_bug50192; -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3, t4; diff --git a/mysql-test/suite/sql_sequence/binlog.result b/mysql-test/suite/sql_sequence/binlog.result index f01b3234e96..32788c988fc 100644 --- a/mysql-test/suite/sql_sequence/binlog.result +++ b/mysql-test/suite/sql_sequence/binlog.result @@ -12,6 +12,20 @@ select next value for s1, minimum_value from s1 where maximum_value> 4; next value for s1 minimum_value 4 1 alter sequence s1 maxvalue 1000; +optimize table s1; +Table Op Msg_type Msg_text +test.s1 optimize note The storage engine for the table doesn't support optimize +analyze table s1; +Table Op Msg_type Msg_text +test.s1 analyze note The storage engine for the table doesn't support analyze +repair table s1; +Table Op Msg_type Msg_text +test.s1 repair status OK +check table s1; +Table Op Msg_type Msg_text +test.s1 check note The storage engine for the table doesn't support check +rename table s1 to tmp_s; +rename table tmp_s to s1; drop sequence s1; include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info @@ -30,4 +44,14 @@ master-bin.000001 # Query # # COMMIT master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter sequence s1 maxvalue 1000 master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; optimize table s1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; analyze table s1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; repair table s1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; rename table s1 to tmp_s +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; rename table tmp_s to s1 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP SEQUENCE `s1` /* generated by server */ diff --git a/mysql-test/suite/sql_sequence/binlog.test b/mysql-test/suite/sql_sequence/binlog.test index 5f2d52d7864..6a12e670a1e 100644 --- a/mysql-test/suite/sql_sequence/binlog.test +++ b/mysql-test/suite/sql_sequence/binlog.test @@ -1,5 +1,5 @@ ---source include/have_udf.inc ---source include/have_log_bin.inc +--source include/have_sequence.inc +--source include/have_binlog_format_mixed_or_row.inc --source include/binlog_start_pos.inc # @@ -21,6 +21,17 @@ select next value for s1, minimum_value from s1 where maximum_value> 4; # alter sequence s1 maxvalue 1000; +# MDEV-24617 OPTIMIZE on a sequence causes unexpected +# ER_BINLOG_UNSAFE_STATEMENT The test below verifies no unsafe +# warnings anymore for any relavant commands that like OPTIMIZE can +# not produce ROW format events therefore the unsafe warning either. +optimize table s1; +analyze table s1; +repair table s1; +check table s1; +rename table s1 to tmp_s; +rename table tmp_s to s1; + drop sequence s1; --let $binlog_file = LAST diff --git a/sql/sql_class.cc b/sql/sql_class.cc index bbc46408c04..7f5a6345770 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -6210,7 +6210,8 @@ int THD::decide_logging_format(TABLE_LIST *tables) table->file->ht) multi_write_engine= TRUE; if (share->non_determinstic_insert && - !(sql_command_flags[lex->sql_command] & CF_SCHEMA_CHANGE)) + (sql_command_flags[lex->sql_command] & CF_CAN_GENERATE_ROW_EVENTS + && !(sql_command_flags[lex->sql_command] & CF_SCHEMA_CHANGE))) has_write_tables_with_unsafe_statements= true; trans= table->file->has_transactions(); From 1766a18e06a056155031dabefb88ce7f201ad921 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Wed, 2 Mar 2022 21:29:53 +0300 Subject: [PATCH 3/4] MDEV-19577 Replication does not work with innodb_autoinc_lock_mode=2 The first step for deprecating innodb_autoinc_lock_mode(see MDEV-27844) is: - to switch statement binlog format to ROW if binlog format is MIXED and the statement changes autoincremented fields - issue warnings if innodb_autoinc_lock_mode == 2 and binlog format is STATEMENT --- .../r/innodb_autoinc_lock_mode_binlog.result | 33 +++++++++++++++++++ .../t/innodb_autoinc_lock_mode_binlog.opt | 1 + .../t/innodb_autoinc_lock_mode_binlog.test | 21 ++++++++++++ sql/handler.h | 5 +++ sql/sql_class.cc | 9 +++++ sql/sql_lex.cc | 9 ++++- sql/sql_lex.h | 5 +++ storage/innobase/handler/ha_innodb.cc | 8 +++++ storage/innobase/handler/ha_innodb.h | 4 +++ 9 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/binlog/r/innodb_autoinc_lock_mode_binlog.result create mode 100644 mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.opt create mode 100644 mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.test diff --git a/mysql-test/suite/binlog/r/innodb_autoinc_lock_mode_binlog.result b/mysql-test/suite/binlog/r/innodb_autoinc_lock_mode_binlog.result new file mode 100644 index 00000000000..d0132931968 --- /dev/null +++ b/mysql-test/suite/binlog/r/innodb_autoinc_lock_mode_binlog.result @@ -0,0 +1,33 @@ +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +select @@innodb_autoinc_lock_mode; +@@innodb_autoinc_lock_mode +2 +select @@binlog_format; +@@binlog_format +MIXED +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=InnoDB; +insert into t1 values (NULL,1); +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT' COLLATE 'latin1_swedish_ci')) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; create table t1 (a int not null auto_increment,b int, primary key (a)) engine=InnoDB +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Annotate_rows # # insert into t1 values (NULL,1) +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Xid # # COMMIT /* XID */ +set global binlog_format=STATEMENT; +connect con1,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK; +insert into t1 values (NULL,1); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system variable that may have a different value on the slave +insert into t1 values (NULL,1); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system variable that may have a different value on the slave +disconnect con1; +connection default; +set global binlog_format=MIXED; +DROP TABLE t1; diff --git a/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.opt b/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.opt new file mode 100644 index 00000000000..824f656cbd5 --- /dev/null +++ b/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.opt @@ -0,0 +1 @@ +--innodb_autoinc_lock_mode=2 diff --git a/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.test b/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.test new file mode 100644 index 00000000000..a7d43db4c1b --- /dev/null +++ b/mysql-test/suite/binlog/t/innodb_autoinc_lock_mode_binlog.test @@ -0,0 +1,21 @@ +--source include/have_innodb.inc +--source include/have_binlog_format_mixed.inc + +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + +select @@innodb_autoinc_lock_mode; +select @@binlog_format; + +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=InnoDB; +insert into t1 values (NULL,1); +--source include/show_binlog_events.inc + +set global binlog_format=STATEMENT; +--connect (con1,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK) +insert into t1 values (NULL,1); +insert into t1 values (NULL,1); +--disconnect con1 +--connection default + +set global binlog_format=MIXED; +DROP TABLE t1; diff --git a/sql/handler.h b/sql/handler.h index 91225982e9e..c65b7b6a8d5 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -4668,6 +4668,11 @@ public: const uchar *pack_frm_data, size_t pack_frm_len) { return HA_ERR_WRONG_COMMAND; } + /* @return true if it's necessary to switch current statement log format from + STATEMENT to ROW if binary log format is MIXED and autoincrement values + are changed in the statement */ + virtual bool autoinc_lock_mode_stmt_unsafe() const + { return false; } virtual int drop_partitions(const char *path) { return HA_ERR_WRONG_COMMAND; } virtual int rename_partitions(const char *path) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7f5a6345770..c808a2c997c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -6079,6 +6079,10 @@ int THD::decide_logging_format(TABLE_LIST *tables) bool is_write= FALSE; // If any write tables bool has_read_tables= FALSE; // If any read only tables bool has_auto_increment_write_tables= FALSE; // Write with auto-increment + /* true if it's necessary to switch current statement log format from + STATEMENT to ROW if binary log format is MIXED and autoincrement values + are changed in the statement */ + bool has_unsafe_stmt_autoinc_lock_mode= false; /* If a write table that doesn't have auto increment part first */ bool has_write_table_auto_increment_not_first_in_pk= FALSE; bool has_auto_increment_write_tables_not_first= FALSE; @@ -6200,6 +6204,8 @@ int THD::decide_logging_format(TABLE_LIST *tables) has_auto_increment_write_tables_not_first= found_first_not_own_table; if (share->next_number_keypart != 0) has_write_table_auto_increment_not_first_in_pk= true; + has_unsafe_stmt_autoinc_lock_mode= + table->file->autoinc_lock_mode_stmt_unsafe(); } } @@ -6268,6 +6274,9 @@ int THD::decide_logging_format(TABLE_LIST *tables) if (has_write_tables_with_unsafe_statements) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION); + if (has_unsafe_stmt_autoinc_lock_mode) + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_AUTOINC_LOCK_MODE); + /* A query that modifies autoinc column in sub-statement can make the master and slave inconsistent. diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 228635915a0..d51b9bd5a26 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -75,7 +75,14 @@ Query_tables_list::binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT] = ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC, ER_BINLOG_UNSAFE_UPDATE_IGNORE, ER_BINLOG_UNSAFE_INSERT_TWO_KEYS, - ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST + ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST, + /* + There is no need to add new error code as we plan to get rid of auto + increment lock mode variable, so we use existing error code below, add + the correspondent text to the existing error message during merging to + non-GA release. + */ + ER_BINLOG_UNSAFE_SYSTEM_VARIABLE }; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 69dda691e45..e1f34afa350 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1740,6 +1740,11 @@ public: */ BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST, + /** + Autoincrement lock mode is incompatible with STATEMENT binlog format. + */ + BINLOG_STMT_UNSAFE_AUTOINC_LOCK_MODE, + /* The last element of this enumeration type. */ BINLOG_STMT_UNSAFE_COUNT }; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 33aafa00113..02ac53e22dd 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9594,6 +9594,14 @@ ha_innobase::change_active_index( DBUG_RETURN(0); } +/* @return true if it's necessary to switch current statement log format from +STATEMENT to ROW if binary log format is MIXED and autoincrement values +are changed in the statement */ +bool ha_innobase::autoinc_lock_mode_stmt_unsafe() const +{ + return innobase_autoinc_lock_mode == AUTOINC_NO_LOCKING; +} + /***********************************************************************//** Reads the next or previous row from a cursor, which must have previously been positioned using index_read. diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 9468edcf226..9356b269fcc 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -448,6 +448,10 @@ protected: int general_fetch(uchar* buf, uint direction, uint match_mode); int change_active_index(uint keynr); + /* @return true if it's necessary to switch current statement log + format from STATEMENT to ROW if binary log format is MIXED and + autoincrement values are changed in the statement */ + bool autoinc_lock_mode_stmt_unsafe() const; dict_index_t* innobase_get_index(uint keynr); #ifdef WITH_WSREP From 77c184df7c056da7364e606ac977cc2d3cd826ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 10 Mar 2022 15:08:39 +0200 Subject: [PATCH 4/4] Explicitly specify that we use the C99 dialect --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88a0d64e6de..6a135b0f8e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (c) 2006, 2017, Oracle and/or its affiliates. -# Copyright (c) 2008, 2021, MariaDB Corporation. +# Copyright (c) 2008, 2022, MariaDB Corporation. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -83,9 +83,11 @@ SET(MYSQL_PROJECT_NAME_DOCSTRING "MySQL project name") IF(CMAKE_VERSION VERSION_LESS "3.1") IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") ENDIF() ELSE() + SET(CMAKE_C_STANDARD 99) SET(CMAKE_CXX_STANDARD 11) ENDIF()