File: innodb_read_only-2.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (212 lines) | stat: -rw-r--r-- 7,979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
######## suite/innodb/t/innodb-wl6445-2                     ##########
#                                                                    #
# Testcase for worklog WL#6445: InnoDB should be able to work with   #
# read-only tables
# All sub-test in this file focus on changing file permission and    #
# restarting server in read only. It verifies necessary operations   #
# are blocked                                                        #
#                                                                    #
#                                                                    #
# Creation:                                                          #
# 2011-09-06 Implemented this test as part of WL#6445                #
#                                                                    #
######################################################################

--source include/no_valgrind_without_big.inc

# *nix specific command to remove write permission
# wanted to use perl to save original permission of file and restore back after
# chnage but could not find way to do.(with perl we could run test on windows too)
-- source include/not_windows.inc

let MYSQLD_DATADIR =`SELECT @@datadir`;
let $innodb_file_per_table = `SELECT @@innodb_file_per_table`;

SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;

let $MYSQLD_DATADIR = `SELECT @@datadir`;


--disable_warnings
DROP DATABASE IF EXISTS testdb_wl6445;
--enable_warnings
CREATE DATABASE testdb_wl6445;


#------------------------------------------------------------------------------
# Testcase covers
# a) Create table/data ,
# b) Stop the server
# c) Remove write permission of ibdata , #ib_redo*
# d) Start server in --innodb-read-only mode and verfiy DDL/DML/DCL in read only mode
#------------------------------------------------------------------------------
--echo case # 1

SET GLOBAL innodb_file_per_table = 1;
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

--source include/add_mtr_suppression_for_innodb_readonly.inc

# Force a change buffer merge, so that --innodb-read-only will not
# refuse startup, in case there exist buffered changes from earlier tests.

--source include/shutdown_innodb_clean.inc

# remove write permissions
--exec chmod a-w $MYSQLD_DATADIR/ibdata1
--exec chmod a-w $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
--exec chmod a-w $MYSQLD_DATADIR/#innodb_redo/#ib_redo*

--source include/start_innodb_readonly.inc

USE testdb_wl6445;
SELECT i FROM t1 ORDER BY i;
--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
--ERROR ER_READ_ONLY_MODE
CREATE TABLE t2 ( i int , j blob) ENGINE = Innodb;
--ERROR ER_CANT_LOCK
UPDATE t1 SET i = i+1;

# Fix in next revision - known ( no data returned)
# SHOW ENGINE INNODB STATUS;
FLUSH STATUS;
FLUSH LOGS;
FLUSH TABLES t1;
FLUSH TABLES WITH READ LOCK;
UNLOCK TABLES;


#------------------------------------------------------------------------------
#cleanup
#------------------------------------------------------------------------------
#
--source include/shutdown_mysqld.inc
# Do something while server is down
--exec chmod 0644 $MYSQLD_DATADIR/ibdata1
--exec chmod 0644 $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
--exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
--source include/start_mysqld.inc
DROP DATABASE testdb_wl6445;


#------------------------------------------------------------------------------
# Testcase covers
# a) Create table/data ,
# b) Remove write permission of ibdata when server is running
# c) Stop the server
# d) Remove write permission of #ib_redo*
# e) Start server in --innodb-read-only mode and verify DDL/DML/DCL in read only mode
#------------------------------------------------------------------------------
--echo case # 2
CREATE DATABASE testdb_wl6445;

USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

# remove write permissions
--exec chmod a-w $MYSQLD_DATADIR/ibdata1
--exec chmod a-w $MYSQLD_DATADIR/testdb_wl6445/t1.ibd

# check dml/ddl after removing write permission
CREATE TABLE t2 ( i int PRIMARY KEY , j blob, KEY k1(j(10)), KEY k2(j(20))) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
SELECT i,LEFT(j,20) FROM t2 ORDER BY i;
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
UPDATE t2 SET i = i + 10;
SELECT i,LEFT(j,20) FROM t2 ORDER BY i;
DELETE FROM t2;
SELECT i,LEFT(j,20) FROM t2 ORDER BY i;

--source include/add_mtr_suppression_for_innodb_readonly.inc

# Force a change buffer merge, so that --innodb-read-only will not
# refuse startup, in case there exist buffered changes from earlier tests.
--source include/shutdown_innodb_clean.inc

--exec chmod a-w $MYSQLD_DATADIR/#innodb_redo/#ib_redo*

--source include/start_innodb_readonly.inc

USE testdb_wl6445;
SELECT i FROM t1 ORDER BY i;
SELECT i FROM t2 ORDER BY i;
--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
--ERROR ER_TABLE_EXISTS_ERROR
CREATE TABLE t2 ( i int , j blob) ENGINE = Innodb;
--ERROR ER_READ_ONLY_MODE
CREATE TABLE t3 ( i int , j blob) ENGINE = Innodb;
--ERROR ER_CANT_LOCK
UPDATE t1 SET i = i+1;

# Fix in next revision - known ( no data returned)
# SHOW ENGINE INNODB STATUS;
FLUSH STATUS;
FLUSH LOGS;
FLUSH TABLES t1,t2;
FLUSH TABLES WITH READ LOCK;
UNLOCK TABLES;


#------------------------------------------------------------------------------
# Testcase covers
# a) Create table/data ,
# b) Remove write permission of ibdata , #ib_redo*
# c) Try to restart server without --innodb-read-only mode
#------------------------------------------------------------------------------
#  Note : write permission is already removed in previous case so we just
#         start server without --innodb-read-only option

--echo case # 3

# We let our server restart attempts write to the file $error_log.
let $error_log= $MYSQLTEST_VARDIR/log/my_restart.err;
# $error_log has to be processed by include/search_pattern.inc which
# contains Perl code requiring that the environment variable SEARCH_FILE points
# to this file.
let SEARCH_FILE= $error_log;

--source include/shutdown_mysqld.inc

--echo #    Try to restart the server without --innodb-read-only after removing
--echo #    write permissions of system tablespace. Server should not start.
--echo #    This confirms server is not automatically started in read-only mode.
#----------------------------------------------------------------------------------
# Detailed explanations of what happens are placed nearby the checks.
--error 1
--exec $MYSQLD_CMD --core-file --loose-console > $error_log 2>&1

# We get depending on the platform either "./ibdata1" or ".\ibdata1".
let SEARCH_PATTERN= The innodb_system data file 'ibdata1' must be writable;
--source include/search_pattern.inc


#------------------------------------------------------------------------------
# Cleanup
#------------------------------------------------------------------------------
#
# Do something while server is down
--exec chmod 0644 $MYSQLD_DATADIR/ibdata1
--exec chmod 0644 $MYSQLD_DATADIR/#innodb_redo/#ib_redo*
--exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
--remove_file $error_log

--source include/start_mysqld.inc
DROP DATABASE testdb_wl6445;