Debian Codegraph @

mysql-test/suite/innodb/t/alter_rename_existing_xtra.test

raw
1 --echo #
2 --echo # Show what happens during ALTER TABLE when an existing file
3 --echo # exists in the target location.
4 --echo #
5 --echo # Bug #19218794: IF TABLESPACE EXISTS, CAN'T CREATE TABLE,
6 --echo # BUT CAN ALTER ENGINE=INNODB
7 --echo #
8
9
10 # Using chmod to remove write permission excludes Windows.
11 --source include/not_windows.inc
12
13 --disable_query_log
14 LET $MYSQLD_DATADIR = `select @@datadir`;
15 SET @old_innodb_file_per_table = @@innodb_file_per_table;
16 --enable_query_log
17
18 CREATE TABLE t1 (a SERIAL, b CHAR(10)) ENGINE=Memory;
19 INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
20
21 --echo #
22 --echo # Create a read-only file called MYSQLD_DATADIR/test/t1.ibd
23 --exec echo "This is not t1.ibd" > $MYSQLD_DATADIR/test/t1.ibd
24 --exec chmod a-w $MYSQLD_DATADIR/test/t1.ibd
25
26 --echo # Directory listing of test/*.ibd
27 --echo #
28 --list_files $MYSQLD_DATADIR/test/ *.ibd
29
30 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
31 --error ER_ERROR_ON_RENAME
32 ALTER TABLE t1 ENGINE = InnoDB;
33
34 --exec chmod a-w $MYSQLD_DATADIR/test
35 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
36 --error ER_GET_ERRNO
37 ALTER TABLE t1 ENGINE = InnoDB;
38 --exec chmod a+w $MYSQLD_DATADIR/test
39
40 --echo #
41 --echo # Move the file to InnoDB as t2
42 --echo #
43 ALTER TABLE t1 RENAME TO t2, ENGINE = INNODB;
44 SHOW CREATE TABLE t2;
45 SELECT * from t2;
46
47 --echo #
48 --echo # Try to rename t2 to t1 with an existing read-only t1 in the way.
49 --echo #
50 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
51 --error ER_ERROR_ON_RENAME
52 ALTER TABLE t2 RENAME TO t1;
53
54 --echo #
55 --echo # Try again but now with a read-only 'test' directory.
56 --echo #
57 --exec chmod a-w $MYSQLD_DATADIR/test
58 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
59 --error ER_ERROR_ON_RENAME
60 ALTER TABLE t2 RENAME TO t1;
61 --exec chmod a+w $MYSQLD_DATADIR/test
62
63 --echo #
64 --echo # Create another t1, but in the system tablespace.
65 --echo #
66 SET GLOBAL innodb_file_per_table=OFF;
67 CREATE TABLE t1 (a SERIAL, b CHAR(20)) ENGINE=InnoDB;
68 INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
69 SHOW CREATE TABLE t1;
70 SELECT name, space=0 FROM information_schema.innodb_tables WHERE name = 'test/t1';
71
72 --echo #
73 --echo # Try to move t1 from the system tablespace to a file-per-table
74 --echo # while a blocking read-only t1.ibd file exists.
75 --echo #
76 --echo # Move using innodb_file_per_table=ON
77 --echo #
78 SET GLOBAL innodb_file_per_table=ON;
79
80 --echo #
81 --echo # Move using using innodb_file_per_table=ON and a read-only directory
82 --echo #
83 --exec chmod a-w $MYSQLD_DATADIR/test
84 ALTER TABLE t1 ADD COLUMN e1 INT, ALGORITHM=INPLACE;
85 ALTER TABLE t1 ADD COLUMN e2 INT, ALGORITHM=COPY;
86 --exec chmod a-w $MYSQLD_DATADIR/test
87
88 --echo #
89 --echo # Move using TABLESPACE=innodb_file_per_table
90 --echo #
91 SET GLOBAL innodb_file_per_table=OFF;
92 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
93 --error ER_GET_ERRNO
94 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE;
95 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
96 --error ER_GET_ERRNO
97 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY;
98
99 --echo #
100 --echo # Move using TABLESPACE=innodb_file_per_table with a read-only directory
101 --echo #
102 --exec chmod a-w $MYSQLD_DATADIR/test
103 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
104 --error ER_GET_ERRNO
105 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE;
106 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
107 --error ER_GET_ERRNO
108 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY;
109 --exec chmod a+w $MYSQLD_DATADIR/test
110
111 --echo #
112 --echo # ALTER TABLE t1 from system tablespace to general tablespace
113 --echo #
114 CREATE TABLESPACE s1 ADD DATAFILE 's1.ibd';
115 ALTER TABLE t1 TABLESPACE s1;
116
117 --echo #
118 --echo # Try to move t1 from a general tablespace to a file-per-table
119 --echo # while a blocking read-only t1.ibd file exists.
120 --echo #
121 --replace_regex /$MYSQLD_DATADIR/MYSQLD_DATADIR/
122 --error ER_TABLESPACE_EXISTS
123 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE;
124 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
125 --error ER_ERROR_ON_RENAME
126 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY;
127
128 --echo #
129 --echo # Try again with a read-only 'test' directory.
130 --echo #
131 --exec chmod a-w $MYSQLD_DATADIR/test
132 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
133 --error ER_GET_ERRNO
134 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE;
135 --replace_regex /create table '.*' \(errno: .*\)/create table 'TEMP_FILE_NAME' (errno: NN)/
136 --error ER_GET_ERRNO
137 ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY;
138 --exec chmod a+w $MYSQLD_DATADIR/test
139
140 --echo #
141 --echo # Cleanup
142 --echo #
143 --remove_file $MYSQLD_DATADIR/test/t1.ibd
144
145 DROP TABLE t1, t2;
146 DROP TABLESPACE s1;
147
148 --disable_query_log
149 call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Cannot rename '.*' to '.*' for space ID .* because the target file exists. Remove the target file and try again");
150 call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Operating system error number 13 in a file operation.");
151 call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* The error means mysqld does not have the access rights to the directory.");
152 call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Cannot create file '.*'");
153 SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;
154 --enable_query_log