# This test case tests if we handle the corrupted redo logs for dynamic metadata
# of tables(corrupted index bit in this case) correctly. 
# Since we save the data and log files in advance, anything that will modify
# the redo logs (or data file) might make it fail.  If it fails, we can do
# as follow to re-generate the log_corruption_1.zip for it
# 1.  In CorruptedIndexPersister::write(), force it to write a bigger number,
#    such as 100 for the number of corrupted index
# 2.  Add a ut_ad(0) right after log_write_up_to() in dict_set_corrupted()
# 3.  Write a test case which creates a table and try to mark one of its index
#    as corrupted.  Please refer to innodb_corrupt_bit.test
# 4.  Run the test case, it should crash at ut_ad(0)
# 5.  zip the ib* data/log files to log_corruption_1.zip and try again

--echo # We want to test if corrupted redo logs generated by logging corrupted
--echo # indexes can be handled well
let newdir = $MYSQLTEST_VARDIR/tmp/innodb-log-debug-1;
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--mkdir $newdir
let SEARCH_FILE = $newdir/my_restart.err;
--exec unzip $MYSQL_TEST_DIR/std_data/log_corruption/log_corruption_1.zip -d $newdir > $SEARCH_FILE
# In scope of WL#9461,WL#9357, in place upgrade condition
# requires mysql.plugin.frm file.  Create the file manually here
# to allow initialization of innodb. 
--mkdir $newdir/mysql
write_file $newdir/mysql/plugin.frm;
EOF

# We must set '--secure-file-priv=""' here, in case that it will fail on some
# platform sporadically
let $args=--no-defaults --innodb_dedicated_server=OFF --datadir=$newdir --secure-file-priv="" --loose-console --log-error-verbosity=3 > $SEARCH_FILE 2>&1 ;

--error 0,1,42
--exec $MYSQLD $args

--echo # Matching the server logs for corrupted redo logs
let SEARCH_PATTERN= ############### CORRUPT LOG RECORD FOUND ###############;
--source include/search_pattern.inc
let SEARCH_PATTERN= Hex dump starting .*  bytes before and ending .*  bytes after the corrupted record;
--source include/search_pattern.inc
let SEARCH_PATTERN= Set innodb_force_recovery to ignore this error;
--source include/search_pattern.inc

--remove_file $SEARCH_FILE
--force-rmdir $newdir

# End of corrupted redo logs test

