mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / extra / rpl_tests / rpl_ndb_apply_status.test
blob6b968fe2e860eea21e9fa49f5895b3eb43b9b92c
1 #############################################
2 #Authors:    TU and Jeb
3 #Date:       2007/04
4 #Purpose:    Generic replication to cluster
5 #            and ensuring that the ndb_apply_status
6 #            table is updated.
7 #############################################
8 # Notes: 
9 # include/select_ndb_apply_status.inc
10 # Selects out the log name, start & end pos
11 # from the ndb_apply_status table
13 # include/show_binlog_using_logname.inc
14 # To select out 1 row from offset 1
15 # from the start position in the binlog whose
16 # name is = log_name
18 # include/tpcb.inc
19 # Creates DATABASE tpcb, the tables and 
20 # stored procedures for loading the DB
21 # and for running transactions against DB.
22 ##############################################
25 --echo
26 --echo *** Test 1 ***
27 --echo
29 connection master;
30 create table t1 (a int key, b int) engine innodb;
31 create table t2 (a int key, b int) engine innodb;
33 --echo
35 --sync_slave_with_master
36 alter table t1 engine ndb;
37 alter table t2 engine ndb;
39 --echo
41 # check binlog position without begin
42 connection master;
43 insert into t1 values (1,2);
45 --echo
47 --sync_slave_with_master
48 --source include/select_ndb_apply_status.inc
50 --echo
52 connection master;
53 --echo # Now check that that is in the apply_status table is consistant
54 --echo # with what is in the binlog
55 --echo
56 --echo # since insert is done with transactional engine, expect a BEGIN
57 --echo # at <start_pos>
58 --echo
59 --let $binlog_start= $start_pos
60 --let $binlog_limit= 1
61 --source include/show_binlog_events.inc
63 --echo
64 --echo # Now the insert, one step after
65 --echo
66 --let $binlog_start= $start_pos
67 --let $binlog_limit= 1,1
68 --source include/show_binlog_events.inc
70 --echo
71 --echo # and the COMMIT should be at <end_pos>
72 --echo
73 --let $binlog_start= $start_pos
74 --let $binlog_limit= 2,1
75 --source include/show_binlog_events.inc
77 --echo
79 # check binlog position with begin
80 begin;
81 insert into t1 values (2,3);
82 insert into t2 values (3,4);
83 commit;
85 --echo
87 --sync_slave_with_master
88 --source include/select_ndb_apply_status.inc
90 connection master;
91 --let $binlog_start= $start_pos
92 --let $binlog_limit= 1
93 --source include/show_binlog_events.inc
94 --echo
95 --let $binlog_start= $start_pos
96 --let $binlog_limit= 1,2
97 --source include/show_binlog_events.inc
98 --echo
99 --let $binlog_start= $start_pos
100 --let $binlog_limit= 3,1
101 --source include/show_binlog_events.inc
103 --echo
105 connection master;
106 DROP TABLE test.t1, test.t2;
107 --sync_slave_with_master
108 SHOW TABLES;
110 # Run in some transactions using stored procedures
111 # and ensure that the ndb_apply_status table is 
112 # updated to show the transactions
115 --echo
116 --echo *** Test 2 ***
117 --echo
119 # Create database/tables and stored procdures
120 connection master;
121 --source include/tpcb.inc
123 # Switch tables on slave to use NDB 
124 --sync_slave_with_master
125 USE tpcb;
126 ALTER TABLE account ENGINE NDB;
127 ALTER TABLE branch ENGINE NDB;
128 ALTER TABLE teller ENGINE NDB;
129 ALTER TABLE history ENGINE NDB;
131 --echo
133 # Load DB tpcb and run some transactions
134 connection master;
135 --disable_query_log
136 CALL tpcb.load();
137 SET AUTOCOMMIT=0;
138 let $run= 5;
139 while ($run)
141  START TRANSACTION;
142  --eval CALL tpcb.trans($rpl_format);
143  eval SET @my_errno= $mysql_errno;
144  let $run_good= `SELECT @my_errno = 0`;
145  let $run_bad= `SELECT @my_errno <> 0`;
146  if ($run_good)
148    COMMIT;
150  if ($run_bad)
152    ROLLBACK;
154  dec $run;
157 SET AUTOCOMMIT=1;
158 --enable_query_log
160 --sync_slave_with_master
161 --source include/select_ndb_apply_status.inc
163 --echo
165 connection master;
166 --source  include/show_binlog_using_logname.inc
168 # Flush the logs on the master moving all
169 # Transaction to a new binlog and ensure
170 # that the ndb_apply_status table is updated
171 # to show the use of the new binlog.
173 --echo
174 --echo ** Test 3 **
175 --echo
177 # Flush logs on master which should force it
178 # to switch to binlog #2
180 FLUSH LOGS;
182 # Run in some transaction to increase end pos in
183 # binlog
185 --disable_query_log
186 SET AUTOCOMMIT=0;
187 let $run= 5;
188 while ($run)
190  START TRANSACTION;
191  --eval CALL tpcb.trans($rpl_format);
192  eval SET @my_errno= $mysql_errno;
193  let $run_good= `SELECT @my_errno = 0`;
194  let $run_bad= `SELECT @my_errno <> 0`;
195  if ($run_good)
197    COMMIT;
199  if ($run_bad)
201    ROLLBACK;
203  dec $run;
205 SET AUTOCOMMIT=1;
206 --enable_query_log
208 --echo
210 --sync_slave_with_master
211 --source include/select_ndb_apply_status.inc
213 --echo
215 connection master;
216 --source  include/show_binlog_using_logname.inc
218 # Now we reset both the master and the slave
219 # Run some more transaction and ensure
220 # that the ndb_apply_status is updated
221 # correctly
223 --echo
224 --echo ** Test 4 **
225 --echo
227 # Reset both slave and master
228 # This should reset binlog to #1
229 --source include/rpl_reset.inc
231 --echo
233 # Run in some transactions and check
234 connection master;
235 --disable_query_log
236 SET AUTOCOMMIT=0;
237 let $run= 5;
238 while ($run)
240  START TRANSACTION;
241  --eval CALL tpcb.trans($rpl_format);
242  eval SET @my_errno= $mysql_errno;
243  let $run_good= `SELECT @my_errno = 0`;
244  let $run_bad= `SELECT @my_errno <> 0`;
245  if ($run_good)
247    COMMIT;
249  if ($run_bad)
251    ROLLBACK;
253  dec $run;
255 SET AUTOCOMMIT=1;
256 --enable_query_log
258 --sync_slave_with_master
259 --source include/select_ndb_apply_status.inc
261 --echo
263 connection master;
264 --source include/show_binlog_using_logname.inc
266 # Since we are doing replication, it is a good
267 # idea to check to make sure all data was 
268 # Replicated correctly
270 --echo
271 --echo *** DUMP MASTER & SLAVE FOR COMPARE ********
273 --exec $MYSQL_DUMP -n -t --compact --order-by-primary --skip-extended-insert tpcb account teller branch history > $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
275 --exec $MYSQL_DUMP_SLAVE -n -t --compact --order-by-primary --skip-extended-insert tpcb account teller branch history > $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql
277 connection master;
278 DROP DATABASE tpcb;
280 --sync_slave_with_master
282 ####### Commenting out until decision on Bug#27960 ###########
284 #--source include/select_ndb_apply_status.inc
286 #connection master;
287 #--eval SHOW BINLOG EVENTS in '$log_name' from $start_pos
288 #--source include/show_binlog_using_logname.inc
290 --echo ****** Do dumps compare ************
293 diff_files $MYSQLTEST_VARDIR/tmp/master_apply_status.sql $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql;
295 ## Note: Ths files should only get removed, if the above diff succeeds.
297 --exec rm $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
298 --exec rm $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql
301 # End of 5.1 Test