← Back to team overview

maria-developers team mailing list archive

MDEV-8831: review request

 

Hi Jan,

Could you please review the attached patch?

Thanks,
Nirbhay
From f9bf5f50593a181effb0cde9d18c1f0fd5c662ff Mon Sep 17 00:00:00 2001
From: Nirbhay Choubey <nirbhay@xxxxxxxxxxx>
Date: Wed, 30 Sep 2015 21:56:50 -0400
Subject: [PATCH] MDEV-8831 : enforce_storage_engine doesn't block table
 creation on other nodes

Check if the engine is supported/allowed before replicating the
statement.
---
 .../suite/galera/r/enforce_storage_engine.result   | 22 +++++++++++++++
 .../suite/galera/t/enforce_storage_engine.test     | 33 ++++++++++++++++++++++
 sql/sql_parse.cc                                   | 13 ++++++---
 sql/sql_table.cc                                   |  5 ++--
 sql/sql_table.h                                    |  2 ++
 5 files changed, 68 insertions(+), 7 deletions(-)
 create mode 100644 mysql-test/suite/galera/r/enforce_storage_engine.result
 create mode 100644 mysql-test/suite/galera/t/enforce_storage_engine.test

diff --git a/mysql-test/suite/galera/r/enforce_storage_engine.result b/mysql-test/suite/galera/r/enforce_storage_engine.result
new file mode 100644
index 0000000..a3513fc
--- /dev/null
+++ b/mysql-test/suite/galera/r/enforce_storage_engine.result
@@ -0,0 +1,22 @@
+#
+# MDEV-8831 : enforce_storage_engine doesn't block table creation on
+# other nodes (galera cluster)
+#
+SET @@enforce_storage_engine=INNODB;
+CREATE TABLE t1(i INT) ENGINE=INNODB;
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+ERROR 42000: Unknown storage engine 'MyISAM'
+INSERT INTO t1 VALUES(1);
+SHOW TABLES;
+Tables_in_test
+t1
+SELECT COUNT(*)=1 FROM t1;
+COUNT(*)=1
+1
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+SHOW TABLES;
+Tables_in_test
+t1
+t2
+DROP TABLE t1, t2;
+# End of tests
diff --git a/mysql-test/suite/galera/t/enforce_storage_engine.test b/mysql-test/suite/galera/t/enforce_storage_engine.test
new file mode 100644
index 0000000..5f07dd5
--- /dev/null
+++ b/mysql-test/suite/galera/t/enforce_storage_engine.test
@@ -0,0 +1,33 @@
+--source include/galera_cluster.inc
+--source include/have_innodb.inc
+
+# enforce_storage_engine should prevent the creation of tables with
+# non-enforced storage engines on the master node and the command
+# should also not replicate to other nodes.
+
+--echo #
+--echo # MDEV-8831 : enforce_storage_engine doesn't block table creation on
+--echo # other nodes (galera cluster)
+--echo #
+
+--connection node_1
+SET @@enforce_storage_engine=INNODB;
+CREATE TABLE t1(i INT) ENGINE=INNODB;
+--error ER_UNKNOWN_STORAGE_ENGINE
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+
+INSERT INTO t1 VALUES(1);
+
+--connection node_2
+SHOW TABLES;
+SELECT COUNT(*)=1 FROM t1;
+
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+
+--connection node_1
+SHOW TABLES;
+
+# Cleanup
+DROP TABLE t1, t2;
+
+--echo # End of tests
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 2141e68..9c6f7c0 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3440,11 +3440,16 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
       }
       else
       {
-        /* in STATEMENT format, we probably have to replicate also temporary
-           tables, like mysql replication does
+        /*
+          In STATEMENT format, we probably have to replicate also temporary
+          tables, like mysql replication does. Also check if the requested
+          engine is allowed/supported.
         */
-        if (WSREP(thd) && (!thd->is_current_stmt_binlog_format_row() ||
-            !create_info.tmp_table()))
+        if (WSREP(thd) &&
+            !check_engine(thd, create_table->db, create_table->table_name,
+                          &create_info) &&
+            (!thd->is_current_stmt_binlog_format_row() ||
+             !create_info.tmp_table()))
         {
 	  WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name, NULL)
         }
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index d3a7253..b05bdc9 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -72,7 +72,6 @@ static int copy_data_between_tables(THD *thd, TABLE *from,TABLE *to,
                                     Alter_table_ctx *alter_ctx);
 
 static bool prepare_blob_field(THD *thd, Create_field *sql_field);
-static bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *);
 static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
                                       uint *, handler *, KEY **, uint *, int);
 static uint blob_length_by_type(enum_field_types type);
@@ -9816,8 +9815,8 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
   @retval true  Engine not available/supported, error has been reported.
   @retval false Engine available/supported.
 */
-static bool check_engine(THD *thd, const char *db_name,
-                         const char *table_name, HA_CREATE_INFO *create_info)
+bool check_engine(THD *thd, const char *db_name,
+                  const char *table_name, HA_CREATE_INFO *create_info)
 {
   DBUG_ENTER("check_engine");
   handlerton **new_engine= &create_info->db_type;
diff --git a/sql/sql_table.h b/sql/sql_table.h
index 85a3393..a812417 100644
--- a/sql/sql_table.h
+++ b/sql/sql_table.h
@@ -284,4 +284,6 @@ uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
 extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
 extern mysql_mutex_t LOCK_gdl;
 
+bool check_engine(THD *, const char *, const char *, HA_CREATE_INFO *);
+
 #endif /* SQL_TABLE_INCLUDED */
-- 
1.9.1