File: innodb_read_only-1.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 (661 lines) | stat: -rw-r--r-- 21,999 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
######## suite/innodb/t/innodb-wl6445-1                     ##########
#                                                                    #
# Testcase for worklog WL#6445: InnoDB should be able to work with   #
# read-only tables
# All sub-test in this file focus on restarting server in read only  #
# and verify necessary operations blocked                            #
# operations                                                         #
#                                                                    #
#                                                                    #
# Creation:                                                          #
# 2011-09-06 Implemented this test as part of WL#6445                #
#                                                                    #
######################################################################

# This test takes long time, so only run it with the --big-test mtr-flag.
--source include/big_test.inc

let MYSQLD_DATADIR =`SELECT @@datadir`;
let $innodb_file_per_table = `SELECT @@innodb_file_per_table`;
let $innodb_flush_log_at_trx_commit_orig =`select @@innodb_flush_log_at_trx_commit`;

SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;

let $MYSQLD_DATADIR = `SELECT @@datadir`;
let $data_index_directory = DATA DIRECTORY='$MYSQL_TMP_DIR/alt_dir';

CREATE DATABASE testdb_wl6445;


#------------------------------------------------------------------------------
# Testcase 1 covers
# a) Create table/data , restart server in readonly mode
# b) verify DDL/DML/DCL in read only mode
# c) statements blocked for non root and root user from differet sessions.
#------------------------------------------------------------------------------
--echo case # 1
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j blob) 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;

# Create user with minimun access
CREATE USER 'test1'@'localhost' IDENTIFIED BY '123';
GRANT ALL ON testdb_wl6445.* TO 'test1'@'localhost';
# Create user with root access
CREATE USER 'test2'@'localhost' IDENTIFIED BY '123';
GRANT ALL ON *.* TO 'test2'@'localhost';

# check when datadir and index dir are specified
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
EVAL CREATE TABLE otherlocation (id int PRIMARY KEY)
ENGINE=InnoDB , $data_index_directory;
INSERT INTO otherlocation VALUES (1),(2),(3);
SELECT * FROM otherlocation ORDER BY id;

#SHOW ENGINE INNODB STATUS;

#

--source include/restart_innodb_read_only.inc

SET GLOBAL innodb_file_per_table = 1;

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;

# User-manipulation statements are disallowed since ACL tables use InnoDB.
--error ER_ACL_OPERATION_FAILED
CREATE USER 'test3'@'localhost' IDENTIFIED BY '123';

--echo # connection con_test1_user try to modify
--connect (con_test1_user,'localhost','test1','123',)
SELECT user();
USE testdb_wl6445;
--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;

--echo # disconnect con_test1_user
--disconnect con_test1_user


--echo # connection con_test2_user
--connect (con_test2_user,'localhost','test2','123',)
SELECT user();
USE testdb_wl6445;
--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;


--echo # disconnect con_test2_user
--disconnect con_test2_user


--echo # connection default
--connection default
USE testdb_wl6445;
--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;

# check with table having data and index directory specified
--ERROR ER_CANT_LOCK
INSERT INTO otherlocation VALUES (1),(2),(3);
SELECT * FROM otherlocation ORDER BY id;

# 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;


#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
#

--source include/restart_mysqld.inc
DROP USER 'test1'@'localhost';
DROP USER 'test2'@'localhost';
DROP DATABASE testdb_wl6445;


#------------------------------------------------------------------------------
# Testcase 2 covers
# a) Create table/data , perform transaction , restart server in readonly mode
# b) verfiy DDL/DML/DCL in read only mode
#------------------------------------------------------------------------------
--echo case # 2
CREATE DATABASE testdb_wl6445;

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


START TRANSACTION;
let $counter= 50;
--disable_query_log
while ($counter>3) {
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --dec $counter
}
--enable_query_log
SAVEPOINT A;
let $counter= 100;
--disable_query_log
while ($counter>50) {
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --dec $counter
}
--enable_query_log
SAVEPOINT B;
ROLLBACK TO A;
--echo "---commit first 50 records "
COMMIT;


