From 0d7d39071119d510ca1dbc8677cc2baea1d34ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 14 Jan 2025 14:29:29 +0200 Subject: [PATCH] MDEV-35748 : Attempting to create a CONNECT engine Table results in non-InnoDB sequences in Galera cluster error Problem was incorrect condition on wsrep_check_sequence when ENGINE!=InnoDB. Fix is not use DB_TYPE_XXX because it is not correct on dynamic storage engines. Instead used storage engine name is looked from thd->lex->m_sql_cmd->option_storage_engine_name. For CREATE TABLE allow anyting except ENGINE=SEQUENCE. For CREATE SEQUENCE only ENGINE=InnoDB is supported. For ALTER TABLE if original table contains sequence information only ENGINE=InnoDB is supported. --- mysql-test/suite/galera/r/MDEV-35748.result | 31 +++++++++++++++++++++ mysql-test/suite/galera/t/MDEV-35748.test | 23 +++++++++++++++ sql/sql_cmd.h | 2 ++ sql/sql_table.cc | 23 +++++++++++++-- 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/galera/r/MDEV-35748.result create mode 100644 mysql-test/suite/galera/t/MDEV-35748.test diff --git a/mysql-test/suite/galera/r/MDEV-35748.result b/mysql-test/suite/galera/r/MDEV-35748.result new file mode 100644 index 0000000000000..fca2ab3ad40f7 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-35748.result @@ -0,0 +1,31 @@ +connection node_2; +connection node_1; +connection node_1; +INSTALL PLUGIN IF NOT EXISTS connect SONAME 'ha_connect'; +CREATE TABLE t1 (f INT) ENGINE=CONNECT; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos +CREATE TABLE t2 (f INT) ENGINE=ROCKSDB; +CREATE TABLE t3 (f INT) ENGINE=SEQUENCE; +ERROR 42000: This version of MariaDB doesn't yet support 'non-InnoDB sequences in Galera cluster' +show warnings; +Level Code Message +Error 1235 This version of MariaDB doesn't yet support 'non-InnoDB sequences in Galera cluster' +Note 1235 ENGINE=SEQUENCE not supported by Galera +connection node_2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f` int(11) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` int(11) DEFAULT NULL +) ENGINE=ROCKSDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +show create table t3; +ERROR 42S02: Table 'test.t3' doesn't exist +connection node_1; +DROP TABLE t1, t2; +UNINSTALL PLUGIN IF EXISTS connect; diff --git a/mysql-test/suite/galera/t/MDEV-35748.test b/mysql-test/suite/galera/t/MDEV-35748.test new file mode 100644 index 0000000000000..db9df9996a069 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-35748.test @@ -0,0 +1,23 @@ +--source include/galera_cluster.inc +--source include/have_sequence.inc +--source include/have_rocksdb.inc + +--connection node_1 +INSTALL PLUGIN IF NOT EXISTS connect SONAME 'ha_connect'; + +CREATE TABLE t1 (f INT) ENGINE=CONNECT; +CREATE TABLE t2 (f INT) ENGINE=ROCKSDB; +--error ER_NOT_SUPPORTED_YET +CREATE TABLE t3 (f INT) ENGINE=SEQUENCE; +show warnings; + +--connection node_2 +show create table t1; +show create table t2; +--error ER_NO_SUCH_TABLE +show create table t3; + +--connection node_1 +DROP TABLE t1, t2; +UNINSTALL PLUGIN IF EXISTS connect; + diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h index ea51837522657..b361f559794be 100644 --- a/sql/sql_cmd.h +++ b/sql/sql_cmd.h @@ -141,6 +141,8 @@ class Storage_engine_name handlerton **ha, bool tmp_table); bool is_set() { return m_storage_engine_name.str != NULL; } + + const LEX_CSTRING *name() const { return &m_storage_engine_name; } }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 4580f7ae9829f..5094084adf9e6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4695,9 +4695,26 @@ bool wsrep_check_sequence(THD* thd, // In Galera cluster we support only InnoDB sequences if (db_type != DB_TYPE_INNODB) { - my_error(ER_NOT_SUPPORTED_YET, MYF(0), - "non-InnoDB sequences in Galera cluster"); - return(true); + // Currently any dynamic storage engine is not possible to identify + // using DB_TYPE_XXXX and ENGINE=SEQUENCE is one of them. + // Therefore, we get storage engine name from lex. + const LEX_CSTRING *tb_name= thd->lex->m_sql_cmd->option_storage_engine_name()->name(); + // (1) CREATE TABLE ... ENGINE=SEQUENCE OR + // (2) ALTER TABLE ... ENGINE= OR + // Note in ALTER TABLE table->s->sequence != nullptr + // (3) CREATE SEQUENCE ... ENGINE= + if ((thd->lex->sql_command == SQLCOM_CREATE_TABLE && + lex_string_eq(tb_name, STRING_WITH_LEN("SEQUENCE"))) || + (thd->lex->sql_command == SQLCOM_ALTER_TABLE) || + (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE)) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "non-InnoDB sequences in Galera cluster"); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_NOT_SUPPORTED_YET, + "ENGINE=%s not supported by Galera", tb_name->str); + return(true); + } } // In Galera cluster it is best to use INCREMENT BY 0 with CACHE