Debian Codegraph @

mysql-test/suite/innodb/t/innodb_read_only-2.test

raw
1 ######## suite/innodb/t/innodb-wl6445-2 ##########
2 # #
3 # Testcase for worklog WL#6445: InnoDB should be able to work with #
4 # read-only tables
5 # All sub-test in this file focus on changing file permission and #
6 # restarting server in read only. It verifies necessary operations #
7 # are blocked #
8 # #
9 # #
10 # Creation: #
11 # 2011-09-06 Implemented this test as part of WL#6445 #
12 # #
13 ######################################################################
14
15 --source include/no_valgrind_without_big.inc
16
17 # *nix specific command to remove write permission
18 # wanted to use perl to save original permission of file and restore back after
19 # chnage but could not find way to do.(with perl we could run test on windows too)
20 -- source include/not_windows.inc
21
22 let MYSQLD_DATADIR =`SELECT @@datadir`;
23 let $innodb_file_per_table = `SELECT @@innodb_file_per_table`;
24
25 SET GLOBAL innodb_file_per_table = 1;
26 SELECT @@innodb_file_per_table;
27
28 let $MYSQLD_DATADIR = `SELECT @@datadir`;
29
30
31 --disable_warnings
32 DROP DATABASE IF EXISTS testdb_wl6445;
33 --enable_warnings
34 CREATE DATABASE testdb_wl6445;
35
36
37 #------------------------------------------------------------------------------
38 # Testcase covers
39 # a) Create table/data ,
40 # b) Stop the server
41 # c) Remove write permission of ibdata , #ib_redo*
42 # d) Start server in --innodb-read-only mode and verfiy DDL/DML/DCL in read only mode
43 #------------------------------------------------------------------------------
44 --echo case # 1
45
46 SET GLOBAL innodb_file_per_table = 1;
47 USE testdb_wl6445;
48 CREATE TABLE t1 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
49 INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
50 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
51
52 --source include/add_mtr_suppression_for_innodb_readonly.inc
53
54 # Force a change buffer merge, so that --innodb-read-only will not
55 # refuse startup, in case there exist buffered changes from earlier tests.
56
57 --source include/shutdown_innodb_clean.inc
58
59 # remove write permissions
60 --exec chmod a-w $MYSQLD_DATADIR/ibdata1
61 --exec chmod a-w $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
62 --exec chmod a-w $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
63
64 --source include/start_innodb_readonly.inc
65
66 USE testdb_wl6445;
67 SELECT i FROM t1 ORDER BY i;
68 --ERROR ER_CANT_LOCK
69 INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
70 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
71
72 --ERROR ER_CANT_LOCK
73 INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
74 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
75 --ERROR ER_READ_ONLY_MODE
76 CREATE TABLE t2 ( i int , j blob) ENGINE = Innodb;
77 --ERROR ER_CANT_LOCK
78 UPDATE t1 SET i = i+1;
79
80 # Fix in next revision - known ( no data returned)
81 # SHOW ENGINE INNODB STATUS;
82 FLUSH STATUS;
83 FLUSH LOGS;
84 FLUSH TABLES t1;
85 FLUSH TABLES WITH READ LOCK;
86 UNLOCK TABLES;
87
88
89 #------------------------------------------------------------------------------
90 #cleanup
91 #------------------------------------------------------------------------------
92 #
93 --source include/shutdown_mysqld.inc
94 # Do something while server is down
95 --exec chmod 0644 $MYSQLD_DATADIR/ibdata1
96 --exec chmod 0644 $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
97 --exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
98 --source include/start_mysqld.inc
99 DROP DATABASE testdb_wl6445;
100
101
102 #------------------------------------------------------------------------------
103 # Testcase covers
104 # a) Create table/data ,
105 # b) Remove write permission of ibdata when server is running
106 # c) Stop the server
107 # d) Remove write permission of #ib_redo*
108 # e) Start server in --innodb-read-only mode and verify DDL/DML/DCL in read only mode
109 #------------------------------------------------------------------------------
110 --echo case # 2
111 CREATE DATABASE testdb_wl6445;
112
113 USE testdb_wl6445;
114 CREATE TABLE t1 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
115 INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
116 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
117
118 # remove write permissions
119 --exec chmod a-w $MYSQLD_DATADIR/ibdata1
120 --exec chmod a-w $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
121
122 # check dml/ddl after removing write permission
123 CREATE TABLE t2 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
124 INSERT INTO t2 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
125 SELECT i,LEFT(j,20) FROM t2 ORDER BY i;
126 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
127 UPDATE t2 SET i = i + 10;
128 SELECT i,LEFT(j,20) FROM t2 ORDER BY i;
129 DELETE FROM t2;
130 SELECT i,LEFT(j,20) FROM t2 ORDER BY i;
131
132 --source include/add_mtr_suppression_for_innodb_readonly.inc
133
134 # Force a change buffer merge, so that --innodb-read-only will not
135 # refuse startup, in case there exist buffered changes from earlier tests.
136 --source include/shutdown_innodb_clean.inc
137
138 --exec chmod a-w $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
139
140 --source include/start_innodb_readonly.inc
141
142 USE testdb_wl6445;
143 SELECT i FROM t1 ORDER BY i;
144 SELECT i FROM t2 ORDER BY i;
145 --ERROR ER_CANT_LOCK
146 INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
147 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
148
149 --ERROR ER_CANT_LOCK
150 INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
151 SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
152 --ERROR ER_TABLE_EXISTS_ERROR
153 CREATE TABLE t2 ( i int , j blob) ENGINE = Innodb;
154 --ERROR ER_READ_ONLY_MODE
155 CREATE TABLE t3 ( i int , j blob) ENGINE = Innodb;
156 --ERROR ER_CANT_LOCK
157 UPDATE t1 SET i = i+1;
158
159 # Fix in next revision - known ( no data returned)
160 # SHOW ENGINE INNODB STATUS;
161 FLUSH STATUS;
162 FLUSH LOGS;
163 FLUSH TABLES t1,t2;
164 FLUSH TABLES WITH READ LOCK;
165 UNLOCK TABLES;
166
167
168 #------------------------------------------------------------------------------
169 # Testcase covers
170 # a) Create table/data ,
171 # b) Remove write permission of ibdata , #ib_redo*
172 # c) Try to restart server without --innodb-read-only mode
173 #------------------------------------------------------------------------------
174 # Note : write permission is already removed in previous case so we just
175 # start server without --innodb-read-only option
176
177 --echo case # 3
178
179 # We let our server restart attempts write to the file $error_log.
180 let $error_log= $MYSQLTEST_VARDIR/log/my_restart.err;
181 # $error_log has to be processed by include/search_pattern.inc which
182 # contains Perl code requiring that the environment variable SEARCH_FILE points
183 # to this file.
184 let SEARCH_FILE= $error_log;
185
186 --source include/shutdown_mysqld.inc
187
188 --echo # Try to restart the server without --innodb-read-only after removing
189 --echo # write permissions of system tablespace. Server should not start.
190 --echo # This confirms server is not automatically started in read-only mode.
191 #----------------------------------------------------------------------------------
192 # Detailed explanations of what happens are placed nearby the checks.
193 --error 1
194 --exec $MYSQLD_CMD --core-file --loose-console > $error_log 2>&1
195
196 # We get depending on the platform either "./ibdata1" or ".\ibdata1".
197 let SEARCH_PATTERN= The innodb_system data file 'ibdata1' must be writable;
198 --source include/search_pattern.inc
199
200
201 #------------------------------------------------------------------------------
202 # Cleanup
203 #------------------------------------------------------------------------------
204 #
205 # Do something while server is down
206 --exec chmod 0644 $MYSQLD_DATADIR/ibdata1
207 --exec chmod 0644 $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
208 --exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
209 --remove_file $error_log
210
211 --source include/start_mysqld.inc
212 DROP DATABASE testdb_wl6445;