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

199 lines
7.3 KiB
Plaintext

######## 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 changinf 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) remove write permission of ibdata , ib_logfile0
# c) restart 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;
# 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/ib_logfile0
#
--source include/restart_innodb_read_only.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/ib_logfile0
--exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
let $restart_parameters = restart;
--source include/start_mysqld.inc
DROP DATABASE testdb_wl6445;
#------------------------------------------------------------------------------
# Testcase covers
# a) Create table/data ,
# b) remove write permission of ibdata , ib_logfile0 when server is running
# c) restart server in --innodb-read-only mode and verfiy 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
--exec chmod a-w $MYSQLD_DATADIR/ib_logfile0
#
# 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/restart_innodb_read_only.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_logfile0
# 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/ib_logfile0
--exec chmod 0660 $MYSQLD_DATADIR/testdb_wl6445/t1.ibd
--remove_file $error_log
let $restart_parameters = restart;
--source include/start_mysqld.inc
DROP DATABASE testdb_wl6445;