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..d6e7432deb3 --- /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 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 GLOBAL 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)