Skip to content

Commit 4102d52

Browse files
philip-galeraNirbhay Choubey
authored andcommitted
Refs codership/mysql-wsrep#113 - tests around FLUSH TABLE, FLUSH TABLES, LOCK TABLE
1 parent 2106fed commit 4102d52

9 files changed

+181
-11
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SET SESSION wsrep_sync_wait = 0;
2+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
3+
FLUSH TABLE t1 WITH READ LOCK;
4+
INSERT INTO t1 VALUES (1);
5+
INSERT INTO t1 VALUES (2);
6+
SET SESSION wsrep_sync_wait = 0;
7+
SELECT COUNT(*) = 0 FROM t1;
8+
COUNT(*) = 0
9+
1
10+
UNLOCK TABLES;
11+
SET SESSION wsrep_sync_wait = 7;
12+
SELECT COUNT(*) = 2 FROM t1;
13+
COUNT(*) = 2
14+
1
15+
DROP TABLE t1;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SET SESSION wsrep_sync_wait = 0;
2+
SET SESSION lock_wait_timeout = 60;
3+
SET SESSION innodb_lock_wait_timeout=60;
4+
SET SESSION wait_timeout=60;
5+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
6+
FLUSH TABLE t1 WITH READ LOCK;
7+
ALTER TABLE t1 ADD COLUMN f2 INTEGER;
8+
SELECT 1 FROM DUAL;
9+
1
10+
1
11+
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock';
12+
COUNT(*) = 1
13+
1
14+
UNLOCK TABLES;
15+
SET SESSION wsrep_sync_wait = 7;
16+
SHOW CREATE TABLE t1;
17+
Table Create Table
18+
t1 CREATE TABLE `t1` (
19+
`f1` int(11) NOT NULL,
20+
`f2` int(11) DEFAULT NULL,
21+
PRIMARY KEY (`f1`)
22+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
23+
SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock';
24+
COUNT(*) = 0
25+
1
26+
DROP TABLE t1;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
2+
SET AUTOCOMMIT=OFF;
3+
FLUSH TABLES t1 FOR EXPORT;
4+
INSERT INTO t1 VALUES (2);
5+
SET SESSION wsrep_sync_wait = 0;
6+
UNLOCK TABLES;
7+
COMMIT;
8+
SELECT COUNT(*) = 1 FROM t1;
9+
COUNT(*) = 1
10+
1
11+
wsrep_local_aborts_increment
12+
1
13+
DROP TABLE t1;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
22
SET AUTOCOMMIT=OFF;
33
LOCK TABLE t1 WRITE;
4-
INSERT INTO t1 VALUES (1);;
54
INSERT INTO t1 VALUES (2);
5+
UNLOCK TABLES;
6+
COMMIT;
7+
SELECT COUNT(*) = 1 FROM t1;
8+
COUNT(*) = 1
9+
1
610
wsrep_local_aborts_increment
711
1
812
DROP TABLE t1;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Test that applying plays well with FLUSH TABLE table_name WITH READ LOCK. The applier
3+
# thread should block until UNLOCK TABLEs.
4+
#
5+
6+
--source include/galera_cluster.inc
7+
--source include/have_innodb.inc
8+
9+
--connection node_1
10+
SET SESSION wsrep_sync_wait = 0;
11+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
12+
13+
FLUSH TABLE t1 WITH READ LOCK;
14+
15+
--connection node_2
16+
INSERT INTO t1 VALUES (1);
17+
INSERT INTO t1 VALUES (2);
18+
19+
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
20+
--connection node_1a
21+
SET SESSION wsrep_sync_wait = 0;
22+
23+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock'
24+
--source include/wait_condition.inc
25+
26+
SELECT COUNT(*) = 0 FROM t1;
27+
28+
--connection node_1
29+
UNLOCK TABLES;
30+
31+
SET SESSION wsrep_sync_wait = 7;
32+
SELECT COUNT(*) = 2 FROM t1;
33+
34+
DROP TABLE t1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--lock_wait_timeout=5 --innodb_lock_wait_timeout=5 --wait_timeout=5
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Test that applying a DDL plays well with FLUSH TABLE table_name WITH READ LOCK. The applier
3+
# thread should block until UNLOCK TABLEs.
4+
#
5+
6+
--source include/galera_cluster.inc
7+
--source include/have_innodb.inc
8+
9+
--connection node_1
10+
SET SESSION wsrep_sync_wait = 0;
11+
12+
# Those values are valid only for connection node_1. The global values from the -master.opt file apply to applier threads.
13+
SET SESSION lock_wait_timeout = 60;
14+
SET SESSION innodb_lock_wait_timeout=60;
15+
SET SESSION wait_timeout=60;
16+
17+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
18+
19+
FLUSH TABLE t1 WITH READ LOCK;
20+
21+
--connection node_2
22+
ALTER TABLE t1 ADD COLUMN f2 INTEGER;
23+
24+
--connection node_1
25+
SELECT 1 FROM DUAL;
26+
# Sleep for longer than the global timeout ...
27+
--sleep 6
28+
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock';
29+
30+
UNLOCK TABLES;
31+
32+
SET SESSION wsrep_sync_wait = 7;
33+
34+
SHOW CREATE TABLE t1;
35+
SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock';
36+
37+
DROP TABLE t1;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
4+
#
5+
# Test that a local FLUSH TABLES FOR BACKUP will NOT be broken by an incoming remote transaction against that table
6+
#
7+
8+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
9+
10+
--connection node_2
11+
SET AUTOCOMMIT=OFF;
12+
--let $wsrep_local_bf_aborts_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'`
13+
FLUSH TABLES t1 FOR EXPORT;
14+
15+
--connection node_1
16+
INSERT INTO t1 VALUES (2);
17+
18+
--connection node_2
19+
SET SESSION wsrep_sync_wait = 0;
20+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock'
21+
--source include/wait_condition.inc
22+
23+
UNLOCK TABLES;
24+
25+
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock'
26+
--source include/wait_condition.inc
27+
28+
COMMIT;
29+
SELECT COUNT(*) = 1 FROM t1;
30+
31+
--let $wsrep_local_bf_aborts_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'`
32+
33+
--disable_query_log
34+
--eval SELECT $wsrep_local_bf_aborts_after - $wsrep_local_bf_aborts_before = 0 AS wsrep_local_aborts_increment;
35+
--enable_query_log
36+
37+
DROP TABLE t1;

mysql-test/suite/galera/t/galera_bf_abort_lock_table.test

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--source include/have_innodb.inc
33

44
#
5-
# Test that a local LOCK TABLE will be broken by an incoming remote transaction against that table
5+
# Test that a local LOCK TABLE will NOT be broken by an incoming remote transaction against that table
66
#
77

88
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
@@ -12,22 +12,25 @@ SET AUTOCOMMIT=OFF;
1212
--let $wsrep_local_bf_aborts_before = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'`
1313
LOCK TABLE t1 WRITE;
1414

15-
# Issue a concurrent INSERT against the lock table that will block
16-
--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2
17-
--send INSERT INTO t1 VALUES (1);
18-
1915
--connection node_1
2016
INSERT INTO t1 VALUES (2);
2117

22-
# The concurent insert is allowed to complete because the LOCK TABLE is now broken
23-
--connection node_2a
24-
--error 0
25-
--reap
18+
--connection node_2
19+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock'
20+
--source include/wait_condition.inc
21+
22+
UNLOCK TABLES;
23+
24+
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE = 'Waiting for table metadata lock'
25+
--source include/wait_condition.inc
26+
27+
COMMIT;
28+
SELECT COUNT(*) = 1 FROM t1;
2629

2730
--let $wsrep_local_bf_aborts_after = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'`
2831

2932
--disable_query_log
30-
--eval SELECT $wsrep_local_bf_aborts_after - $wsrep_local_bf_aborts_before = 1 AS wsrep_local_aborts_increment;
33+
--eval SELECT $wsrep_local_bf_aborts_after - $wsrep_local_bf_aborts_before = 0 AS wsrep_local_aborts_increment;
3134
--enable_query_log
3235

3336
DROP TABLE t1;

0 commit comments

Comments
 (0)