1 ################### include/rpl_stmt_seq.inc ###########################
3 # Check if a given SQL statement (->$my_stmt) / AUTOCOMMIT mode / #
4 # storage engine somehow involved causes COMMIT or ROLLBACK. #
7 # The typical test sequence #
8 # ------------------------- #
9 # 1. master connection: INSERT without commit #
10 # check table content of master and slave #
11 # 2. master connection: EXECUTE the statement #
12 # check table content of master and slave #
13 # 3. master connection: ROLLBACK #
14 # check table content of master and slave #
18 # $show_binlog -- print binlog entries #
19 # 0 - default + fits to the file with #
21 # 1 - useful for debugging #
22 # This variable is used within #
23 # include/rpl_stmt_seq.inc. #
24 # $manipulate -- Manipulation of the binary logs #
26 # 1 - so that the output of SHOW BINLOG #
27 # EVENTS IN <current log> contains only #
28 # commands of the current test sequence #
29 # This is especially useful, if the #
30 # $show_binlog is set to 1 and many #
31 # subtest are executed. #
32 # This variable is used within #
33 # include/rpl_stmt_seq.inc. #
34 # have to be set before sourcing this script. #
36 # Please be very careful when editing this routine, because the #
37 # handling of the $variables is extreme sensitive. #
39 ########################################################################
42 # 2007-02-12 ML Replace comments via SQL by "--echo ..."
45 let $VERSION=`select version()`;
48 --echo ######## $my_stmt ########
51 ###############################################################
52 # Predict the number of the current log
53 ###############################################################
54 # Disable the logging of the log number computation.
56 # $_log_num_n should contain the number of the current binlog in numeric style.
57 # If this routine is called for the first time, $_log_num will not initialized
58 # and contain the value '' instead of '1'. So we will correct it here.
60 eval
set @aux= IF(
'$_log_num_n' =
'',
'1',
'$_log_num_n');
61 let $_log_num_n= `SELECT @aux`;
62 eval
set @aux= LPAD(
'$_log_num_n',6,
'0');
63 # SELECT @aux AS "@aux is";
65 # $_log_num_s should contain the number of the current binlog in string style.
66 let $_log_num_s= `select @aux`;
67 # eval SELECT '$log_num' ;
70 ###############################################################
72 ###############################################################
74 --echo --------
switch to master -------
76 # Maybe it would be smarter to use a table with an autoincrement column.
77 let $MAX= `SELECT MAX(f1) FROM t1` ;
78 eval INSERT INTO t1 SET f1= $MAX + 1;
79 # results before DDL(to be tested)
80 SELECT MAX(f1) FROM t1;
83 --let $binlog_file= master-bin.$_log_num_s
84 --source include/show_binlog_events.inc
86 sync_slave_with_master;
89 --echo --------
switch to slave --------
91 # results before DDL(to be tested)
92 SELECT MAX(f1) FROM t1;
95 --let $binlog_file= slave-bin.$_log_num_s
96 --source include/show_binlog_events.inc
99 ###############################################################
100 # command to be tested
101 ###############################################################
103 --echo --------
switch to master -------
106 # Devaluate $my_stmt, to detect script bugs
107 let $my_stmt= ERROR: YOU FORGOT TO FILL IN THE STATEMENT;
108 # results after DDL(to be tested)
109 SELECT MAX(f1) FROM t1;
112 --let $binlog_file= master-bin.$_log_num_s
113 --source include/show_binlog_events.inc
115 sync_slave_with_master;
118 --echo --------
switch to slave --------
120 # results after DDL(to be tested)
121 SELECT MAX(f1) FROM t1;
124 --let $binlog_file= slave-bin.$_log_num_s
125 --source include/show_binlog_events.inc
128 ###############################################################
130 ###############################################################
132 --echo --------
switch to master -------
135 # results after final ROLLBACK
136 SELECT MAX(f1) FROM t1;
137 # Try to detect if the DDL command caused that the INSERT is committed
138 # $MAX holds the highest/last value just before the insert of MAX + 1
140 eval SELECT CONCAT(CONCAT(
'TEST-INFO: MASTER: The INSERT is ',
141 IF(MAX(f1) = $MAX + 1,
'committed',
'not committed')),
142 IF((MAX(f1) = $MAX + 1) XOR NOT $my_master_commit,
149 --let $binlog_file= master-bin.$_log_num_s
150 --source include/show_binlog_events.inc
152 sync_slave_with_master;
155 --echo --------
switch to slave --------
157 # results after final ROLLBACK
158 SELECT MAX(f1) FROM t1;
160 eval SELECT CONCAT(CONCAT('TEST-INFO: SLAVE: The INSERT is ',
161 IF(MAX(f1) = $MAX + 1, 'committed', 'not committed')),
162 IF((MAX(f1) = $MAX + 1) XOR NOT $my_slave_commit,
169 --let $binlog_file= slave-bin.$_log_num_s
170 --source include/show_binlog_events.inc
173 ###############################################################
175 ###############################################################
178 #### Manipulate the binary logs,
179 # so that the output of SHOW BINLOG EVENTS IN <current log>
180 # contains only commands of the current test sequence.
181 # - flush the master and the slave log
182 # ---> both start to write into new logs with incremented number
183 # - increment $_log_num_n
185 --echo --------
switch to master -------
189 # eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
190 sync_slave_with_master;
193 --echo --------
switch to slave --------
195 # the final content of the binary log
197 # The next sleep is urgent needed.
198 # Without this sleep the slaves crashes often, when the SHOW BINLOG
201 # eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
206 --echo --------
switch to master -------