[Commits] 1c9da8d: MDEV-9312: storage engine not enforced during galera cluster replication

Nirbhay Choubey nirbhay at mariadb.com
Wed Sep 28 19:36:54 EEST 2016


revision-id: 1c9da8d955977cea080bc81cc63f82a0a012a418 (mariadb-10.1.17-22-g1c9da8d)
parent(s): 6a6b253a6ecbd4d3dd254044d12ec64475453275
author: Nirbhay Choubey
committer: Nirbhay Choubey
timestamp: 2016-09-28 12:36:51 -0400
message:

MDEV-9312: storage engine not enforced during galera cluster replication

Perform a post initialization of plugin-related variables
of wsrep threads after their global counterparts have been
initialized.

---
 .../suite/galera/r/enforce_storage_engine2.result  | 24 ++++++
 .../suite/galera/t/enforce_storage_engine2.opt     |  2 +
 .../suite/galera/t/enforce_storage_engine2.test    | 20 +++++
 sql/mysqld.cc                                      | 15 ++++
 sql/sql_plugin.cc                                  | 86 +++++++++++++++-------
 sql/sql_plugin.h                                   |  7 ++
 sql/wsrep_mysqld.cc                                |  9 ++-
 7 files changed, 137 insertions(+), 26 deletions(-)

diff --git a/mysql-test/suite/galera/r/enforce_storage_engine2.result b/mysql-test/suite/galera/r/enforce_storage_engine2.result
new file mode 100644
index 0000000..053c37d
--- /dev/null
+++ b/mysql-test/suite/galera/r/enforce_storage_engine2.result
@@ -0,0 +1,24 @@
+#
+# MDEV-9312: storage engine not enforced during galera cluster
+# replication
+#
+CREATE TABLE t1(i INT) ENGINE=INNODB;
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+Warnings:
+Note	1266	Using storage engine InnoDB for table 't2'
+SHOW TABLES;
+Tables_in_test
+t1
+t2
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `i` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `i` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1, t2;
+# End of tests
diff --git a/mysql-test/suite/galera/t/enforce_storage_engine2.opt b/mysql-test/suite/galera/t/enforce_storage_engine2.opt
new file mode 100644
index 0000000..03f7dc5
--- /dev/null
+++ b/mysql-test/suite/galera/t/enforce_storage_engine2.opt
@@ -0,0 +1,2 @@
+--enforce_storage_engine=innodb --sql_mode=''
+
diff --git a/mysql-test/suite/galera/t/enforce_storage_engine2.test b/mysql-test/suite/galera/t/enforce_storage_engine2.test
new file mode 100644
index 0000000..7a822bc
--- /dev/null
+++ b/mysql-test/suite/galera/t/enforce_storage_engine2.test
@@ -0,0 +1,20 @@
+--source include/galera_cluster.inc
+--source include/have_innodb.inc
+
+--echo #
+--echo # MDEV-9312: storage engine not enforced during galera cluster
+--echo # replication
+--echo #
+--connection node_1
+CREATE TABLE t1(i INT) ENGINE=INNODB;
+CREATE TABLE t2(i INT) ENGINE=MYISAM;
+
+--connection node_2
+SHOW TABLES;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+# Cleanup
+DROP TABLE t1, t2;
+
+--echo # End of tests
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index a71d6d1..5bc31be 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5075,6 +5075,12 @@ static int init_server_components()
   }
 
   /*
+    Since some wsrep threads (THDs) are create before plugins are
+    initialized, LOCK_plugin mutex needs to be initialized here.
+  */
+  plugin_mutex_init();
+
+  /*
     Wsrep initialization must happen at this point, because:
     - opt_bin_logname must be known when starting replication
       since SST may need it
@@ -5302,6 +5308,15 @@ static int init_server_components()
 #endif
 
 #ifdef WITH_WSREP
+  /*
+    Now is the right time to initialize members of wsrep startup threads
+    that rely on plugins and other related global system variables to be
+    initialized. This initialization was not possible before, as plugins
+    (and thus some global system variables) are initialized after wsrep
+    startup threads are created.
+  */
+  wsrep_plugins_post_init();
+
   if (WSREP_ON && !opt_bin_log)
   {
     wsrep_emulate_bin_log= 1;
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 60248f3..7b0dd70 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1548,9 +1548,6 @@ int plugin_init(int *argc, char **argv, int flags)
                    get_bookmark_hash_key, NULL, HASH_UNIQUE))
       goto err;
 
