diff --git a/mysql-test/suite/galera/r/galera_flush_local.result b/mysql-test/suite/galera/r/galera_flush_local.result new file mode 100644 index 00000000000..f740b0a7f65 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_flush_local.result @@ -0,0 +1,151 @@ +DROP TABLE IF EXISTS t1, t2, x1, x2; +CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER); +SET SESSION wsrep_replicate_myisam = TRUE; +CREATE TABLE x1 (f1 INTEGER) ENGINE=MyISAM; +CREATE TABLE x2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO x1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO t2 (f2) SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4; +INSERT INTO x2 (f2) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +FLUSH LOCAL DES_KEY_FILE; +FLUSH LOCAL HOSTS; +FLUSH LOCAL QUERY CACHE; +FLUSH LOCAL STATUS; +FLUSH LOCAL PRIVILEGES; +FLUSH LOCAL USER_RESOURCES; +FLUSH LOCAL TABLES; +FLUSH LOCAL TABLES t2; +FLUSH LOCAL ERROR LOGS; +FLUSH LOCAL SLOW LOGS; +FLUSH LOCAL GENERAL LOGS; +FLUSH LOCAL ENGINE LOGS; +FLUSH LOCAL RELAY LOGS; +FLUSH LOCAL CLIENT_STATISTICS; +FLUSH LOCAL INDEX_STATISTICS; +FLUSH LOCAL TABLE_STATISTICS; +FLUSH LOCAL USER_STATISTICS; +FLUSH LOCAL THREAD_STATISTICS; +FLUSH LOCAL CHANGED_PAGE_BITMAPS; +FLUSH LOCAL LOGS; +FLUSH LOCAL BINARY LOGS; +FLUSH LOCAL TABLES WITH READ LOCK; +UNLOCK TABLES; +FLUSH LOCAL TABLES t1 WITH READ LOCK; +UNLOCK TABLES; +FLUSH LOCAL TABLES t1 FOR EXPORT; +UNLOCK TABLES; +LOCK TABLES t1 WRITE; +FLUSH LOCAL TABLES t1; +UNLOCK TABLES; +LOCK TABLES t1 READ; +FLUSH LOCAL TABLES t1; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +UNLOCK TABLES; +FLUSH LOCAL TABLES t1; +ANALYZE LOCAL TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +OPTIMIZE LOCAL TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 optimize note Table does not support optimize, doing recreate + analyze instead +test.t1 optimize status OK +test.t2 optimize note Table does not support optimize, doing recreate + analyze instead +test.t2 optimize status OK +REPAIR LOCAL TABLE x1, x2; +Table Op Msg_type Msg_text +test.x1 repair status OK +test.x2 repair status OK +wsrep_last_committed_diff +1 +SELECT COUNT(*) = 10 FROM t1; +COUNT(*) = 10 +1 +SELECT COUNT(*) = 10 FROM x1; +COUNT(*) = 10 +1 +SELECT COUNT(*) = 10000 FROM t2; +COUNT(*) = 10000 +1 +SELECT COUNT(*) = 10 FROM x2; +COUNT(*) = 10 +1 +DROP TABLE t1, t2, x1, x2; +CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER); +SET SESSION wsrep_replicate_myisam = TRUE; +CREATE TABLE x1 (f1 INTEGER) ENGINE=MyISAM; +CREATE TABLE x2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO x1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO t2 (f2) SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4; +INSERT INTO x2 (f2) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +set wsrep_on=0; +FLUSH DES_KEY_FILE; +FLUSH HOSTS; +FLUSH QUERY CACHE; +FLUSH STATUS; +FLUSH PRIVILEGES; +FLUSH USER_RESOURCES; +FLUSH TABLES; +FLUSH TABLES t2; +FLUSH ERROR LOGS; +FLUSH SLOW LOGS; +FLUSH GENERAL LOGS; +FLUSH ENGINE LOGS; +FLUSH RELAY LOGS; +FLUSH CLIENT_STATISTICS; +FLUSH INDEX_STATISTICS; +FLUSH TABLE_STATISTICS; +FLUSH USER_STATISTICS; +FLUSH THREAD_STATISTICS; +FLUSH CHANGED_PAGE_BITMAPS; +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; +LOCK TABLES t1 WRITE; +FLUSH TABLES t1; +UNLOCK TABLES; +LOCK TABLES t1 READ; +FLUSH TABLES t1; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +UNLOCK TABLES; +FLUSH TABLES t1; +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +OPTIMIZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 optimize note Table does not support optimize, doing recreate + analyze instead +test.t1 optimize status OK +test.t2 optimize note Table does not support optimize, doing recreate + analyze instead +test.t2 optimize status OK +REPAIR TABLE x1, x2; +Table Op Msg_type Msg_text +test.x1 repair status OK +test.x2 repair status OK +wsrep_last_committed_diff +1 +wsrep_last_committed_diff2 +1 +SELECT COUNT(*) = 10 FROM t1; +COUNT(*) = 10 +1 +SELECT COUNT(*) = 10 FROM x1; +COUNT(*) = 10 +1 +SELECT COUNT(*) = 10000 FROM t2; +COUNT(*) = 10000 +1 +SELECT COUNT(*) = 10 FROM x2; +COUNT(*) = 10 +1 +set wsrep_on=1; +DROP TABLE t1, t2, x1, x2; diff --git a/mysql-test/suite/galera/t/galera_flush_local.opt b/mysql-test/suite/galera/t/galera_flush_local.opt new file mode 100644 index 00000000000..698bbefe41f --- /dev/null +++ b/mysql-test/suite/galera/t/galera_flush_local.opt @@ -0,0 +1 @@ +--query_cache_type=1 --query_cache_size=1000000 --innodb_track_changed_pages=1 --userstat=1 --thread_statistics=1 diff --git a/mysql-test/suite/galera/t/galera_flush_local.test b/mysql-test/suite/galera/t/galera_flush_local.test new file mode 100644 index 00000000000..8f578c78e54 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_flush_local.test @@ -0,0 +1,148 @@ +# +# Test that various FLUSH LOCAL commands are replicated. Whenever possible, check the slave for the effects. +# PXC-391 + +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_query_cache.inc + +--disable_warnings +DROP TABLE IF EXISTS t1, t2, x1, x2; +--enable_warnings +# +# The following FLUSH LOCAL statements should *not* be replicated +# +--connection node_1 +CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER); +SET SESSION wsrep_replicate_myisam = TRUE; +CREATE TABLE x1 (f1 INTEGER) ENGINE=MyISAM; +CREATE TABLE x2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO x1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO t2 (f2) SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4; +INSERT INTO x2 (f2) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); + +--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 LOCAL DES_KEY_FILE; +FLUSH LOCAL HOSTS; +FLUSH LOCAL QUERY CACHE; +FLUSH LOCAL STATUS; +FLUSH LOCAL PRIVILEGES; +FLUSH LOCAL USER_RESOURCES; +FLUSH LOCAL TABLES; +FLUSH LOCAL TABLES t2; +FLUSH LOCAL ERROR LOGS; +FLUSH LOCAL SLOW LOGS; +FLUSH LOCAL GENERAL LOGS; +FLUSH LOCAL ENGINE LOGS; +FLUSH LOCAL RELAY LOGS; +FLUSH LOCAL CLIENT_STATISTICS; +FLUSH LOCAL INDEX_STATISTICS; +FLUSH LOCAL TABLE_STATISTICS; +FLUSH LOCAL USER_STATISTICS; +FLUSH LOCAL THREAD_STATISTICS; +FLUSH LOCAL CHANGED_PAGE_BITMAPS; +FLUSH LOCAL LOGS; +FLUSH LOCAL BINARY LOGS; +FLUSH LOCAL TABLES WITH READ LOCK; +UNLOCK TABLES; +FLUSH LOCAL TABLES t1 WITH READ LOCK; +UNLOCK TABLES; +FLUSH LOCAL TABLES t1 FOR EXPORT; +UNLOCK TABLES; +LOCK TABLES t1 WRITE; +FLUSH LOCAL TABLES t1; +UNLOCK TABLES; +LOCK TABLES t1 READ; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +FLUSH LOCAL TABLES t1; +UNLOCK TABLES; +FLUSH LOCAL TABLES t1; +ANALYZE LOCAL TABLE t1, t2; +OPTIMIZE LOCAL TABLE t1, t2; +REPAIR LOCAL TABLE x1, x2; +--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 AS wsrep_last_committed_diff; +--enable_query_log + +SELECT COUNT(*) = 10 FROM t1; +SELECT COUNT(*) = 10 FROM x1; +SELECT COUNT(*) = 10000 FROM t2; +SELECT COUNT(*) = 10 FROM x2; + + +--connection node_1 +DROP TABLE t1, t2, x1, x2; +CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER); +SET SESSION wsrep_replicate_myisam = TRUE; +CREATE TABLE x1 (f1 INTEGER) ENGINE=MyISAM; +CREATE TABLE x2 (f1 INT PRIMARY KEY AUTO_INCREMENT, f2 INTEGER) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO x1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO t2 (f2) SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4; +INSERT INTO x2 (f2) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); + + +--connection node_2 +--let $wsrep_last_committed_before2 = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--connection node_1 +set wsrep_on=0; +FLUSH DES_KEY_FILE; +FLUSH HOSTS; +FLUSH QUERY CACHE; +FLUSH STATUS; +FLUSH PRIVILEGES; +FLUSH USER_RESOURCES; +FLUSH TABLES; +FLUSH TABLES t2; +FLUSH ERROR LOGS; +FLUSH SLOW LOGS; +FLUSH GENERAL LOGS; +FLUSH ENGINE LOGS; +FLUSH RELAY LOGS; +FLUSH CLIENT_STATISTICS; +FLUSH INDEX_STATISTICS; +FLUSH TABLE_STATISTICS; +FLUSH USER_STATISTICS; +FLUSH THREAD_STATISTICS; +FLUSH CHANGED_PAGE_BITMAPS; +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; +LOCK TABLES t1 WRITE; +FLUSH TABLES t1; +UNLOCK TABLES; +LOCK TABLES t1 READ; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +FLUSH TABLES t1; +UNLOCK TABLES; +FLUSH TABLES t1; +ANALYZE TABLE t1, t2; +OPTIMIZE TABLE t1, t2; +REPAIR TABLE x1, x2; +--connection node_2 +--let $wsrep_last_committed_after2 = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed'` +--disable_query_log +--eval SELECT $wsrep_last_committed_after2 = $wsrep_last_committed_before2 AS wsrep_last_committed_diff; +--eval SELECT $wsrep_last_committed_after2 = $wsrep_last_committed_before + 9 AS wsrep_last_committed_diff2; +--enable_query_log + +SELECT COUNT(*) = 10 FROM t1; +SELECT COUNT(*) = 10 FROM x1; +SELECT COUNT(*) = 10000 FROM t2; +SELECT COUNT(*) = 10 FROM x2; + +--connection node_1 +set wsrep_on=1; +DROP TABLE t1, t2, x1, x2; diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 5ffa8b16345..3ed8545bcb4 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -1175,6 +1175,7 @@ bool Sql_cmd_analyze_table::execute(THD *thd) if (check_table_access(thd, SELECT_ACL | INSERT_ACL, first_table, FALSE, UINT_MAX, FALSE)) goto error; + WSREP_TO_ISOLATION_BEGIN_WRTCHK(NULL, NULL, first_table); thd->enable_slow_log= opt_log_slow_admin_statements; #ifdef WITH_WSREP WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL); @@ -1233,7 +1234,7 @@ bool Sql_cmd_optimize_table::execute(THD *thd) if (check_table_access(thd, SELECT_ACL | INSERT_ACL, first_table, FALSE, UINT_MAX, FALSE)) goto error; /* purecov: inspected */ - WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL) + WSREP_TO_ISOLATION_BEGIN_WRTCHK(NULL, NULL, first_table); thd->enable_slow_log= opt_log_slow_admin_statements; res= (specialflag & SPECIAL_NO_NEW_FUNC) ? mysql_recreate_table(thd, first_table, true) : @@ -1267,7 +1268,7 @@ bool Sql_cmd_repair_table::execute(THD *thd) FALSE, UINT_MAX, FALSE)) goto error; /* purecov: inspected */ thd->enable_slow_log= opt_log_slow_admin_statements; - WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL) + WSREP_TO_ISOLATION_BEGIN_WRTCHK(NULL, NULL, first_table); res= mysql_admin_table(thd, first_table, &m_lex->check_opt, "repair", TL_WRITE, 1, MY_TEST(m_lex->check_opt.sql_flags & TT_USEFRM), diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 99a1af749f9..7faa319feb0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4679,7 +4679,7 @@ end_with_restore_list: REFRESH_STATUS | REFRESH_USER_RESOURCES)) { - WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL) + WSREP_TO_ISOLATION_BEGIN_WRTCHK(WSREP_MYSQL_DB, NULL, NULL) } #endif /* WITH_WSREP*/ diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 5e46c881510..16d2986f031 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -215,6 +215,13 @@ inline bool is_supported_parser_charset(CHARSET_INFO *cs) if (WSREP(thd) || (thd && thd->wsrep_exec_mode==TOTAL_ORDER)) \ wsrep_to_isolation_end(thd); +/* Checks if lex->no_write_to_binlog is set for statements that use + LOCAL or NO_WRITE_TO_BINLOG +*/ +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \ + if (WSREP(thd) && !thd->lex->no_write_to_binlog \ + && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto error; + #else #define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index f3909913c5b..ee05ad7bd36 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -312,6 +312,36 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, } } } +#ifdef WITH_WSREP + if (WSREP(thd) && !thd->lex->no_write_to_binlog + && (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 */ #ifdef WITH_WSREP if (thd && thd->wsrep_applier) diff --git a/sql/wsrep_hton.cc b/sql/wsrep_hton.cc index c096d2610eb..812d64c8c82 100644 --- a/sql/wsrep_hton.cc +++ b/sql/wsrep_hton.cc @@ -69,6 +69,17 @@ void wsrep_register_hton(THD* thd, bool all) { if (thd->wsrep_exec_mode != TOTAL_ORDER && !thd->wsrep_apply_toi) { + if (thd->wsrep_exec_mode == LOCAL_STATE && + (thd_sql_command(thd) == SQLCOM_OPTIMIZE || + thd_sql_command(thd) == SQLCOM_ANALYZE || + thd_sql_command(thd) == SQLCOM_REPAIR) && + thd->lex->no_write_to_binlog == 1) + { + WSREP_DEBUG("Skipping wsrep_register_hton for LOCAL sql admin command : %s", + thd->query()); + return; + } + THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; for (Ha_trx_info *i= trans->ha_list; WSREP(thd) && i; i = i->next()) {