You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
6.2 KiB

  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
  12. #
  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
  17. #
  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. ##############################################
  23. --echo
  24. --echo *** Test 1 ***
  25. --echo
  26. connection master;
  27. create table t1 (a int key, b int) engine innodb;
  28. create table t2 (a int key, b int) engine innodb;
  29. --echo
  30. --sync_slave_with_master
  31. alter table t1 engine ndb;
  32. alter table t2 engine ndb;
  33. --echo
  34. # check binlog position without begin
  35. connection master;
  36. insert into t1 values (1,2);
  37. --echo
  38. --sync_slave_with_master
  39. --source include/select_ndb_apply_status.inc
  40. --echo
  41. connection master;
  42. # here is actually a bug, since there is no begin statement, the
  43. # query is autocommitted, and end_pos shows end of the insert and not
  44. # end of the commit
  45. --replace_result $start_pos <start_pos>
  46. --replace_column 5 #
  47. --eval show binlog events from $start_pos limit 1
  48. --echo
  49. --replace_result $start_pos <start_pos> $end_pos <end_pos>
  50. --replace_column 2 #
  51. --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
  52. --eval show binlog events from $start_pos limit 1,1
  53. --echo
  54. # check binlog position with begin
  55. begin;
  56. insert into t1 values (2,3);
  57. insert into t2 values (3,4);
  58. commit;
  59. --echo
  60. --sync_slave_with_master
  61. --source include/select_ndb_apply_status.inc
  62. connection master;
  63. --replace_result $start_pos <start_pos>
  64. --replace_column 5 #
  65. --eval show binlog events from $start_pos limit 1
  66. --echo
  67. --replace_result $start_pos <start_pos>
  68. --replace_column 2 # 4 # 5 #
  69. --eval show binlog events from $start_pos limit 1,2
  70. --echo
  71. --replace_result $start_pos <start_pos> $end_pos <end_pos>
  72. --replace_column 2 #
  73. --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
  74. --eval show binlog events from $start_pos limit 3,1
  75. --echo
  76. connection master;
  77. DROP TABLE test.t1, test.t2;
  78. --sync_slave_with_master
  79. SHOW TABLES;
  80. # Run in some transactions using stored procedures
  81. # and ensure that the ndb_apply_status table is
  82. # updated to show the transactions
  83. --echo
  84. --echo *** Test 2 ***
  85. --echo
  86. # Create database/tables and stored procdures
  87. connection master;
  88. --source include/tpcb.inc
  89. # Switch tables on slave to use NDB
  90. --sync_slave_with_master
  91. USE tpcb;
  92. ALTER TABLE account ENGINE NDB;
  93. ALTER TABLE branch ENGINE NDB;
  94. ALTER TABLE teller ENGINE NDB;
  95. ALTER TABLE history ENGINE NDB;
  96. --echo
  97. # Load DB tpcb and run some transactions
  98. connection master;
  99. --disable_query_log
  100. CALL tpcb.load();
  101. SET AUTOCOMMIT=0;
  102. let $run= 5;
  103. while ($run)
  104. {
  105. START TRANSACTION;
  106. --eval CALL tpcb.trans($rpl_format);
  107. eval SET @my_errno= $mysql_errno;
  108. let $run_good= `SELECT @my_errno = 0`;
  109. let $run_bad= `SELECT @my_errno <> 0`;
  110. if ($run_good)
  111. {
  112. COMMIT;
  113. }
  114. if ($run_bad)
  115. {
  116. ROLLBACK;
  117. }
  118. dec $run;
  119. }
  120. SET AUTOCOMMIT=1;
  121. --enable_query_log
  122. --sync_slave_with_master
  123. --source include/select_ndb_apply_status.inc
  124. --echo
  125. connection master;
  126. --source include/show_binlog_using_logname.inc
  127. # Flush the logs on the master moving all
  128. # Transaction to a new binlog and ensure
  129. # that the ndb_apply_status table is updated
  130. # to show the use of the new binlog.
  131. --echo
  132. --echo ** Test 3 **
  133. --echo
  134. # Flush logs on master which should force it
  135. # to switch to binlog #2
  136. FLUSH LOGS;
  137. # Run in some transaction to increase end pos in
  138. # binlog
  139. --disable_query_log
  140. SET AUTOCOMMIT=0;
  141. let $run= 5;
  142. while ($run)
  143. {
  144. START TRANSACTION;
  145. --eval CALL tpcb.trans($rpl_format);
  146. eval SET @my_errno= $mysql_errno;
  147. let $run_good= `SELECT @my_errno = 0`;
  148. let $run_bad= `SELECT @my_errno <> 0`;
  149. if ($run_good)
  150. {
  151. COMMIT;
  152. }
  153. if ($run_bad)
  154. {
  155. ROLLBACK;
  156. }
  157. dec $run;
  158. }
  159. SET AUTOCOMMIT=1;
  160. --enable_query_log
  161. --echo
  162. --sync_slave_with_master
  163. --source include/select_ndb_apply_status.inc
  164. --echo
  165. connection master;
  166. --source include/show_binlog_using_logname.inc
  167. # Now we reset both the master and the slave
  168. # Run some more transaction and ensure
  169. # that the ndb_apply_status is updated
  170. # correctly
  171. --echo
  172. --echo ** Test 4 **
  173. --echo
  174. # Reset both slave and master
  175. # This should reset binlog to #1
  176. --source include/master-slave-reset.inc
  177. --echo
  178. # Run in some transactions and check
  179. connection master;
  180. --disable_query_log
  181. SET AUTOCOMMIT=0;
  182. let $run= 5;
  183. while ($run)
  184. {
  185. START TRANSACTION;
  186. --eval CALL tpcb.trans($rpl_format);
  187. eval SET @my_errno= $mysql_errno;
  188. let $run_good= `SELECT @my_errno = 0`;
  189. let $run_bad= `SELECT @my_errno <> 0`;
  190. if ($run_good)
  191. {
  192. COMMIT;
  193. }
  194. if ($run_bad)
  195. {
  196. ROLLBACK;
  197. }
  198. dec $run;
  199. }
  200. SET AUTOCOMMIT=1;
  201. --enable_query_log
  202. --sync_slave_with_master
  203. --source include/select_ndb_apply_status.inc
  204. --echo
  205. connection master;
  206. --source include/show_binlog_using_logname.inc
  207. # Since we are doing replication, it is a good
  208. # idea to check to make sure all data was
  209. # Replicated correctly
  210. --echo
  211. --echo *** DUMP MASTER & SLAVE FOR COMPARE ********
  212. --exec $MYSQL_DUMP -n -t --compact --order-by-primary --skip-extended-insert tpcb account teller branch history > $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
  213. --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
  214. connection master;
  215. DROP DATABASE tpcb;
  216. --sync_slave_with_master
  217. ####### Commenting out until decision on Bug#27960 ###########
  218. #--source include/select_ndb_apply_status.inc
  219. #connection master;
  220. #--eval SHOW BINLOG EVENTS in '$log_name' from $start_pos
  221. #--source include/show_binlog_using_logname.inc
  222. --echo ****** Do dumps compare ************
  223. diff_files $MYSQLTEST_VARDIR/tmp/master_apply_status.sql $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql;
  224. ## Note: Ths files should only get removed, if the above diff succeeds.
  225. --exec rm $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
  226. --exec rm $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql
  227. # End of 5.1 Test