| 1 |
# Test adjusted to 16k pages. |
| 2 |
--source include/have_innodb_16k.inc |
| 3 |
|
| 4 |
# We use DBUG_EXECUTE_IF. |
| 5 |
--source include/have_debug.inc |
| 6 |
|
| 7 |
# Required for the crash just after COMMIT resulting in recovery without rows. |
| 8 |
--source include/not_log_bin.inc |
| 9 |
|
| 10 |
# Currently valgrind has issues with DBUG_SUICIDE(). |
| 11 |
--source include/not_valgrind.inc |
| 12 |
|
| 13 |
--disable_query_log |
| 14 |
--disable_result_log |
| 15 |
|
| 16 |
let $debug_test = 0; |
| 17 |
|
| 18 |
--echo # |
| 19 |
--echo # Scenario 1. Test recovery when recovery starts and ends in the same block as checkpoint_lsn. |
| 20 |
--echo # |
| 21 |
|
| 22 |
let $pass = 0; |
| 23 |
|
| 24 |
while ($pass != 2) { |
| 25 |
|
| 26 |
--echo Pass: $pass |
| 27 |
|
| 28 |
--echo # Initialization - create table, resets autoincrement value. |
| 29 |
CREATE TABLE t (a INT NOT NULL, b INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE = InnoDB; |
| 30 |
INSERT INTO t (a) VALUES (100); |
| 31 |
|
| 32 |
# Enable all METRICS within log module |
| 33 |
SET GLOBAL innodb_monitor_enable = module_log; |
| 34 |
|
| 35 |
--source ../include/log_disable_page_cleaners.inc |
| 36 |
|
| 37 |
--echo # 0. Move to the next log block. |
| 38 |
let $log_fill_block_sql = INSERT INTO t(a) VALUES (101); |
| 39 |
let $log_fill_block_and_crash = 0; |
| 40 |
--source ../include/log_fill_block.inc |
| 41 |
let $start_lsn = $end_lsn; |
| 42 |
|
| 43 |
--echo # 1. Execute tiny mini-transaction in the current block [only pass 0] |
| 44 |
if ($pass == 0) { |
| 45 |
SET AUTOCOMMIT = 0; |
| 46 |
INSERT INTO t (a) VALUES(102); |
| 47 |
|
| 48 |
if ($debug_test) { |
| 49 |
--source ../include/log_read_current_lsn.inc |
| 50 |
--echo State: after writing first mtr to the block |
| 51 |
--echo LSN: $current_lsn |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
--echo # 2. Create checkpoint at the current lsn and block further checkpoints |
| 56 |
SET GLOBAL innodb_page_cleaner_disabled_debug = 0; |
| 57 |
SET GLOBAL innodb_checkpoint_disabled = 0; |
| 58 |
SET GLOBAL innodb_log_checkpoint_now = 1; |
| 59 |
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; |
| 60 |
SET GLOBAL innodb_checkpoint_disabled = 1; |
| 61 |
|
| 62 |
if ($debug_test) { |
| 63 |
--source ../include/log_read_current_lsn.inc |
| 64 |
--source ../include/log_read_checkpoint_lsn.inc |
| 65 |
--echo State: after checkpoint write |
| 66 |
--echo LSN: $current_lsn |
| 67 |
--echo Checkpoint LSN: $checkpoint_lsn |
| 68 |
} |
| 69 |
|
| 70 |
--echo # 3. Execute transaction to force non-trivial crash recovery: 103. |
| 71 |
INSERT INTO t (a) VALUES (103); |
| 72 |
COMMIT; |
| 73 |
|
| 74 |
--source ../include/log_read_current_lsn.inc |
| 75 |
--let $end_lsn = $current_lsn |
| 76 |
if ($debug_test) { |
| 77 |
--echo State: after writing 103 |
| 78 |
--echo LSN: $end_lsn |
| 79 |
} |
| 80 |
|
| 81 |
--let $assert_text = All must happen within the single log block (this was required for the bug) |
| 82 |
--let $assert_cond = [SELECT $start_lsn DIV 512] = [SELECT ($end_lsn + 50) DIV 512] |
| 83 |
--source include/assert.inc |
| 84 |
|
| 85 |
--echo # 5. Crash when trying to insert B. |
| 86 |
SET GLOBAL DEBUG="+d,mtr_commit_crash"; |
| 87 |
--source include/expect_crash.inc |
| 88 |
--error 2013 |
| 89 |
INSERT INTO t (a) VALUES (105); |
| 90 |
|
| 91 |
--echo # 6. Recover 103, write new redo record X during recovery and crash just before flushing page with 103 |
| 92 |
|
| 93 |
# We use a test-specific log_first_rec_group_test DBUG point to add new dummy |
| 94 |
# redo record, force write it to redolog file and then crash. We need to do |
| 95 |
# that before the Persistent Table Metadata that were parsed during recovery, |
| 96 |
# are to be stored inside srv_start. This will allow us to see the |
| 97 |
# AUTO_INCREMENT values after another restart to be incorrect, old. |
| 98 |
--error 2,137 |
| 99 |
--exec $MYSQLD_CMD --debug="+d,log_first_rec_group_test" |
| 100 |
|
| 101 |
--echo # 7. Start recovery and ensure all is recovered - we must recover 103. |
| 102 |
--echo # If first_rec_group was pointing to X we would skip 103. |
| 103 |
--echo # The auto increment value should also be stored properly (with |
| 104 |
--echo # value of 5 in first pass, 4 in second). |
| 105 |
|
| 106 |
--source include/start_mysqld.inc |
| 107 |
|
| 108 |
--enable_query_log |
| 109 |
--enable_result_log |
| 110 |
SELECT * FROM t; |
| 111 |
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't'; |
| 112 |
--disable_query_log |
| 113 |
--disable_result_log |
| 114 |
|
| 115 |
if ($debug_test) { |
| 116 |
--echo State: after recovery |
| 117 |
--echo LSN: $end_lsn |
| 118 |
} |
| 119 |
|
| 120 |
DROP TABLE t; |
| 121 |
inc $pass; |
| 122 |
} |
| 123 |
|
| 124 |
# Note that all global settings (disabled purge, dict_stats etc) are reset because |
| 125 |
# we have restarted mysqld. |
| 126 |
|
| 127 |
--echo # |
| 128 |
--echo # Scenario 2. Restart after writing full log block with record ending at boundary, |
| 129 |
--echo # recovery should start in middle of the last written block (pass 0, 2) |
| 130 |
--echo # or at the beginning of that block (pass 1, 3) and end before the next |
| 131 |
--echo # block (pass 0, 1) or just 12 bytes after its beginning (pass 2, 3). |
| 132 |
--echo # |
| 133 |
|
| 134 |
let $pass = 0; |
| 135 |
|
| 136 |
while ($pass != 4) { |
| 137 |
|
| 138 |
--echo Pass: $pass |
| 139 |
|
| 140 |
--echo # Initialization - create table, resets autoincrement value. |
| 141 |
CREATE TABLE t (a INT NOT NULL, b INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE = InnoDB; |
| 142 |
INSERT INTO t (a) VALUES (200); |
| 143 |
|
| 144 |
# Enable all METRICS within log module |
| 145 |
SET GLOBAL innodb_monitor_enable = module_log; |
| 146 |
|
| 147 |
--source ../include/log_disable_page_cleaners.inc |
| 148 |
|
| 149 |
--echo # 0. Move to the next log block |
| 150 |
let $log_fill_block_sql = INSERT INTO t(a) VALUES (201); |
| 151 |
let $log_fill_block_and_crash = 0; |
| 152 |
--source ../include/log_fill_block.inc |
| 153 |
|
| 154 |
--echo # 1. Execute tiny mini-transaction in the current block [pass 0, 2] |
| 155 |
let $insert_202 = 0; |
| 156 |
if ($pass == 0) { |
| 157 |
let $insert_202 = 1; |
| 158 |
} |
| 159 |
if ($pass == 2) { |
| 160 |
let $insert_202 = 1; |
| 161 |
} |
| 162 |
if ($insert_202 == 1) { |
| 163 |
SET AUTOCOMMIT = 0; |
| 164 |
INSERT INTO t (a) VALUES (202); |
| 165 |
} |
| 166 |
|
| 167 |
# Execute sharp checkpoint (flush all pages) and block further checkpoints |
| 168 |
SET GLOBAL innodb_log_checkpoint_now = 1; |
| 169 |
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; |
| 170 |
SET GLOBAL innodb_checkpoint_disabled = 1; |
| 171 |
|
| 172 |
--echo # 2. Write up to the end of the block. |
| 173 |
let $crash_at_203 = 0; |
| 174 |
if ($pass == 0) { |
| 175 |
let $crash_at_203 = 1; |
| 176 |
} |
| 177 |
if ($pass == 1) { |
| 178 |
let $crash_at_203 = 1; |
| 179 |
} |
| 180 |
|
| 181 |
--echo # 3. Crash on writing next 12 bytes of incomplete block [pass 0, 1]. |
| 182 |
let $log_fill_block_and_crash = $crash_at_203; |
| 183 |
let $log_fill_block_sql = INSERT INTO t(a) VALUES (203); |
| 184 |
--source ../include/log_fill_block.inc |
| 185 |
|
| 186 |
--echo # 4. If we still haven't crashed, force mtr to crash. |
| 187 |
if ($crash_at_203 == 0) { |
| 188 |
SET GLOBAL DEBUG = "+d,mtr_commit_crash"; |
| 189 |
--source include/expect_crash.inc |
| 190 |
--error 2013 |
| 191 |
INSERT INTO t (a) VALUES (204); |
| 192 |
} |
| 193 |
|
| 194 |
--echo # 5. Start MySQL after crash to see how it takes care of recovery |
| 195 |
--source include/start_mysqld.inc |
| 196 |
|
| 197 |
--enable_query_log |
| 198 |
--enable_result_log |
| 199 |
SELECT * FROM t; |
| 200 |
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't'; |
| 201 |
--disable_query_log |
| 202 |
--disable_result_log |
| 203 |
|
| 204 |
DROP TABLE t; |
| 205 |
inc $pass; |
| 206 |
} |
| 207 |
|
| 208 |
# Note that all global settings (disabled purge, dict_stats etc) are reset because |
| 209 |
# we have restarted mysqld. |
| 210 |
|
| 211 |
--echo # Cleanup... |
| 212 |
|
| 213 |
--enable_query_log |
| 214 |
--enable_result_log |