SELECT COUNT(*) FROM testdb_wl6445.t1;
#SHOW ENGINE INNODB STATUS;

#

--source include/restart_innodb_read_only.inc

USE testdb_wl6445;
--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (211,repeat('a',200)),(212,repeat('b',200)),(213,repeat('c',200));
SELECT i,LEFT(j,20) FROM t1 WHERE i%10=0 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;

SELECT i,LEFT(j,20) FROM t1  WHERE i%10=0  ORDER BY i;

# Check with transaction in read-only mode with innodb_flush_log_at_trx_commit=0
START TRANSACTION;
SET GLOBAL innodb_flush_log_at_trx_commit = 0;
let $counter= 200;
--disable_query_log
while ($counter>150) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT A;
let $counter= 250;
--disable_query_log
while ($counter>200) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT B;
ROLLBACK TO A;
--echo "---commit first 50 records with innodb_flush_log_at_trx_commit = 0 --"
COMMIT;

SELECT i,LEFT(j,20) FROM t1  WHERE i%10=0  ORDER BY i;

# Check with transaction in read-only mode with innodb_flush_log_at_trx_commit=1
START TRANSACTION;
SET GLOBAL innodb_flush_log_at_trx_commit = 1;
let $counter= 200;
--disable_query_log
while ($counter>150) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT A;
let $counter= 250;
--disable_query_log
while ($counter>200) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT B;
ROLLBACK TO A;
--echo "---commit first 50 records with innodb_flush_log_at_trx_commit = 1 --"
COMMIT;

SELECT i,LEFT(j,20) FROM t1  WHERE i%10=0  ORDER BY i;

# Check with transaction in read-only mode with innodb_flush_log_at_trx_commit=2
START TRANSACTION;
SET GLOBAL innodb_flush_log_at_trx_commit = 2;
let $counter= 200;
--disable_query_log
while ($counter>150) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT A;
let $counter= 250;
--disable_query_log
while ($counter>200) {
   --ERROR ER_CANT_LOCK
   EVAL INSERT INTO testdb_wl6445.t1 VALUES ($counter,repeat(CONCAT('a',$counter),2000));
   --ERROR ER_CANT_LOCK
   UPDATE testdb_wl6445.t1 SET i = i + 1;
   --ERROR ER_CANT_LOCK
   DELETE FROM testdb_wl6445.t1;
   --dec $counter
}
--enable_query_log
SAVEPOINT B;
ROLLBACK TO A;
--echo "---commit first 50 records with innodb_flush_log_at_trx_commit = 2 --"
COMMIT;


# 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;

#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
#
--source include/restart_mysqld.inc
DROP DATABASE testdb_wl6445;

#------------------------------------------------------------------------------
# Testcase 3 covers
# a) Create table/data with trigger & procedure, partitioned table
# b) restart server in readonly mode
# c) verfiy behavior with trigger,procedure,partitioned and temp table
#------------------------------------------------------------------------------
--echo case # 3
CREATE DATABASE testdb_wl6445;
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j blob) ENGINE = InnoDB;
CREATE TABLE t2 ( t2_i int PRIMARY KEY , t2_j blob) ENGINE = InnoDB;
CREATE TABLE t3 ( i int PRIMARY KEY , j VARCHAR(20)) ENGINE = InnoDB;

# create partitioned table
CREATE TABLE t4 (val INT)
PARTITION BY LIST(val)(
         PARTITION mypart_odd VALUES IN (1,3,5),
         PARTITION MyPart_even VALUES IN (2,4,6));
INSERT INTO testdb_wl6445.t4 VALUES (1),(2),(3),(4),(5),(6);
SELECT * FROM testdb_wl6445.t4 ORDER BY val;