-
-  mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST);
-
   if (my_init_dynamic_array(&plugin_dl_array,
                             sizeof(struct st_plugin_dl *), 16, 16, MYF(0)) ||
       my_init_dynamic_array(&plugin_array,
@@ -3116,28 +3113,19 @@ void plugin_thdvar_init(THD *thd)
   thd->variables.dynamic_variables_size= 0;
   thd->variables.dynamic_variables_ptr= 0;
 
-  if (IF_WSREP((!WSREP(thd) || !thd->wsrep_applier),1))
-  {
-    mysql_mutex_lock(&LOCK_plugin);
-    thd->variables.table_plugin=
-        intern_plugin_lock(NULL, global_system_variables.table_plugin);
-    if (global_system_variables.tmp_table_plugin)
-      thd->variables.tmp_table_plugin=
-            intern_plugin_lock(NULL, global_system_variables.tmp_table_plugin);
-    if (global_system_variables.enforced_table_plugin)
-      thd->variables.enforced_table_plugin=
-            intern_plugin_lock(NULL, global_system_variables.enforced_table_plugin);
-    intern_plugin_unlock(NULL, old_table_plugin);
-    intern_plugin_unlock(NULL, old_tmp_table_plugin);
-    intern_plugin_unlock(NULL, old_enforced_table_plugin);
-    mysql_mutex_unlock(&LOCK_plugin);
-  }
-  else
-  {
-    thd->variables.table_plugin= NULL;
-    thd->variables.tmp_table_plugin= NULL;
-    thd->variables.enforced_table_plugin= NULL;
-  }
+  mysql_mutex_lock(&LOCK_plugin);
+  thd->variables.table_plugin=
+      intern_plugin_lock(NULL, global_system_variables.table_plugin);
+  if (global_system_variables.tmp_table_plugin)
+    thd->variables.tmp_table_plugin=
+          intern_plugin_lock(NULL, global_system_variables.tmp_table_plugin);
+  if (global_system_variables.enforced_table_plugin)
+    thd->variables.enforced_table_plugin=
+          intern_plugin_lock(NULL, global_system_variables.enforced_table_plugin);
+  intern_plugin_unlock(NULL, old_table_plugin);
+  intern_plugin_unlock(NULL, old_tmp_table_plugin);
+  intern_plugin_unlock(NULL, old_enforced_table_plugin);
+  mysql_mutex_unlock(&LOCK_plugin);
 
   DBUG_VOID_RETURN;
 }
@@ -4261,3 +4249,51 @@ int thd_setspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key, void *value)
   return 0;
 }
 
+void plugin_mutex_init()
+{
+  mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST);
+}
+
+#ifdef WITH_WSREP
+
+/*
+  Placeholder for global_system_variables.table_plugin required during
+  initialization of startup wsrep threads.
+*/
+static st_plugin_int wsrep_dummy_plugin;
+static st_plugin_int *wsrep_dummy_plugin_ptr;
+
+/*
+  Initialize wsrep_dummy_plugin and assign it to
+  global_system_variables.table_plugin.
+*/
+void wsrep_plugins_pre_init()
+{
+  wsrep_dummy_plugin_ptr= &wsrep_dummy_plugin;
+  wsrep_dummy_plugin.state= PLUGIN_IS_DISABLED;
+  global_system_variables.table_plugin=
+    plugin_int_to_ref(wsrep_dummy_plugin_ptr);
+}
+
+/*
+  This function is intended to be called after the plugins and related
+  global system variables are initialized. It re-initializes some data
+  members of wsrep startup threads with correct values, as these value
+  were not available at the time these threads were created.
+*/
+void wsrep_plugins_post_init()
+{
+  THD *thd;
+  I_List_iterator<THD> it(threads);
+
+  while ((thd= it++))
+  {
+    if (IF_WSREP(thd->wsrep_applier,1))
+    {
+      plugin_thdvar_init(thd);
+    }
+  }
+
+  return;
+}
+#endif /* WITH_WSREP */
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index 77ec24b..d11c449 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -180,6 +180,7 @@ extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
 void plugin_opt_set_limits(struct my_option *, const struct st_mysql_sys_var *);
 extern SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type);
 extern bool check_valid_path(const char *path, size_t length);
+extern void plugin_mutex_init();
 
 typedef my_bool (plugin_foreach_func)(THD *thd,
                                       plugin_ref plugin,
@@ -194,3 +195,9 @@ extern bool plugin_dl_foreach(THD *thd, const LEX_STRING *dl,
 
 extern void sync_dynamic_session_variables(THD* thd, bool global_lock);
 #endif
+
+#ifdef WITH_WSREP
+extern void wsrep_plugins_pre_init();
+extern void wsrep_plugins_post_init();
+#endif /* WITH_WSREP */
+
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index 776bf4a..5f25ea1 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -36,6 +36,7 @@
 #include <cstdlib>
 #include "log_event.h"
 #include <slave.h>
+#include "sql_plugin.h"                         /* wsrep_plugins_pre_init() */
 
 wsrep_t *wsrep                  = NULL;
 /*
@@ -771,7 +772,6 @@ void wsrep_thr_init()
   mysql_mutex_init(key_LOCK_wsrep_config_state, &LOCK_wsrep_config_state, MY_MUTEX_INIT_FAST);
 }
 
-
 void wsrep_init_startup (bool first)
 {
   if (wsrep_init()) unireg_abort(1);
@@ -782,6 +782,13 @@ void wsrep_init_startup (bool first)
      wsrep_debug, wsrep_convert_LOCK_to_trx,
      (wsrep_on_fun)wsrep_on);
 
+  /*
+    Pre-initialize global_system_variables.table_plugin with a dummy engine
+    (placeholder) required during the initialization of wsrep threads (THDs).
+    (see: plugin_thdvar_init())
+  */
+  wsrep_plugins_pre_init();
+
   /* Skip replication start if dummy wsrep provider is loaded */
   if (!strcmp(wsrep_provider, WSREP_NONE)) return;
 


More information about the commits mailing list