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# --source include/rpl_diff.inc
12#
13# Parameters:
14#   $rpl_diff_statement
15#     Statement to check. For each compared server, this script will
16#     start a new client and pass this statement to the client.
17#     Note: This string will be evaluated as a single-quote-escaped
18#     SQL string and hence must be quoted as such.  In particular, any
19#     single quotes in this string must be escaped.
20#
21#   $rpl_diff_servers
22#     By default, this file compares all servers configured by
23#     rpl_init.inc.  You can set $diff_servers to a comma-separated
24#     list of numbers: only the servers identified by these numbers
25#     will be compared.
26#
27#   $rpl_diff_database
28#     By default, the statement will be executed on the database
29#     'test'.  If $rpl_diff_database is set, the statement will be
30#     executed on the database named $rpl_diff_database instead.
31
32
33--let $include_filename= rpl_diff.inc
34--source include/begin_include_file.inc
35
36
37if (!$rpl_diff_statement)
38{
39  --die ERROR IN TEST: you must set $rpl_diff_statement before you source include/rpl_diff.inc
40}
41
42
43# Sync.
44--source include/rpl_sync.inc
45
46
47# Get database name.
48--let $_rpl_diff_database= $rpl_diff_database
49if (!$_rpl_diff_database)
50{
51  --let $_rpl_diff_database= test
52}
53
54
55# Generate list of servers.
56--let $_rpl_diff_servers= $rpl_diff_servers
57if (!$_rpl_diff_servers)
58{
59  --let $_rpl_server_i= $rpl_server_count
60  --let $_rpl_diff_servers=
61  while ($_rpl_server_i)
62  {
63    --let $_rpl_diff_servers= $_rpl_server_i,$_rpl_diff_servers
64    --dec $_rpl_server_i
65  }
66}
67if ($rpl_debug)
68{
69  --echo \$rpl_diff_servers= '$_rpl_diff_servers'
70}
71
72
73if (!$rpl_debug)
74{
75  --disable_query_log
76}
77
78
79# Generate file containing $rpl_diff_statement. We don't pass the
80# statement on the command line, because it would be subject to shell
81# substitutions.
82--let $write_to_file= GENERATE
83--let $write_var= $rpl_diff_statement
84--source include/write_var_to_file.inc
85--let $_rpl_diff_statement_file= $write_to_file
86
87
88# Compare all servers.
89--let $_rpl_diff_first= 1
90while ($_rpl_diff_servers)
91{
92  # Set $_rpl_diff_server_i to the first number in the list
93  --let $_rpl_diff_server_i= `SELECT SUBSTRING_INDEX('$_rpl_diff_servers', ',', 1)`
94  # Remove $_rpl_diff_server_i from the list
95  --let $_rpl_diff_servers= `SELECT SUBSTRING('$_rpl_diff_servers', LENGTH('$_rpl_diff_server_i') + 2)`
96
97  # Execute statement
98  --let $_rpl_diff_file= $MYSQLTEST_VARDIR/tmp/_rpl_diff_server-$_rpl_diff_server_i.tmp
99  --exec $MYSQL --defaults-group-suffix=.$_rpl_diff_server_i $_rpl_diff_database < $_rpl_diff_statement_file > $_rpl_diff_file
100
101  # Compare
102  if (!$_rpl_diff_first)
103  {
104    if ($rpl_debug)
105    {
106      --echo diffing $_rpl_diff_file and $_rpl_diff_prev_file
107    }
108    --diff_files $_rpl_diff_file $_rpl_diff_prev_file
109    --remove_file $_rpl_diff_prev_file
110  }
111  --let $_rpl_diff_prev_file= $_rpl_diff_file
112  --let $_rpl_diff_first= 0
113}
114--remove_file $_rpl_diff_prev_file
115--remove_file $_rpl_diff_statement_file
116
117--let $include_filename= rpl_diff.inc
118--source include/end_include_file.inc
119