DELIMITER //;
CREATE TRIGGER TRIGGER_1 BEFORE INSERT ON testdb_wl6445.t1 FOR EACH ROW BEGIN
INSERT INTO testdb_wl6445.t2 SET t2_i = NEW.i , t2_j = NEW.j;
END;//
CREATE PROCEDURE proc1 (OUT param1 INT)
BEGIN
SELECT COUNT(*) INTO param1 FROM testdb_wl6445.t1;
END;//
CREATE PROCEDURE proc2 (IN param1 INT,IN param2 VARCHAR(20))
BEGIN
INSERT INTO testdb_wl6445.t3 VALUES (param1,param2);
END;//
DELIMITER ;//

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;
SELECT t2_i,LEFT(t2_j,20) FROM t2 ORDER BY t2_i;
CALL proc1(@a);
SELECT @a;
CALL proc2(1,'test1');
SELECT * FROM t3;

#SHOW ENGINE INNODB STATUS;

#

--source include/restart_innodb_read_only.inc

SET GLOBAL innodb_file_per_table = 1;
USE testdb_wl6445;
--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;
SELECT t2_i,LEFT(t2_j,20) FROM t2 ORDER BY t2_i;
CALL proc1(@a);
SELECT @a;
--ERROR ER_CANT_LOCK
CALL proc2(2,'test2');
SELECT * FROM t3;

# try to CREATE temp table
--ERROR ER_INNODB_READ_ONLY
CREATE TEMPORARY TABLE temp_1 ( i INT ) ENGINE = Innodb;

# Try to insert with partitioned table
--ERROR ER_CANT_LOCK
INSERT INTO testdb_wl6445.t4 VALUES (1),(2),(3),(4),(5),(6);
SELECT * FROM testdb_wl6445.t4 ORDER BY val;

FLUSH STATUS;
FLUSH LOGS;
FLUSH TABLES t1,t2,t3;
FLUSH TABLES WITH READ LOCK;
UNLOCK TABLES;


#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
#

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

#------------------------------------------------------------------------------
# Testcase 4 covers
# a) Create table/data restart server in readonly mode
# b) check the effect of server variables impacting change of RO
#    ( they will be ignored)
#------------------------------------------------------------------------------
--echo case # 4
CREATE DATABASE testdb_wl6445;
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j VARCHAR(300), FULLTEXT KEY (j)) ENGINE = InnoDB;
CREATE INDEX idx1 ON testdb_wl6445.t1(i);
INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
INSERT INTO t1 VALUES (4,'mysql database'),(5,'mysql database innodb support'),(6,'innodb engine');
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

#FTS Query
SELECT * FROM t1 WHERE MATCH (j) AGAINST ('mysql (+database -innodb)' IN BOOLEAN MODE) ;

# store initial values
let $innodb_max_purge_lag_orig = `SELECT @@innodb_max_purge_lag`;
let $innodb_max_purge_lag_delay_orig = `SELECT @@innodb_max_purge_lag_delay`;
let $innodb_purge_batch_size_orig = `select @@innodb_purge_batch_size`;
let $innodb_purge_threads_orig = `SELECT @@innodb_purge_threads`;
let $relay_log_purge_orig = `select @@relay_log_purge`;
let $innodb_buffer_pool_size_orig = `select @@innodb_buffer_pool_size`;
let $innodb_change_buffer_max_size_orig = `select @@innodb_change_buffer_max_size`;
let $innodb_change_buffering_orig = `select @@innodb_change_buffering`;
let $innodb_print_all_deadlocks_orig = `select @@innodb_print_all_deadlocks`;


let $extra_restart_parameters = --innodb_purge_threads=5 --innodb_buffer_pool_size=16M;
--source include/restart_innodb_read_only.inc
let $extra_restart_parameters = ;

SET GLOBAL innodb_max_purge_lag = 10;
SET GLOBAL innodb_max_purge_lag_delay = 10;
SET GLOBAL innodb_purge_batch_size = 600;
# purge thread is read only variable
#SET GLOBAL innodb_purge_threads = 5;
SET GLOBAL relay_log_purge = 0;
SET GLOBAL innodb_change_buffer_max_size = 30;
SET GLOBAL innodb_change_buffering = 'changes';
SET GLOBAL innodb_print_all_deadlocks = 'ON';


