MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_row_img_parts_master_slave.inc
1 #
2 # This is a wrapper to help minimize writing of assertions
3 # that resort to rpl_row_img_parts_assertion.inc on a
4 # master-slave scenario.
5 #
6 # This script takes a statement to be executed and master
7 # and slave expected images description as parameters. Before
8 # statement execution (on the master only), both servers are
9 # synchronized, and positions explicitly saved. These are
10 # then used as starting position in mysqlbinlog -v (see
11 # suite/rpl/include/rpl_row_img_parts_assertion.inc).
12 #
13 # Parameters:
14 # - $row_img_query
15 # The query to be executed on the master, which will
16 # make master and slave log one or more row events.
17 #
18 # - $row_img_expected_master
19 # String representation of the expected images to search
20 # on master's mysqlbinlog -v output
21 #
22 # - $row_img_expected_slave
23 # String representation of the expected images to search
24 # on slaves's mysqlbinlog -v output
25 #
26 # Sample usage:
27 #
28 # -- let $row_img_query= INSERT INTO t VALUES (1, 2, 3)
29 # -- let $row_img_expected_master= | 1:1 2:2 3:3
30 # -- let $row_img_expected_slave = | 1:1 2:2 3:3
31 # -- source include/rpl_row_img_parts_master_slave.inc
32 #
33 # -- let $row_img_query= UPDATE t SET c2= 4 WHERE c1=1
34 # -- let $row_img_expected_master= 1:1 | 2:4
35 # -- let $row_img_expected_slave = 1:1 2:2 3:3 | 1:1 2:4 3:3
36 # -- source include/rpl_row_img_parts_master_slave.inc
37 #
38 # -- let $row_img_query= DELETE FROM t WHERE c2=4
39 # -- let $row_img_expected_master= 1:1 |
40 # -- let $row_img_expected_slave = 1:1 2:4 3:3 |
41 # -- source include/rpl_row_img_parts_master_slave.inc
42 #
43 # NOTES:
44 #
45 # 1. Both master and slave are synchronized before execution
46 # of the query takes place
47 #
48 # 2. original connection - the one in use before including
49 # this script - is restored at the end
50 
51 -- let $old_conn= $CURRENT_CONNECTION
52 
53 -- connection master
54 -- sync_slave_with_master
55 
56 -- let $row_img_pos_slave= query_get_value(SHOW MASTER STATUS, Position, 1)
57 
58 -- connection master
59 -- let $row_img_pos_master= query_get_value(SHOW MASTER STATUS, Position, 1)
60 
61 # execute the query
62 -- connection master
63 -- eval $row_img_query
64 
65 # lets wait until the binary log position changes
66 # we may have just executed an insert delayed
67 -- let $_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
68 
69 # wait for 5 minutes
70 -- let $iterations=3000
71 while($_pos == $row_img_pos_master)
72 {
73  -- sleep 0.1
74  -- let $_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
75  -- dec $iterations
76 }
77 
78 if (!$iterations)
79 {
80  -- echo Time out while waiting for the event to be written to the binary log at the master!
81  -- echo Query: $row_img_query
82  -- source include/show_rpl_debug_info.inc
83  -- exit
84 }
85 
86 # now sync the slave
87 -- sync_slave_with_master
88 
89 # master assertion
90 -- connection master
91 -- let $row_img_expected= $row_img_expected_master
92 -- let $row_img_pos= $row_img_pos_master
93 -- source include/rpl_row_img_parts_assertion.inc
94 
95 # slave assertion
96 -- connection slave
97 -- let $row_img_expected= $row_img_expected_slave
98 -- let $row_img_pos= $row_img_pos_slave
99 -- source include/rpl_row_img_parts_assertion.inc
100 
101 -- connection $old_conn