--echo # Testcase for the following bugs
--echo # Bug#16691130 - ASSERT WHEN INNODB_LOG_GROUP_HOME_DIR DOES NOT EXIST
--echo # Bug#16418661 - CHANGING NAME IN FOR INNODB_DATA_FILE_PATH SHOULD NOT SUCCEED WITH LOG FILES

--source include/have_innodb.inc
let bugdir= $MYSQLTEST_VARDIR/tmp/log_file;
--mkdir $bugdir

let SEARCH_FILE = $bugdir/my_restart.err;
let $args=--defaults-file=$bugdir/my.cnf --datadir=$bugdir --loose-console --core-file --loose-skip-auto_generate_certs --loose-skip-sha256_password_auto_generate_rsa_keys --secure-file-priv="" > $SEARCH_FILE 2>&1 ;

--echo # Write tmp/log_file/my.cnf
--write_file $bugdir/my.cnf
[mysqld]
EOF

--exec echo "innodb_data_home_dir = $bugdir" >> $bugdir/my.cnf

--append_file $bugdir/my.cnf
innodb_data_file_path = ibdata1:10M;ibdata2:10M:autoextend
innodb_rollback_segments = 20
innodb_undo_tablespaces = 3
innodb_log_files_in_group = 3
EOF

--echo # Start mysqld without the possibility to create innodb_undo_tablespaces
--mkdir $bugdir/undo002
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=\[ERROR\] InnoDB: Could not create undo tablespace '.*undo002';
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

--echo # Remove  undo001,undo002,ibdata1,ibdata2,ib_logfile1,ib_logfile2,ib_logfile101
--remove_file $bugdir/undo001
--rmdir $bugdir/undo002
--remove_file $bugdir/ibdata1
--remove_file $bugdir/ibdata2
--remove_file $bugdir/ib_logfile1
--remove_file $bugdir/ib_logfile2
--remove_file $bugdir/ib_logfile101
--list_files $bugdir

--echo # Start mysqld with non existent innodb_log_group_home_dir
--error 1
--exec $MYSQLD $args --innodb_log_group_home_dir=/path/to/non-existent/
let SEARCH_PATTERN=File .path.to.non-existent.*ib_logfile101: 'create' returned OS error \d+;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

--echo # Remove ibdata1 & ibdata2
--remove_file $bugdir/ibdata1
--remove_file $bugdir/ibdata2
--list_files $bugdir

# Innodb creates system tablespaces according to my.cnf and aborts
# complaining about mysql.* tables. This is sufficient for testing
# missing tablespaces.
--echo # Start mysqld to create tablespaces according to my.cnf
--error 1
--exec $MYSQLD $args --skip-grant-tables --innodb-unknown-parameter
let SEARCH_PATTERN=unknown option '--innodb-unknown-parameter';
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

--echo # Backup tmp/logfile/*
--copy_file $bugdir/ibdata1 $bugdir/bak_ibdata1
--copy_file $bugdir/ibdata2 $bugdir/bak_ibdata2
--copy_file $bugdir/ib_logfile0 $bugdir/bak_ib_logfile0
--copy_file $bugdir/ib_logfile1 $bugdir/bak_ib_logfile1
--copy_file $bugdir/ib_logfile2 $bugdir/bak_ib_logfile2
--copy_file $bugdir/undo001 $bugdir/bak_undo001
--copy_file $bugdir/undo002 $bugdir/bak_undo002
--copy_file $bugdir/undo003 $bugdir/bak_undo003

--echo # 1. With ibdata2, Without ibdata1
--remove_file $bugdir/ibdata1
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=The innodb_system data file 'ibdata1' was not found but one of the other data files 'ibdata2' exists;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 2. With ibdata1, without ibdata2
--remove_file $bugdir/ibdata2
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=Tablespace size stored in header is \d+ pages, but;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 3. Without ibdata1 & ibdata2
--remove_file $bugdir/ibdata1
--remove_file $bugdir/ibdata2
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=undo tablespace .*undo001.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 4. Without ibdata*, ib_logfile* and with undo00*
--remove_files_wildcard $bugdir ibdata*
--remove_files_wildcard $bugdir ib_logfile*
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=undo tablespace .*undo001.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc


--echo # 5. Without ibdata*,ib_logfile* files & Without undo002
--remove_files_wildcard $bugdir ibdata*
--remove_files_wildcard $bugdir ib_logfile*
--remove_file $bugdir/undo002
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=undo tablespace .*undo001.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 6. Without ibdata*,ib_logfile* files & Without undo001, undo002
# and with undo003
--remove_files_wildcard $bugdir ibdata*
--remove_files_wildcard $bugdir ib_logfile*
--remove_file $bugdir/undo001
--remove_file $bugdir/undo002
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=undo tablespace .*undo003.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 7. With ibdata files & Without undo002
--remove_file $bugdir/undo002
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=Expected to open 3 undo tablespaces but was able;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=to find only 1 undo tablespaces;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc
# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 8. With ibdata files & Without undo001, undo002
--remove_file $bugdir/undo001
--remove_file $bugdir/undo002
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=Expected to open 3 undo tablespaces but was able;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=to find only 0 undo tablespaces;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 9. Without ibdata*, without undo*, Without ib_logfile1 and with ib_logfile2
--remove_files_wildcard $bugdir ibdata*
--remove_files_wildcard $bugdir undo00*
--remove_file $bugdir/ib_logfile1
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=redo log file .*ib_logfile0.* exists\. Creating system tablespace with existing redo log files is not recommended\. Please delete all redo log files before creating new system tablespace\.;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

# 10. With ibdata*, without ib_logfile0
#--remove_file $bugdir/ib_logfile0
# The below would start the server. Since we cannot start a parallel
# server, do not test the below case
#--error 1
#--exec $MYSQLD $args

# clean up & Restore
#--source ../include/log_file_cleanup.inc

--echo # 11. With ibdata*, without ib_logfile1
--remove_file $bugdir/ib_logfile1
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=Only one log file found;
--source include/search_pattern_in_file.inc
let SEARCH_PATTERN=\[ERROR\] Aborting;
--source include/search_pattern_in_file.inc

# clean up & Restore
--source ../include/log_file_cleanup.inc

--echo # 12. With ibdata*, without ib_logfile2
--remove_file $bugdir/ib_logfile2
--list_files $bugdir
--error 1
--exec $MYSQLD $args
let SEARCH_PATTERN=Resizing redo log from \d+\*\d+ to \d+\*\d+ pages, LSN=\d+;
--source include/search_pattern_in_file.inc

--echo # Cleanup
# Remove ibtmp* which are re-generated after each mysqld invocation
# skip auto generated auto.cnf from list_files
--remove_files_wildcard $bugdir auto.cnf
--remove_files_wildcard $bugdir ibtmp*
--list_files $bugdir
--remove_files_wildcard $bugdir
--rmdir $bugdir
