~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
################### include/rpl_stmt_seq.inc ###########################
2
#                                                                      #
3
# Check if a given SQL statement (->$my_stmt) / AUTOCOMMIT mode /      #
4
# storage engine somehow involved causes COMMIT or ROLLBACK.           #
5
#                                                                      #
6
#                                                                      #
7
# The typical test sequence                                            #
8
# -------------------------                                            #
9
# 1. master connection: INSERT without commit                          #
10
#    check table content of master and slave                           #
11
# 2. master connection: EXECUTE the statement                          #
12
#    check table content of master and slave                           #
13
# 3. master connection: ROLLBACK                                       #
14
#    check table content of master and slave                           #
15
# 4. flush the logs                                                    #
16
#                                                                      #
17
# The variables                                                        #
18
#    $show_binlog       -- print binlog entries                        #
19
#                          0 - default + fits to the file with         #
20
#                              results                                 #
21
#                          1 - useful for debugging                    #
22
#                          This variable is used within                #
23
#                          include/rpl_stmt_seq.inc.                   #
24
#    $manipulate        -- Manipulation of the binary logs             #
25
#                          0 - do nothing                              #
26
#                          1 - so that the output of SHOW BINLOG       #
27
#                              EVENTS IN <current log> contains only   #
28
#                              commands of the current test sequence   #
29
#                              This is especially useful, if the       #
30
#                              $show_binlog is set to 1 and many       #
31
#                              subtest are executed.                   #
32
#                          This variable is used within                #
33
#                          include/rpl_stmt_seq.inc.                   #
34
# have to be set before sourcing this script.                          #
35
#                                                                      #
36
# Please be very careful when editing this routine, because the        #
37
# handling of the $variables is extreme sensitive.                     #
38
#                                                                      #
39
########################################################################
40
41
# Last update:
42
# 2007-02-12 ML Replace comments via SQL by "--echo ..."
43
#
44
45
let $VERSION=`select version()`;
46
47
--echo
48
--echo ######## $my_stmt ########
49
50
51
###############################################################
52
# Predict the number of the current log
53
###############################################################
54
# Disable the logging of the log number computation. 
55
--disable_query_log
56
# $_log_num_n should contain the number of the current binlog in numeric style.
57
# If this routine is called for the first time, $_log_num will not initialized
58
# and contain the value '' instead of '1'. So we will correct it here.
59
#
60
eval set @aux= IF('$_log_num_n' = '', '1', '$_log_num_n');
61
let $_log_num_n= `SELECT @aux`;
62
eval set @aux= LPAD('$_log_num_n',6,'0');
63
#              SELECT @aux AS "@aux is";
64
#
65
# $_log_num_s should contain the number of the current binlog in string style.
66
let $_log_num_s= `select @aux`;
67
# eval SELECT '$log_num' ;
68
--enable_query_log
69
70
###############################################################
71
# INSERT 
72
###############################################################
73
--echo
74
--echo -------- switch to master -------
75
connection master;
76
# Maybe it would be smarter to use a table with an autoincrement column.
77
let $MAX= `SELECT MAX(f1) FROM t1` ;
78
eval INSERT INTO t1 SET f1= $MAX + 1;
79
# results before DDL(to be tested)
80
SELECT MAX(f1) FROM t1;
81
if ($show_binlog)
82
{
83
--replace_result $VERSION VERSION
84
--replace_column 2 # 5 #
85
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
86
}
87
sync_slave_with_master;
88
89
--echo
90
--echo -------- switch to slave --------
91
connection slave;
92
# results before DDL(to be tested)
93
SELECT MAX(f1) FROM t1;
94
if ($show_binlog)
95
{
96
--replace_result $VERSION VERSION
97
--replace_column 2 # 5 #
98
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
99
}
100
101
###############################################################
102
# command to be tested
103
###############################################################
104
--echo
105
--echo -------- switch to master -------
106
connection master;
107
eval $my_stmt;
108
# Devaluate $my_stmt, to detect script bugs
109
let $my_stmt= ERROR: YOU FORGOT TO FILL IN THE STATEMENT;
110
# results after DDL(to be tested)
111
SELECT MAX(f1) FROM t1;
112
if ($show_binlog)
113
{
114
--replace_result $VERSION VERSION
115
--replace_column 2 # 5 #
116
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
117
}
118
sync_slave_with_master;
119
120
--echo
121
--echo -------- switch to slave --------
122
connection slave;
123
# results after DDL(to be tested)
124
SELECT MAX(f1) FROM t1;
125
if ($show_binlog)
126
{
127
--replace_result $VERSION VERSION
128
--replace_column 2 # 5 #
129
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
130
}
131
132
###############################################################
133
# ROLLBACK
134
###############################################################
135
--echo
136
--echo -------- switch to master -------
137
connection master;
138
ROLLBACK;
139
# results after final ROLLBACK
140
SELECT MAX(f1) FROM t1;
141
# Try to detect if the DDL command caused that the INSERT is committed
142
# $MAX holds the highest/last value just before the insert of MAX + 1
143
--disable_query_log
144
eval SELECT CONCAT(CONCAT('TEST-INFO: MASTER: The INSERT is ',
145
               IF(MAX(f1) = $MAX + 1, 'committed', 'not committed')),
146
               IF((MAX(f1) = $MAX + 1) XOR NOT $my_master_commit,
147
                ' (Succeeded)',
148
                ' (Failed)')) AS "" 
149
               FROM mysqltest1.t1;
150
--enable_query_log
151
if ($show_binlog)
152
{
153
--replace_result $VERSION VERSION
154
--replace_column 2 # 5 #
155
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
156
}
157
sync_slave_with_master;
158
159
--echo
160
--echo -------- switch to slave --------
161
connection slave;
162
# results after final ROLLBACK
163
SELECT MAX(f1) FROM t1;
164
--disable_query_log
165
eval SELECT CONCAT(CONCAT('TEST-INFO: SLAVE:  The INSERT is ',
166
               IF(MAX(f1) = $MAX + 1, 'committed', 'not committed')),
167
               IF((MAX(f1) = $MAX + 1) XOR NOT $my_slave_commit,
168
                ' (Succeeded)',
169
                ' (Failed)')) AS "" 
170
               FROM mysqltest1.t1;
171
--enable_query_log
172
if ($show_binlog)
173
{
174
--replace_result $VERSION VERSION
175
--replace_column 2 # 5 #
176
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
177
}
178
179
###############################################################
180
# Manipulate binlog
181
###############################################################
182
if ($manipulate)
183
{
184
#### Manipulate the binary logs,
185
# so that the output of SHOW BINLOG EVENTS IN <current log>
186
# contains only commands of the current test sequence.
187
# - flush the master and the slave log
188
#   ---> both start to write into new logs with incremented number
189
# - increment $_log_num_n
190
--echo
191
--echo -------- switch to master -------
192
connection master;
193
flush logs;
194
# sleep 1;
195
# eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
196
sync_slave_with_master;
197
198
--echo
199
--echo -------- switch to slave --------
200
connection slave;
201
# the final content of the binary log
202
flush logs;
203
# The next sleep is urgent needed.
204
# Without this sleep the slaves crashes often, when the SHOW BINLOG
205
# is executed.   :-(
206
# sleep 1;
207
# eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
208
inc $_log_num_n;
209
}
210
211
--echo
212
--echo -------- switch to master -------
213
connection master;