|
| 1 | +# |
| 2 | +# The macro processes a DDL statement while its handling is |
| 3 | +# interrupted by simulated crashes at time of the query |
| 4 | +# has not yet been logged and upon that. |
| 5 | +# The first, pre-binlog crash happens right after prepare in SEs |
| 6 | +# (storage engines), before binary log event for the statement is |
| 7 | +# flushed to the disk. In this case statement should be correctly |
| 8 | +# rolled back by recovery. The second, post-binlog crash to the |
| 9 | +# repeated statement occurs after binary log event is flushed to the |
| 10 | +# disk, before commit in the SEs. |
| 11 | +# The query results must be found committed upon the server restart. |
| 12 | +# The binlog is rotated at the beginning of either crash simulation |
| 13 | +# and its resulted file is memorized to optionally print out |
| 14 | +# its events which must contain a new XID field. |
| 15 | +# |
| 16 | +# Another purpose of the macro to run simply as a load |
| 17 | +# generator e.g for a slave server without crash simulations |
| 18 | +# ($do_only_regular_logging). |
| 19 | +# |
| 20 | +# The macro increments |
| 21 | +# $count_ddl_queries |
| 22 | +# per its invocation which serves as a counter for the number of |
| 23 | +# processed queries. |
| 24 | +# |
| 25 | +# Usage, e.g: |
| 26 | +# |
| 27 | +# --let $do_pre_binlog=1 |
| 28 | +# --let $do_post_binlog=1 |
| 29 | +# --let $do_only_regular_logging=1 # run only query no crash simulation |
| 30 | +# --let $ddl_query=CREATE USER user1 |
| 31 | +# --let $pre_binlog_crash_check= [SELECT count(*) = 0 FROM mysql.user WHERE user = 'user1'] |
| 32 | +# --let $post_binlog_crash_check= [SELECT count(*) = 1 FROM mysql.user WHERE user = 'user1'] |
| 33 | +# |
| 34 | +# --let $do_show_binlog_events=1 # invoke show-binlog-events at the |
| 35 | +# # end of query execution |
| 36 | +# --let $do_count_queries # When set the processed queries are counted in $count_ddl_queries |
| 37 | +# --let $master_log_table # DDL query and post-recovery checks can be logged in a table |
| 38 | +# --let $master_log_db # The database of the log table |
| 39 | +# |
| 40 | +# here a value in [] can be just empty to indicate no check after |
| 41 | +# the corresponding crash is done. |
| 42 | +# |
| 43 | + |
| 44 | +if ($do_count_queries) |
| 45 | +{ |
| 46 | + --inc $count_ddl_queries |
| 47 | +} |
| 48 | + |
| 49 | +--disable_query_log |
| 50 | +if ($master_log_table) |
| 51 | +{ |
| 52 | + --let $save_curr_db=`SELECT database()` |
| 53 | + if ($master_log_db) |
| 54 | + { |
| 55 | + --eval USE $master_log_db |
| 56 | + } |
| 57 | + --eval INSERT INTO $master_log_table SET id= NULL, ddl_query= "$ddl_query", pre_binlog_check= "$pre_binlog_crash_check", post_binlog_check= "$post_binlog_crash_check" |
| 58 | + --eval USE $save_curr_db |
| 59 | +} |
| 60 | +--enable_query_log |
| 61 | + |
| 62 | +# $do_only_regular_logging is incompatible with crash simulating $do:s. |
| 63 | +if ($do_only_regular_logging) |
| 64 | +{ |
| 65 | + if ($do_pre_binlog) |
| 66 | + { |
| 67 | + --echo *** Wrong option combination! *** |
| 68 | + --die |
| 69 | + } |
| 70 | + if ($do_post_binlog) |
| 71 | + { |
| 72 | + --echo *** Wrong option combination! *** |
| 73 | + --die |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +--source include/gtid_step_reset.inc |
| 78 | + |
| 79 | +if ($do_pre_binlog) |
| 80 | +{ |
| 81 | + FLUSH LOGS; |
| 82 | + --let $binlog_file= query_get_value("SHOW MASTER STATUS", File, 1) |
| 83 | + |
| 84 | + # |
| 85 | + # prepare, the first CRASH, /* log, commit */ |
| 86 | + # |
| 87 | + --echo *** Crash right after '$ddl_query' has been prepared in the engine before being logged *** |
| 88 | + --source include/expect_crash.inc |
| 89 | + |
| 90 | + SET @@SESSION.debug="+d,crash_commit_before_log"; |
| 91 | + --disable_query_log |
| 92 | + if ($manual_gtid_next) |
| 93 | + { |
| 94 | + --eval $manual_gtid_next |
| 95 | + } |
| 96 | + --enable_query_log |
| 97 | + --error 2013 |
| 98 | + --eval $ddl_query |
| 99 | + |
| 100 | + # |
| 101 | + # restart the server |
| 102 | + # |
| 103 | + --source include/start_mysqld.inc |
| 104 | + |
| 105 | + if ($pre_binlog_crash_check) |
| 106 | + { |
| 107 | + if (!`$pre_binlog_crash_check`) |
| 108 | + { |
| 109 | + --echo *** State check upon recovery after pre-binlog crash fails *** |
| 110 | + --die |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + if ($do_show_binlog_events) |
| 115 | + { |
| 116 | + --let $keep_ddl_xid=1 |
| 117 | + --let $show_binlog_events_mask_columns=1,2,4,5 |
| 118 | + --source include/show_binlog_events.inc |
| 119 | + } |
| 120 | + |
| 121 | + # The Gtid check, when its mode ON. |
| 122 | + # After rollback-recovery of this branch Gtid executed must |
| 123 | + # remain as was before the query execution. |
| 124 | + --let $gtid_step_count=0 |
| 125 | + --source include/gtid_step_assert.inc |
| 126 | + |
| 127 | +} # end of $do_pre_binlog |
| 128 | + |
| 129 | +if ($do_post_binlog) |
| 130 | +{ |
| 131 | + FLUSH LOGS; |
| 132 | + --let $binlog_file= query_get_value("SHOW MASTER STATUS", File, 1) |
| 133 | + |
| 134 | + # |
| 135 | + # prepare, log, the 2nd CRASH, /* commit */ |
| 136 | + # |
| 137 | + --echo *** Crash right after '$ddl_query' has been binary-logged before committed in the engine *** |
| 138 | + --source include/expect_crash.inc |
| 139 | + |
| 140 | + SET @@SESSION.debug="+d,crash_commit_after_log"; |
| 141 | + # End of Debug |
| 142 | + --disable_query_log |
| 143 | + if ($manual_gtid_next) |
| 144 | + { |
| 145 | + --eval $manual_gtid_next |
| 146 | + } |
| 147 | + --enable_query_log |
| 148 | + --error 2013 |
| 149 | + --eval $ddl_query |
| 150 | + |
| 151 | + # |
| 152 | + # restart the server |
| 153 | + # |
| 154 | + --source include/start_mysqld.inc |
| 155 | + |
| 156 | + if ($post_binlog_crash_check) |
| 157 | + { |
| 158 | + if (!`$post_binlog_crash_check`) |
| 159 | + { |
| 160 | + --echo *** State check upon recovery after pre-commit crash fails *** |
| 161 | + --die |
| 162 | + } |
| 163 | + } |
| 164 | + if ($do_show_binlog_events) |
| 165 | + { |
| 166 | + --let $keep_ddl_xid=1 |
| 167 | + --let $show_binlog_events_mask_columns=1,2,4,5 |
| 168 | + --source include/show_binlog_events.inc |
| 169 | + } |
| 170 | + |
| 171 | + # The Gtid check, when its mode ON. |
| 172 | + # After commit-recovery of this branch Gtid executed must |
| 173 | + # receive a new gtid item of the current DDL transaction. |
| 174 | + |
| 175 | + --let $gtid_step_count=1 |
| 176 | + --source include/gtid_step_assert.inc |
| 177 | + |
| 178 | +} # end of $do_post_binlog |
| 179 | + |
| 180 | +if ($do_only_regular_logging) |
| 181 | +{ |
| 182 | + FLUSH LOGS; |
| 183 | + --eval $ddl_query |
| 184 | + if ($do_show_binlog_events) |
| 185 | + { |
| 186 | + --let $keep_ddl_xid=1 |
| 187 | + --let $show_binlog_events_mask_columns=1,2,4,5 |
| 188 | + --source include/show_binlog_events.inc |
| 189 | + } |
| 190 | + |
| 191 | + # The Gtid check, when its mode ON. |
| 192 | + # After commit-recovery of this branch Gtid executed must |
| 193 | + # receive a new gtid item of the current DDL transaction. |
| 194 | + |
| 195 | + --let $gtid_step_count=1 |
| 196 | + --source include/gtid_step_assert.inc |
| 197 | +} |
| 198 | + |
| 199 | +# |
| 200 | +# Cleanup |
| 201 | +# |
| 202 | +--let $keep_ddl_xid= |
| 203 | +--let $show_binlog_events_mask_columns= |
0 commit comments