1# ==== Purpose ====
2#
3# Diff the output of a statement on all configured servers (usually
4# master and slave).
5#
6#
7# ==== Usage =====
8#
9# --let $rpl_diff_statement= SELECT * FROM t1 WHERE a < 100
10# [--let $rpl_diff_servers= <server1>,<server2>,...<serverN>]
11# [--let $rpl_diff_database= database]
12# [--let $rpl_skip_sync= 1]
13# [--let $rpl_only_running_threads= 1]
14# --source include/rpl_diff.inc
15#
16# Parameters:
17#   $rpl_diff_statement
18#     Statement to check. For each compared server, this script will
19#     start a new client and pass this statement to the client.
20#     Note: This string will be evaluated as a single-quote-escaped
21#     SQL string and hence must be quoted as such.  In particular, any
22#     single quotes in this string must be escaped.
23#
24#   $rpl_diff_servers
25#     By default, this file compares all servers configured by
26#     rpl_init.inc.  You can set $diff_servers to a comma-separated
27#     list of numbers: only the servers identified by these numbers
28#     will be compared.
29#
30#   $rpl_diff_database
31#     By default, the statement will be executed on the database
32#     'test'.  If $rpl_diff_database is set, the statement will be
33#     executed on the database named $rpl_diff_database instead.
34#
35#   $rpl_skip_sync
36#     By default, all slaves are synced using rpl_sync.inc. Set this
37#     option to 1 to disable this behavior (note that you must
38#     manually sync all servers in this case). Normally you want to
39#     sync, but you need to disable sync if you use multi-source.
40#
41#   $rpl_only_running_threads
42#     If one or both of the IO and SQL threads is stopped, sync and
43#     stop only the threads that are running.  See
44#     include/rpl_sync.inc and include/stop_slave.inc for details.
45
46
47--let $include_filename= rpl_diff.inc
48--source include/begin_include_file.inc
49
50
51if (!$rpl_diff_statement)
52{
53  --die ERROR IN TEST: you must set $rpl_diff_statement before you source include/rpl_diff.inc
54}
55
56
57# Sync.
58if (!$rpl_skip_sync)
59{
60  --source include/rpl_sync.inc
61}
62
63
64# Get database name.
65--let $_rpl_diff_database= $rpl_diff_database
66if (!$_rpl_diff_database)
67{
68  --let $_rpl_diff_database= test
69}
70
71
72# Generate list of servers.
73--let $_rpl_diff_servers= $rpl_diff_servers
74if (!$_rpl_diff_servers)
75{
76  --let $_rpl_server_i= $rpl_server_count
77  --let $_rpl_diff_servers=
78  while ($_rpl_server_i)
79  {
80    --let $_rpl_diff_servers= $_rpl_server_i,$_rpl_diff_servers
81    --dec $_rpl_server_i
82  }
83}
84if ($rpl_debug)
85{
86  --echo \$rpl_diff_servers= '$_rpl_diff_servers'
87}
88
89
90if (!$rpl_debug)
91{
92  --disable_query_log
93}
94
95
96# Generate file containing $rpl_diff_statement. We don't pass the
97# statement on the command line, because it would be subject to shell
98# substitutions.
99--let $write_to_file= GENERATE
100--let $write_var= $rpl_diff_statement
101--source include/write_var_to_file.inc
102--let $_rpl_diff_statement_file= $write_to_file
103
104
105# Compare all servers.
106--let $_rpl_diff_first= 1
107while ($_rpl_diff_servers)
108{
109  # Set $_rpl_diff_server_i to the first number in the list
110  --let $_rpl_diff_server_i= `SELECT SUBSTRING_INDEX('$_rpl_diff_servers', ',', 1)`
111  # Remove $_rpl_diff_server_i from the list
112  --let $_rpl_diff_servers= `SELECT SUBSTRING('$_rpl_diff_servers', LENGTH('$_rpl_diff_server_i') + 2)`
113
114  # Execute statement
115  --let $_rpl_diff_file= $MYSQLTEST_VARDIR/tmp/_rpl_diff_server-$_rpl_diff_server_i.tmp
116  --exec $MYSQL --defaults-group-suffix=.$_rpl_diff_server_i $_rpl_diff_database < $_rpl_diff_statement_file > $_rpl_diff_file
117
118  # Compare
119  if (!$_rpl_diff_first)
120  {
121    if ($rpl_debug)
122    {
123      --echo diffing $_rpl_diff_file and $_rpl_diff_prev_file
124    }
125    --diff_files $_rpl_diff_file $_rpl_diff_prev_file
126    --remove_file $_rpl_diff_prev_file
127  }
128  --let $_rpl_diff_prev_file= $_rpl_diff_file
129  --let $_rpl_diff_first= 0
130}
131--remove_file $_rpl_diff_prev_file
132
133
134--let $include_filename= rpl_diff.inc
135--source include/end_include_file.inc
136