Skip to content

Commit 92cb41b

Browse files
committed
Bug#20676000: FAILING MDL TABLESPACE ASSERTION FOR ALTER NDB TABLE IN UNIREG.CC:263
For mysql versions before 50120, NDB stored the tablespace names only in the NDB dictionary. Thus, we have to get the tablespace name from the engine rather than the .FRM file in this case. This patch introduces a new handlerton function 'get_tablespace()', which retrieves a tablespace name from a storage engine, given a schema- and table name. The new handlerton function is implemented for the NDB storage engine. The existing server function 'get_tablespace_name()', currently retrieving the tablespace name from an .FRM file, is extended to instead get the name from the storage engine, using the new handlerton function, in the cases where this is relevant.
1 parent 1cd170a commit 92cb41b

File tree

6 files changed

+511
-8
lines changed

6 files changed

+511
-8
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#################################################################
2+
# Test DDL statement 1: ALTER TABLE.
3+
SHOW CREATE TABLE t1;
4+
Table Create Table
5+
t1 CREATE TABLE `t1` (
6+
`a1` smallint(6) NOT NULL,
7+
`a2` int(11) NOT NULL,
8+
`a3` bigint(20) NOT NULL,
9+
`a4` char(10) DEFAULT NULL,
10+
`a5` decimal(5,1) DEFAULT NULL,
11+
`a6` time DEFAULT NULL,
12+
`a7` date DEFAULT NULL,
13+
`a8` datetime DEFAULT NULL,
14+
`a9` varchar(255) DEFAULT NULL,
15+
`a10` blob,
16+
PRIMARY KEY (`a1`)
17+
) /*!50100 TABLESPACE `ts` */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
18+
connect con1, localhost, root;
19+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
20+
SIGNAL got_lock
21+
WAIT_FOR cont';
22+
# Sending 'ALTER TABLE t1 ADD COLUMN c int;'
23+
ALTER TABLE t1 ADD COLUMN c int;;
24+
# Verify that the tablespace name is locked.
25+
connection default;
26+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
27+
SET DEBUG_SYNC= 'now SIGNAL cont';
28+
connection con1;
29+
# Reaping 'ALTER TABLE t1 ADD COLUMN c int;'
30+
Warnings:
31+
Note 1880 TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format.
32+
disconnect con1;
33+
connection default;
34+
SET DEBUG_SYNC= 'RESET';
35+
DROP TABLE t1;
36+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
37+
DROP TABLESPACE ts ENGINE NDB;
38+
DROP LOGFILE GROUP lg ENGINE NDB;
39+
#################################################################
40+
# Test DDL statement 2: RENAME TABLE.
41+
# Disabled due to failing assert in ndb.
42+
#################################################################
43+
# Test DDL statement 3: TRUNCATE TABLE.
44+
SHOW CREATE TABLE t1;
45+
Table Create Table
46+
t1 CREATE TABLE `t1` (
47+
`a1` smallint(6) NOT NULL,
48+
`a2` int(11) NOT NULL,
49+
`a3` bigint(20) NOT NULL,
50+
`a4` char(10) DEFAULT NULL,
51+
`a5` decimal(5,1) DEFAULT NULL,
52+
`a6` time DEFAULT NULL,
53+
`a7` date DEFAULT NULL,
54+
`a8` datetime DEFAULT NULL,
55+
`a9` varchar(255) DEFAULT NULL,
56+
`a10` blob,
57+
PRIMARY KEY (`a1`)
58+
) /*!50100 TABLESPACE `ts` */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
59+
connect con1, localhost, root;
60+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
61+
SIGNAL got_lock
62+
WAIT_FOR cont';
63+
# Sending 'TRUNCATE TABLE t1;'
64+
TRUNCATE TABLE t1;;
65+
# Verify that the tablespace name is locked.
66+
connection default;
67+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
68+
SET DEBUG_SYNC= 'now SIGNAL cont';
69+
connection con1;
70+
# Reaping 'TRUNCATE TABLE t1;'
71+
disconnect con1;
72+
connection default;
73+
SET DEBUG_SYNC= 'RESET';
74+
DROP TABLE t1;
75+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
76+
DROP TABLESPACE ts ENGINE NDB;
77+
DROP LOGFILE GROUP lg ENGINE NDB;
78+
#################################################################
79+
# Test DDL statement 4: DROP TABLE.
80+
SHOW CREATE TABLE t1;
81+
Table Create Table
82+
t1 CREATE TABLE `t1` (
83+
`a1` smallint(6) NOT NULL,
84+
`a2` int(11) NOT NULL,
85+
`a3` bigint(20) NOT NULL,
86+
`a4` char(10) DEFAULT NULL,
87+
`a5` decimal(5,1) DEFAULT NULL,
88+
`a6` time DEFAULT NULL,
89+
`a7` date DEFAULT NULL,
90+
`a8` datetime DEFAULT NULL,
91+
`a9` varchar(255) DEFAULT NULL,
92+
`a10` blob,
93+
PRIMARY KEY (`a1`)
94+
) /*!50100 TABLESPACE `ts` */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
95+
connect con1, localhost, root;
96+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
97+
SIGNAL got_lock
98+
WAIT_FOR cont';
99+
# Sending 'DROP TABLE t1;'
100+
DROP TABLE t1;;
101+
# Verify that the tablespace name is locked.
102+
connection default;
103+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
104+
SET DEBUG_SYNC= 'now SIGNAL cont';
105+
connection con1;
106+
# Reaping 'DROP TABLE t1;'
107+
disconnect con1;
108+
connection default;
109+
SET DEBUG_SYNC= 'RESET';
110+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
111+
DROP TABLESPACE ts ENGINE NDB;
112+
DROP LOGFILE GROUP lg ENGINE NDB;
113+
#################################################################
114+
# Test DDL statement 5: ALTER TABLE, but now use the default
115+
# connection to verify that repeated use of the same connection
116+
# works too. In this case, we skip the verification of MDL lock
117+
# acquisition, since it has already been tested above.
118+
SHOW CREATE TABLE t1;
119+
Table Create Table
120+
t1 CREATE TABLE `t1` (
121+
`a1` smallint(6) NOT NULL,
122+
`a2` int(11) NOT NULL,
123+
`a3` bigint(20) NOT NULL,
124+
`a4` char(10) DEFAULT NULL,
125+
`a5` decimal(5,1) DEFAULT NULL,
126+
`a6` time DEFAULT NULL,
127+
`a7` date DEFAULT NULL,
128+
`a8` datetime DEFAULT NULL,
129+
`a9` varchar(255) DEFAULT NULL,
130+
`a10` blob,
131+
PRIMARY KEY (`a1`)
132+
) /*!50100 TABLESPACE `ts` */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
133+
ALTER TABLE t1 ADD COLUMN c int;
134+
Warnings:
135+
Note 1880 TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format.
136+
SHOW CREATE TABLE t1;
137+
Table Create Table
138+
t1 CREATE TABLE `t1` (
139+
`a1` smallint(6) NOT NULL,
140+
`a2` int(11) NOT NULL,
141+
`a3` bigint(20) NOT NULL,
142+
`a4` char(10) DEFAULT NULL,
143+
`a5` decimal(5,1) DEFAULT NULL,
144+
`a6` time DEFAULT NULL,
145+
`a7` date DEFAULT NULL,
146+
`a8` datetime DEFAULT NULL,
147+
`a9` varchar(255) DEFAULT NULL,
148+
`a10` blob,
149+
`c` int(11) DEFAULT NULL,
150+
PRIMARY KEY (`a1`)
151+
) /*!50100 TABLESPACE `ts` */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
152+
DROP TABLE t1;
153+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
154+
DROP TABLESPACE ts ENGINE NDB;
155+
DROP LOGFILE GROUP lg ENGINE NDB;
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Bug#20676000 FAILING MDL TABLESPACE ASSERTION FOR ALTER NDB TABLE IN UNIREG.CC:263
2+
#
3+
# For mysql versions before 50120, NDB stored the tablespace names only
4+
# in the NDB dictionary. Thus, in order to acquire an MDL lock on the
5+
# tablespace name, the server has to get the name from the engine rather
6+
# than the .FRM file in this case. This test verifies that restoring an
7+
# NDB table with version < 50120, followed by various SQL commands,
8+
# will lock the tablespace name properly.
9+
#
10+
# We do various SQL statements in a separate connection, and verify that
11+
# each statement grabs an MDL lock on the tablespace name. We create
12+
# a new connection each time to verify that this works even if getting
13+
# the tablespace name from NDB is the first function in NDB being invoked
14+
# for the given connection. Between each SQL statement that is tested,
15+
# we must drop the restored database items and restore over again,
16+
# because the DDL statements will write the meta data according to the
17+
# target mysql version, and not the backed up version < 50120 (which is
18+
# what we want to test in this context).
19+
20+
--source include/have_ndb.inc
21+
--source include/have_debug.inc
22+
--source include/have_debug_sync.inc
23+
--source include/have_perfschema.inc
24+
25+
--enable_connect_log
26+
27+
# Directory containing the saved backup files
28+
let $backup_data_dir=$MYSQL_TEST_DIR/suite/ndb/backups;
29+
30+
--echo #################################################################
31+
--echo # Test DDL statement 1: ALTER TABLE.
32+
33+
--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -p 1 -m -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
34+
--exec $NDB_RESTORE --no-defaults -e -b 1 -n 2 -p 1 -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
35+
SHOW CREATE TABLE t1;
36+
37+
--connect (con1, localhost, root)
38+
39+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
40+
SIGNAL got_lock
41+
WAIT_FOR cont';
42+
--echo # Sending 'ALTER TABLE t1 ADD COLUMN c int;'
43+
--send ALTER TABLE t1 ADD COLUMN c int;
44+
45+
--echo # Verify that the tablespace name is locked.
46+
--connection default
47+
48+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
49+
LET $wait_condition=
50+
SELECT COUNT(*) = 1 FROM performance_schema.metadata_locks
51+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts';
52+
--source include/wait_condition.inc
53+
54+
SET DEBUG_SYNC= 'now SIGNAL cont';
55+
56+
--connection con1
57+
--echo # Reaping 'ALTER TABLE t1 ADD COLUMN c int;'
58+
--reap
59+
--disconnect con1
60+
--source include/wait_until_disconnected.inc
61+
--connection default
62+
63+
SET DEBUG_SYNC= 'RESET';
64+
DROP TABLE t1;
65+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
66+
DROP TABLESPACE ts ENGINE NDB;
67+
DROP LOGFILE GROUP lg ENGINE NDB;
68+
69+
--echo #################################################################
70+
--echo # Test DDL statement 2: RENAME TABLE.
71+
--echo # Disabled due to failing assert in ndb.
72+
73+
#--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -p 1 -m -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
74+
#--exec $NDB_RESTORE --no-defaults -e -b 1 -n 2 -p 1 -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
75+
#SHOW CREATE TABLE t1;
76+
#
77+
#--connect (con1, localhost, root)
78+
#
79+
#SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
80+
# SIGNAL got_lock
81+
# WAIT_FOR cont';
82+
#--echo # Sending 'RENAME TABLE t1 TO t2;'
83+
#--send RENAME TABLE t1 TO t2;
84+
#
85+
#--echo # Verify that the tablespace name is locked.
86+
#--connection default
87+
#
88+
#SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
89+
#LET $wait_condition=
90+
# SELECT COUNT(*) = 1 FROM performance_schema.metadata_locks
91+
# WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts';
92+
#--source include/wait_condition.inc
93+
#
94+
#SET DEBUG_SYNC= 'now SIGNAL cont';
95+
#
96+
#--connection con1
97+
#--echo # Reaping 'RENAME TABLE t1 TO t2;'
98+
#--reap
99+
#--disconnect con1
100+
#--source include/wait_until_disconnected.inc
101+
#--connection default
102+
#
103+
#SET DEBUG_SYNC= 'RESET';
104+
#DROP TABLE t2;
105+
#ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
106+
#DROP TABLESPACE ts ENGINE NDB;
107+
#DROP LOGFILE GROUP lg ENGINE NDB;
108+
109+
--echo #################################################################
110+
--echo # Test DDL statement 3: TRUNCATE TABLE.
111+
112+
--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -p 1 -m -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
113+
--exec $NDB_RESTORE --no-defaults -e -b 1 -n 2 -p 1 -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
114+
SHOW CREATE TABLE t1;
115+
116+
--connect (con1, localhost, root)
117+
118+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
119+
SIGNAL got_lock
120+
WAIT_FOR cont';
121+
--echo # Sending 'TRUNCATE TABLE t1;'
122+
--send TRUNCATE TABLE t1;
123+
124+
--echo # Verify that the tablespace name is locked.
125+
--connection default
126+
127+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
128+
LET $wait_condition=
129+
SELECT COUNT(*) = 1 FROM performance_schema.metadata_locks
130+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts';
131+
--source include/wait_condition.inc
132+
133+
SET DEBUG_SYNC= 'now SIGNAL cont';
134+
135+
--connection con1
136+
--echo # Reaping 'TRUNCATE TABLE t1;'
137+
--reap
138+
--disconnect con1
139+
--source include/wait_until_disconnected.inc
140+
--connection default
141+
142+
SET DEBUG_SYNC= 'RESET';
143+
DROP TABLE t1;
144+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
145+
DROP TABLESPACE ts ENGINE NDB;
146+
DROP LOGFILE GROUP lg ENGINE NDB;
147+
148+
--echo #################################################################
149+
--echo # Test DDL statement 4: DROP TABLE.
150+
151+
--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -p 1 -m -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
152+
--exec $NDB_RESTORE --no-defaults -e -b 1 -n 2 -p 1 -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
153+
SHOW CREATE TABLE t1;
154+
155+
--connect (con1, localhost, root)
156+
157+
SET DEBUG_SYNC= 'after_wait_locked_tablespace_name_for_table
158+
SIGNAL got_lock
159+
WAIT_FOR cont';
160+
--echo # Sending 'DROP TABLE t1;'
161+
--send DROP TABLE t1;
162+
163+
--echo # Verify that the tablespace name is locked.
164+
--connection default
165+
166+
SET DEBUG_SYNC= 'now WAIT_FOR got_lock';
167+
LET $wait_condition=
168+
SELECT COUNT(*) = 1 FROM performance_schema.metadata_locks
169+
WHERE object_type LIKE 'TABLESPACE' AND object_name LIKE 'ts';
170+
--source include/wait_condition.inc
171+
172+
SET DEBUG_SYNC= 'now SIGNAL cont';
173+
174+
--connection con1
175+
--echo # Reaping 'DROP TABLE t1;'
176+
--reap
177+
--disconnect con1
178+
--source include/wait_until_disconnected.inc
179+
--connection default
180+
181+
SET DEBUG_SYNC= 'RESET';
182+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
183+
DROP TABLESPACE ts ENGINE NDB;
184+
DROP LOGFILE GROUP lg ENGINE NDB;
185+
186+
--echo #################################################################
187+
--echo # Test DDL statement 5: ALTER TABLE, but now use the default
188+
--echo # connection to verify that repeated use of the same connection
189+
--echo # works too. In this case, we skip the verification of MDL lock
190+
--echo # acquisition, since it has already been tested above.
191+
192+
--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -p 1 -m -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
193+
--exec $NDB_RESTORE --no-defaults -e -b 1 -n 2 -p 1 -r $backup_data_dir/51_dd >> $NDB_TOOLS_OUTPUT
194+
195+
SHOW CREATE TABLE t1;
196+
ALTER TABLE t1 ADD COLUMN c int;
197+
SHOW CREATE TABLE t1;
198+
199+
DROP TABLE t1;
200+
ALTER TABLESPACE ts DROP DATAFILE 'datafile.dat' ENGINE NDB;
201+
DROP TABLESPACE ts ENGINE NDB;
202+
DROP LOGFILE GROUP lg ENGINE NDB;
203+
204+
--disable_connect_log

0 commit comments

Comments
 (0)