mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / include / rpl_stmt_seq.inc
blob08f6e44aba0860363c2504d9b4296fd570a05fef
1 ################### include/rpl_stmt_seq.inc ###########################
2 #                                                                      #
3 # Check if a given SQL statement (->$my_stmt) / AUTOCOMMIT mode /      #
4 # storage engine somehow involved causes COMMIT or ROLLBACK.           #
5 #                                                                      #
6 #                                                                      #
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                           #
15 # 4. flush the logs                                                    #
16 #                                                                      #
17 # The variables                                                        #
18 #    $show_binlog       -- print binlog entries                        #
19 #                          0 - default + fits to the file with         #
20 #                              results                                 #
21 #                          1 - useful for debugging                    #
22 #                          This variable is used within                #
23 #                          include/rpl_stmt_seq.inc.                   #
24 #    $manipulate        -- Manipulation of the binary logs             #
25 #                          0 - do nothing                              #
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.                          #
35 #                                                                      #
36 # Please be very careful when editing this routine, because the        #
37 # handling of the $variables is extreme sensitive.                     #
38 #                                                                      #
39 ########################################################################
41 # Last update:
42 # 2007-02-12 ML Replace comments via SQL by "--echo ..."
45 let $VERSION=`select version()`;
47 --echo
48 --echo ######## $my_stmt ########
51 ###############################################################
52 # Predict the number of the current log
53 ###############################################################
54 # Disable the logging of the log number computation. 
55 --disable_query_log
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' ;
68 --enable_query_log
70 ###############################################################
71 # INSERT 
72 ###############################################################
73 --echo
74 --echo -------- switch to master -------
75 connection 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;
81 if ($show_binlog)
83   --let $binlog_file= master-bin.$_log_num_s
84   --source include/show_binlog_events.inc
86 sync_slave_with_master;
88 --echo
89 --echo -------- switch to slave --------
90 connection slave;
91 # results before DDL(to be tested)
92 SELECT MAX(f1) FROM t1;
93 if ($show_binlog)
95   --let $binlog_file= slave-bin.$_log_num_s
96   --source include/show_binlog_events.inc
99 ###############################################################
100 # command to be tested
101 ###############################################################
102 --echo
103 --echo -------- switch to master -------
104 connection master;
105 eval $my_stmt;
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;
110 if ($show_binlog)
112   --let $binlog_file= master-bin.$_log_num_s
113   --source include/show_binlog_events.inc
115 sync_slave_with_master;
117 --echo
118 --echo -------- switch to slave --------
119 connection slave;
120 # results after DDL(to be tested)
121 SELECT MAX(f1) FROM t1;
122 if ($show_binlog)
124   --let $binlog_file= slave-bin.$_log_num_s
125   --source include/show_binlog_events.inc
128 ###############################################################
129 # ROLLBACK
130 ###############################################################
131 --echo
132 --echo -------- switch to master -------
133 connection master;
134 ROLLBACK;
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
139 --disable_query_log
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,
143                 ' (Succeeded)',
144                 ' (Failed)')) AS "" 
145                FROM mysqltest1.t1;
146 --enable_query_log
147 if ($show_binlog)
149   --let $binlog_file= master-bin.$_log_num_s
150   --source include/show_binlog_events.inc
152 sync_slave_with_master;
154 --echo
155 --echo -------- switch to slave --------
156 connection slave;
157 # results after final ROLLBACK
158 SELECT MAX(f1) FROM t1;
159 --disable_query_log
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,
163                 ' (Succeeded)',
164                 ' (Failed)')) AS "" 
165                FROM mysqltest1.t1;
166 --enable_query_log
167 if ($show_binlog)
169   --let $binlog_file= slave-bin.$_log_num_s
170   --source include/show_binlog_events.inc
173 ###############################################################
174 # Manipulate binlog
175 ###############################################################
176 if ($manipulate)
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
184 --echo
185 --echo -------- switch to master -------
186 connection master;
187 flush logs;
188 # sleep 1;
189 # eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
190 sync_slave_with_master;
192 --echo
193 --echo -------- switch to slave --------
194 connection slave;
195 # the final content of the binary log
196 flush logs;
197 # The next sleep is urgent needed.
198 # Without this sleep the slaves crashes often, when the SHOW BINLOG
199 # is executed.   :-(
200 # sleep 1;
201 # eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
202 inc $_log_num_n;
205 --echo
206 --echo -------- switch to master -------
207 connection master;