Commit fbe739cb authored by Raghavendra D Prabhu's avatar Raghavendra D Prabhu Committed by Nirbhay Choubey

Bug#1421360: Add 'FLUSH TABLES' to Total Order Isolation execution.

Before this, FLUSH TABLES and FLUSH TABLES t1 (REFRESH_TABLES hereafter) were executed locally,
which also had implications for GTID. MySQL async replication does
replicate FLUSH TABLES.

Hence, this commit

a)  Adds REFRESH_TABLES to TOI.

b) Skips LOCK-based REFRESH_TABLES from TOI, ie. FLUSH TABLES WITH READ
LOCK and FLUSH TABLES FOR EXPORT.

c) Executes them after reload_acl_and_cache. This is done since
reload_acl_and_cache checks for thd->locked_tables_mode and does upgrade
of MDL locks accordingly. A failure here means REFRESH_TABLES cannot
run.

    i) This is also important since LOCK TABLES is not replicated in
    galera.

d) Test galera_flush has been modified for

    i) wsrep_replicate_myisam SESSION variable.

    ii) Testing REFRESH_TABLES.

    iii) Testing REFRESH_TABLES + LOCK TABLES.

e) Use different WSREP_TO_ISOLATION_BEGIN for global FLUSH TABLES and FLUSH TABLES <table,>.
parent 5a002adb
......@@ -8,7 +8,7 @@ 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','N');
FLUSH PRIVILEGES;
DELETE FROM mysql.user WHERE user = 'user1';
SET GLOBAL wsrep_replicate_myisam = FALSE;
SET SESSION wsrep_replicate_myisam = FALSE;
FLUSH PRIVILEGES;
FLUSH QUERY CACHE;
wsrep_last_committed_diff
......@@ -19,6 +19,13 @@ wsrep_last_committed_diff
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
CREATE TABLE t1 (f1 INTEGER);
FLUSH LOGS;
FLUSH TABLES WITH READ LOCK;
......@@ -29,4 +36,19 @@ 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;
......@@ -39,7 +39,7 @@ FLUSH PRIVILEGES;
--connect node_2a, 127.0.0.1, user1, pass1, test, $NODE_MYPORT_2
--connection node_1
DELETE FROM mysql.user WHERE user = 'user1';
SET GLOBAL wsrep_replicate_myisam = FALSE;
SET SESSION wsrep_replicate_myisam = FALSE;
FLUSH PRIVILEGES;
......@@ -77,8 +77,32 @@ FLUSH USER_RESOURCES;
--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 TABLES;
--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_1
CREATE TABLE t2 (f1 INTEGER);
--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 TABLES t2;
--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
# The following statements should not be replicated: FLUSH LOGS, FLUSH TABLES WITH LOCKS
#
......@@ -103,5 +127,47 @@ UNLOCK TABLES;
--eval SELECT $wsrep_last_committed_after = $wsrep_last_committed_before AS wsrep_last_committed_diff;
--enable_query_log
## Test LOCK TABLES with FLUSH TABLES
## LOCK TABLES t1 write followed by flush tables t1 should succeed due to MDL upgrade.
## LOCK tables t2 read followed by flush tables t2 should fail with ER_TABLE_NOT_LOCKED_FOR_WRITE
--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
LOCK TABLES t1 WRITE;
FLUSH TABLES t1;
UNLOCK TABLES;
--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
LOCK TABLES t1 READ;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
FLUSH TABLES t1;
UNLOCK TABLES;
--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
--connection node_1
FLUSH TABLES t1;
--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_1
DROP TABLE t1;
DROP TABLE t2;
......@@ -4695,6 +4695,25 @@ 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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment