From c283319c057e8627487a2070a52f30a093a51032 Mon Sep 17 00:00:00 2001 From: Raghavendra D Prabhu Date: Thu, 2 Jul 2015 21:51:22 +0530 Subject: [PATCH 1/2] Bug#1421360: Add 'FLUSH * LOGS' except BINARY LOG and FLUSH LOGS, also move FLUSH TABLES. With this commit, a) FLUSH * LOGS have been added to TOI as well. The commands being: FLUSH ERROR LOGS; FLUSH SLOW LOGS; FLUSH GENERAL LOGS; FLUSH ENGINE LOGS; FLUSH RELAY LOGS; b) FLUSH LOGS and FLUSH BINARY LOGS are not replicated. Former is not done because it enables BINARY LOGS too. Tests have been added for them. In addition, another test has been added which runs the same through binlogging and gtid enabled. Finally, REFRESH_TABLES logic from previous commit has been moved to reload_acl_and_cache to just before close_cached_tables. This is required because: a) TOI for REFRESH_TABLES needs to be done before the command to be executed, in this case in close_cached_tables. b) Also, since LOCK TABLE WRITE is not replicated, it needs to be done after the check of thd->locked_tables_mode as described in earlier commit. Also, a comment about 'thread holds MDL locks at TI' appearing in the logs has been added to indicate that it is benign for this context. Conflicts: sql/sql_reload.cc --- mysql-test/suite/galera/r/galera_flush.result | 16 +++++ .../suite/galera/r/galera_flush_gtid.result | 70 +++++++++++++++++++ mysql-test/suite/galera/t/galera_flush.test | 55 ++++++++++++++- .../galera/t/galera_flush_gtid-master.opt | 1 + .../suite/galera/t/galera_flush_gtid.test | 9 +++ sql/sql_parse.cc | 32 ++++----- sql/sql_reload.cc | 35 ++++++++++ 7 files changed, 198 insertions(+), 20 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_flush_gtid.result create mode 100644 mysql-test/suite/galera/t/galera_flush_gtid-master.opt create mode 100644 mysql-test/suite/galera/t/galera_flush_gtid.test diff --git a/mysql-test/suite/galera/r/galera_flush.result b/mysql-test/suite/galera/r/galera_flush.result index 2fb57c079db..d6e7432deb3 100644 --- a/mysql-test/suite/galera/r/galera_flush.result +++ b/mysql-test/suite/galera/r/galera_flush.result @@ -26,8 +26,24 @@ CREATE TABLE t2 (f1 INTEGER); FLUSH TABLES t2; wsrep_last_committed_diff 1 +FLUSH ERROR LOGS; +wsrep_last_committed_diff +1 +FLUSH SLOW LOGS; +wsrep_last_committed_diff +1 +FLUSH GENERAL LOGS; +wsrep_last_committed_diff +1 +FLUSH ENGINE LOGS; +wsrep_last_committed_diff +1 +FLUSH RELAY LOGS; +wsrep_last_committed_diff +1 CREATE TABLE t1 (f1 INTEGER); FLUSH LOGS; +FLUSH BINARY LOGS; FLUSH TABLES WITH READ LOCK; UNLOCK TABLES; FLUSH TABLES t1 WITH READ LOCK; diff --git a/mysql-test/suite/galera/r/galera_flush_gtid.result b/mysql-test/suite/galera/r/galera_flush_gtid.result new file mode 100644 index 00000000000..53d673048ec --- /dev/null +++ b/mysql-test/suite/galera/r/galera_flush_gtid.result @@ -0,0 +1,70 @@ +FLUSH DES_KEY_FILE; +wsrep_last_committed_diff +1 +FLUSH HOSTS; +wsrep_last_committed_diff +1 +SET SESSION wsrep_replicate_myisam = TRUE; +INSERT INTO mysql.user VALUES('localhost','user1',PASSWORD('pass1'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N'); +FLUSH PRIVILEGES; +DELETE FROM mysql.user WHERE user = 'user1'; +SET SESSION wsrep_replicate_myisam = FALSE; +FLUSH PRIVILEGES; +FLUSH QUERY CACHE; +wsrep_last_committed_diff +1 +FLUSH STATUS; +wsrep_last_committed_diff +1 +FLUSH USER_RESOURCES; +wsrep_last_committed_diff +1 +FLUSH TABLES; +wsrep_last_committed_diff +1 +CREATE TABLE t2 (f1 INTEGER); +FLUSH TABLES t2; +wsrep_last_committed_diff +1 +FLUSH ERROR LOGS; +wsrep_last_committed_diff +1 +FLUSH SLOW LOGS; +wsrep_last_committed_diff +1 +FLUSH GENERAL LOGS; +wsrep_last_committed_diff +1 +FLUSH ENGINE LOGS; +wsrep_last_committed_diff +1 +FLUSH RELAY LOGS; +wsrep_last_committed_diff +1 +CREATE TABLE t1 (f1 INTEGER); +FLUSH LOGS; +FLUSH BINARY LOGS; +FLUSH TABLES WITH READ LOCK; +UNLOCK TABLES; +FLUSH TABLES t1 WITH READ LOCK; +UNLOCK TABLES; +FLUSH TABLES t1 FOR EXPORT; +UNLOCK TABLES; +wsrep_last_committed_diff +1 +LOCK TABLES t1 WRITE; +FLUSH TABLES t1; +UNLOCK TABLES; +wsrep_last_committed_diff +1 +LOCK TABLES t1 READ; +FLUSH TABLES t1; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +UNLOCK TABLES; +wsrep_last_committed_diff +1 +FLUSH TABLES t1; +wsrep_last_committed_diff +1 +DROP TABLE t1; +DROP TABLE t2; diff --git a/mysql-test/suite/galera/t/galera_flush.test b/mysql-test/suite/galera/t/galera_flush.test index f3a542599d1..bb3ce54a78b 100644 --- a/mysql-test/suite/galera/t/galera_flush.test +++ b/mysql-test/suite/galera/t/galera_flush.test @@ -101,8 +101,60 @@ FLUSH TABLES t2; --enable_query_log +--connection node_2 +--let $wsrep_last_committed_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +FLUSH ERROR LOGS; +--connection node_2 +--let $wsrep_last_committed_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before + 1 AS wsrep_last_committed_diff; +--enable_query_log + + +--connection node_2 +--let $wsrep_last_committed_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +FLUSH SLOW LOGS; +--connection node_2 +--let $wsrep_last_committed_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before + 1 AS wsrep_last_committed_diff; +--enable_query_log + +--connection node_2 +--let $wsrep_last_committed_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +FLUSH GENERAL LOGS; +--connection node_2 +--let $wsrep_last_committed_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before + 1 AS wsrep_last_committed_diff; +--enable_query_log + +--connection node_2 +--let $wsrep_last_committed_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +FLUSH ENGINE LOGS; +--connection node_2 +--let $wsrep_last_committed_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before + 1 AS wsrep_last_committed_diff; +--enable_query_log + +--connection node_2 +--let $wsrep_last_committed_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +FLUSH RELAY LOGS; +--connection node_2 +--let $wsrep_last_committed_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before + 1 AS wsrep_last_committed_diff; +--enable_query_log + + # -# The following statements should not be replicated: FLUSH LOGS, FLUSH TABLES WITH LOCKS +# The following statements should not be replicated: FLUSH LOGS, FLUSH BINARY LOGS, FLUSH TABLES WITH LOCKS. # @@ -114,6 +166,7 @@ CREATE TABLE t1 (f1 INTEGER); --connection node_1 FLUSH LOGS; +FLUSH BINARY LOGS; FLUSH TABLES WITH READ LOCK; UNLOCK TABLES; FLUSH TABLES t1 WITH READ LOCK; diff --git a/mysql-test/suite/galera/t/galera_flush_gtid-master.opt b/mysql-test/suite/galera/t/galera_flush_gtid-master.opt new file mode 100644 index 00000000000..cfe3725a00e --- /dev/null +++ b/mysql-test/suite/galera/t/galera_flush_gtid-master.opt @@ -0,0 +1 @@ +--query_cache_type=1 --query_cache_size=1000000 --gtid-mode=ON --log-bin --log-slave-updates --enforce-gtid-consistency diff --git a/mysql-test/suite/galera/t/galera_flush_gtid.test b/mysql-test/suite/galera/t/galera_flush_gtid.test new file mode 100644 index 00000000000..ba091d59b80 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_flush_gtid.test @@ -0,0 +1,9 @@ +# +# Test that various FLUSH commands are replicated. +# This is similar to galera_flush.test except +# with gtid and binlogging enabled. +# + +--source include/have_log_bin.inc +--source suite/galera/t/galera_flush.test + diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 5588c38ea25..348e184d051 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4581,7 +4581,20 @@ case SQLCOM_PREPARE: if (lex->type & ( REFRESH_GRANT | REFRESH_HOSTS | +#ifdef HAVE_OPENSSL REFRESH_DES_KEY_FILE | +#endif + /* + * Write all flush log statements except + * FLUSH LOGS + * FLUSH BINARY LOGS + * Check reload_acl_and_cache for why. + */ + REFRESH_RELAY_LOG | + REFRESH_SLOW_LOG | + REFRESH_GENERAL_LOG | + REFRESH_ENGINE_LOG | + REFRESH_ERROR_LOG | #ifdef HAVE_QUERY_CACHE REFRESH_QUERY_CACHE_FREE | #endif /* HAVE_QUERY_CACHE */ @@ -4598,25 +4611,6 @@ case SQLCOM_PREPARE: */ if (!reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog)) { -#ifdef WITH_WSREP - if ((lex->type & REFRESH_TABLES) && !(lex->type & (REFRESH_FOR_EXPORT|REFRESH_READ_LOCK))) - { - /* - This is done after reload_acl_and_cache is because - LOCK TABLES is not replicated in galera, the upgrade of which - is checked in reload_acl_and_cache. - Hence, done after/if we are able to upgrade locks. - */ - if (first_table) - { - WSREP_TO_ISOLATION_BEGIN(NULL, NULL, first_table); - } - else - { - WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL); - } - } -#endif /* WITH_WSREP */ /* We WANT to write and we CAN write. ! we write after unlocking the table. diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index 60ab4761756..19426ec76dd 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -29,6 +29,9 @@ #include "rpl_mi.h" #include "debug_sync.h" +#ifdef WITH_WSREP +#include "sql_parse.h" +#endif /* WITH_WSREP */ /** Reload/resets privileges and the different caches. @@ -303,6 +306,35 @@ bool reload_acl_and_cache(THD *thd, unsigned long options, } } } +#ifdef WITH_WSREP + if (WSREP(thd) && (options & REFRESH_TABLES) && + !(options & (REFRESH_FOR_EXPORT|REFRESH_READ_LOCK))) + { + /* + This is done here because LOCK TABLES is not replicated in galera, + the upgrade of which is checked above. Hence, done after/if we + are able to upgrade locks. + + Also, note that, in error log with debug you may see + 'thread holds MDL locks at TI' but since this is a flush + tables and is required for LOCK TABLE WRITE + it can be ignored there. + */ + if (tables) + { + if (wsrep_to_isolation_begin(thd, NULL, NULL, tables)) + { + result= 1; + goto cleanup; + } + } + else if (wsrep_to_isolation_begin(thd, WSREP_MYSQL_DB, NULL, NULL)) + { + result= 1; + goto cleanup; + } + } +#endif /* WITH_WSREP */ if (close_cached_tables(thd, tables, ((options & REFRESH_FAST) ? FALSE : TRUE), @@ -316,6 +348,9 @@ bool reload_acl_and_cache(THD *thd, unsigned long options, result= 1; } } +#ifdef WITH_WSREP +cleanup: +#endif /* WITH_WSREP */ my_dbopt_cleanup(); } if (options & REFRESH_HOSTS) From 9ad15a33732498a0092ffc1bd36925c338890810 Mon Sep 17 00:00:00 2001 From: Philip Stoev Date: Fri, 3 Jul 2015 02:07:51 -0700 Subject: [PATCH 2/2] Adjust galera_flush_gtid.result to use SET GLOBAL wsrep_replicate_myisam. --- mysql-test/suite/galera/r/galera_flush_gtid.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_flush_gtid.result b/mysql-test/suite/galera/r/galera_flush_gtid.result index 53d673048ec..d6e7432deb3 100644 --- a/mysql-test/suite/galera/r/galera_flush_gtid.result +++ b/mysql-test/suite/galera/r/galera_flush_gtid.result @@ -4,11 +4,11 @@ wsrep_last_committed_diff FLUSH HOSTS; wsrep_last_committed_diff 1 -SET SESSION wsrep_replicate_myisam = TRUE; +SET GLOBAL wsrep_replicate_myisam = TRUE; INSERT INTO mysql.user VALUES('localhost','user1',PASSWORD('pass1'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N'); FLUSH PRIVILEGES; DELETE FROM mysql.user WHERE user = 'user1'; -SET SESSION wsrep_replicate_myisam = FALSE; +SET GLOBAL wsrep_replicate_myisam = FALSE; FLUSH PRIVILEGES; FLUSH QUERY CACHE; wsrep_last_committed_diff