USE testdb_wl6445;
--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
--ERROR ER_CANT_LOCK
UPDATE t1 SET i = i + 1;
--ERROR ER_CANT_LOCK
DELETE FROM t1 ;


SELECT @@innodb_max_purge_lag,@@innodb_max_purge_lag_delay,@@innodb_purge_batch_size,
@@innodb_purge_threads,@@relay_log_purge,@@innodb_buffer_pool_size,
@@innodb_change_buffer_max_size,@@innodb_change_buffering,@@innodb_print_all_deadlocks;

SELECT i,LEFT(j,20) FROM t1 ORDER BY i;

#FTS Query
SELECT * FROM t1 WHERE MATCH (j) AGAINST ('mysql (+database -innodb)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (j) AGAINST ('innodb') ;

# restore initial values
--disable_query_log
eval SET GLOBAL innodb_max_purge_lag=$innodb_max_purge_lag_orig;
eval SET GLOBAL innodb_max_purge_lag_delay=$innodb_max_purge_lag_delay_orig;
eval SET GLOBAL innodb_purge_batch_size = $innodb_purge_batch_size_orig;
#eval SET GLOBAL innodb_purge_threads = $innodb_purge_threads_orig;
eval SET GLOBAL relay_log_purge = $relay_log_purge_orig;
eval SET GLOBAL innodb_change_buffer_max_size = $innodb_change_buffer_max_size_orig;
eval SET GLOBAL innodb_change_buffering = $innodb_change_buffering_orig;
eval SET GLOBAL innodb_print_all_deadlocks = $innodb_print_all_deadlocks_orig;
--enable_query_log


#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
#

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

#------------------------------------------------------------------------------
# Testcase 5 covers
# a) Create table/data restart server in readonly mode
# b) check starting with both --read-only and --innodb-read-only
# c) check starting with only --read-only
#------------------------------------------------------------------------------
--echo case # 5
CREATE DATABASE testdb_wl6445;
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY , j VARCHAR(300), FULLTEXT KEY (j)) ENGINE = InnoDB;
CREATE INDEX idx1 ON testdb_wl6445.t1(i);
INSERT INTO t1 VALUES (1,repeat('a',200)),(2,repeat('b',200)),(3,repeat('c',200));
INSERT INTO t1 VALUES (4,'mysql database'),(5,'mysql database innodb support'),(6,'innodb engine');
#FTS Query
SELECT * FROM t1 WHERE MATCH (j) AGAINST ('mysql (+database -innodb)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (j) AGAINST ('innodb') ;

let $extra_restart_parameters = --read-only;
--source include/restart_innodb_read_only.inc
let $extra_restart_parameters = ;
USE testdb_wl6445;
show tables;
select * from t1 where i = 4;
# check if root user able to modify
--ERROR ER_CANT_LOCK
INSERT INTO t1 VALUES (11,repeat('a',200)),(12,repeat('b',200)),(13,repeat('c',200));
--ERROR ER_CANT_LOCK
UPDATE t1 SET i = i + 20;
--ERROR ER_CANT_LOCK
DELETE FROM t1;
--ERROR ER_READ_ONLY_MODE
CREATE TABLE t2 ( i INT ) ENGINE = Innodb;

# User-manipulation statements are disallowed since ACL tables use InnoDB.
--error ER_ACL_OPERATION_FAILED
CREATE USER 'test5'@'localhost' IDENTIFIED BY '123';

let $restart_parameters = restart: --read-only;
--source include/restart_mysqld.inc
let $restart_parameters = restart;
USE testdb_wl6445;
# check if root user able to do DML/DDL
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;
UPDATE t1 SET i = i + 20;
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
DELETE FROM t1;
SELECT i,LEFT(j,20) FROM t1 ORDER BY i;
CREATE TABLE t2 ( i INT ) ENGINE = Innodb;
CREATE USER 'test5_2'@'localhost' IDENTIFIED BY '123';
GRANT ALL ON testdb_wl6445.* TO 'test5_2'@'localhost';


#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
#

--source include/restart_mysqld.inc
DROP USER 'test5_2'@'localhost';
DROP DATABASE testdb_wl6445;

#------------------------------------------------------------------------------
# Testcase 6 covers
# a) Create table/data restart server in readonly mode
# b) check mysqldump/mysqlimport work
#------------------------------------------------------------------------------
--echo case # 6
CREATE DATABASE testdb_wl6445;
USE testdb_wl6445;
CREATE TABLE t1 ( i int PRIMARY KEY ) ENGINE = InnoDB;
CREATE INDEX idx1 ON testdb_wl6445.t1(i);
INSERT INTO t1 VALUES (1),(2),(3);
SELECT i FROM t1 ORDER BY i;

--echo # Creating a temp sql file to be loaded.
--write_file $MYSQLTEST_VARDIR/tmp/t1.sql
11
12
13
EOF


--source include/restart_innodb_read_only.inc

USE testdb_wl6445;
# try mysql import
--replace_regex /.*Error//i
--error 1
--exec $MYSQL_IMPORT -uroot testdb_wl6445 $MYSQLTEST_VARDIR/tmp/t1.sql 2>&1
# only 3 records get in select as import shoudl fail due to --innodb-read-only
SELECT i FROM t1 ORDER BY i;


# mysqldump works
--exec $MYSQL_DUMP --skip-comments --databases testdb_wl6445 > $MYSQLTEST_VARDIR/tmp/testdb_wl6445_dump.txt

--error 0,1
--remove_file $MYSQLTEST_VARDIR/tmp/testdb_wl6445_dump.txt
--error 0,1
--remove_file $MYSQLTEST_VARDIR/tmp/t1.sql

#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
--source include/restart_mysqld.inc
DROP DATABASE testdb_wl6445;
--rmdir $MYSQL_TMP_DIR/alt_dir/testdb_wl6445
--rmdir $MYSQL_TMP_DIR/alt_dir
--disable_query_log
eval SET GLOBAL INNODB_FILE_PER_TABLE=$innodb_file_per_table;
eval SET GLOBAL innodb_flush_log_at_trx_commit = $innodb_flush_log_at_trx_commit_orig;
call mtr.add_suppression("deleting orphaned .ibd file");
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Cannot open datafile for read-only:");
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Operating system error number 2 in a file operation.");
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* The error means the system cannot find the path specified.");
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* If you are installing InnoDB, remember that you must create directories yourself, InnoDB does not create them.");
--enable_query_log


#------------------------------------------------------------------------------
# Testcase 7 covers
# a) Create/Load table in normal mode such that index level > 1.
# b) Restart server in read-only mode and try to check validity of table/data.
#------------------------------------------------------------------------------
--echo case # 7 (restart server in read-only mode and perform check table)
use test;
#
create table t1 (
	i int,
	f float,
	c char(100),
	b blob
	) engine = innodb;
#
delimiter |;
CREATE PROCEDURE populate_t1()
BEGIN
        DECLARE i INT DEFAULT 1;
        while (i <= 100) DO
                insert into t1 values (
		i, 2.323,
		'adfaqfafafafafsasfafsa',
		'badfadfsaeerer234234asdfdsafdasr2354234324234234');
                SET i = i + 1;
        END WHILE;
END|
delimiter ;|
begin;
call populate_t1();
commit;
check table t1 extended;
#
#
--source include/restart_innodb_read_only.inc
#
check table t1 extended;

#------------------------------------------------------------------------------
# clean-up
#------------------------------------------------------------------------------
let $restart_parameters = restart;
--source include/restart_mysqld.inc
check table t1 extended;
drop table t1;
drop procedure populate_t1;