mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / suite / rpl / t / rpl_row_tbl_metadata.test
blobe8ac74f0125dfee26801beb077dbf00ca93c96b8
2 # BUG#42749: infinite loop writing to row based binlog - processlist shows
3 # "freeing items"
6 # WHY
7 # ===
9 #   This bug would make table map event to report data_written one
10 #   byte less than what would actually be written in its body. This
11 #   would cause one byte shorter event end_log_pos. The ultimate
12 #   impact was that it would make fixing the position in
13 #   MYSQL_BIN_LOG::write_cache bogus or end up in an infinite loop.
15 # HOW
16 # ===
18 #   Checking that the patch fixes the problem is done as follows:
20 #     i) one table with m_field_metadata sized at 290
21 #    ii) an insert is performed;
22 #   iii) the logs are flushed;
23 #    iv) mysqlbinlog is used to check if it succeeds.
24
25 #   In step iv), before the bug was fixed, the test case would fail
26 #   with mysqlbinlog reporting that it was unable to succeed in
27 #   reading the event.
29 -- source include/master-slave.inc
30 -- source include/have_innodb.inc
31 -- source include/have_binlog_format_row.inc
33 -- disable_warnings
34 DROP TABLE IF EXISTS `t1`;
35 -- enable_warnings
37 -- echo ### TABLE with field_metadata_size == 290
38 CREATE TABLE `t1` (
39   `c1` int(11) NOT NULL AUTO_INCREMENT,
40   `c2` varchar(30) NOT NULL,
41   `c3` varchar(30) DEFAULT NULL,
42   `c4` varchar(30) DEFAULT NULL,
43   `c5` varchar(30) DEFAULT NULL,
44   `c6` varchar(30) DEFAULT NULL,
45   `c7` varchar(30) DEFAULT NULL,
46   `c8` varchar(30) DEFAULT NULL,
47   `c9` varchar(30) DEFAULT NULL,
48   `c10` varchar(30) DEFAULT NULL,
49   `c11` varchar(30) DEFAULT NULL,
50   `c12` varchar(30) DEFAULT NULL,
51   `c13` varchar(30) DEFAULT NULL,
52   `c14` varchar(30) DEFAULT NULL,
53   `c15` varchar(30) DEFAULT NULL,
54   `c16` varchar(30) DEFAULT NULL,
55   `c17` varchar(30) DEFAULT NULL,
56   `c18` varchar(30) DEFAULT NULL,
57   `c19` varchar(30) DEFAULT NULL,
58   `c20` varchar(30) DEFAULT NULL,
59   `c21` varchar(30) DEFAULT NULL,
60   `c22` varchar(30) DEFAULT NULL,
61   `c23` varchar(30) DEFAULT NULL,
62   `c24` varchar(30) DEFAULT NULL,
63   `c25` varchar(30) DEFAULT NULL,
64   `c26` varchar(30) DEFAULT NULL,
65   `c27` varchar(30) DEFAULT NULL,
66   `c28` varchar(30) DEFAULT NULL,
67   `c29` varchar(30) DEFAULT NULL,
68   `c30` varchar(30) DEFAULT NULL,
69   `c31` varchar(30) DEFAULT NULL,
70   `c32` varchar(30) DEFAULT NULL,
71   `c33` varchar(30) DEFAULT NULL,
72   `c34` varchar(30) DEFAULT NULL,
73   `c35` varchar(30) DEFAULT NULL,
74   `c36` varchar(30) DEFAULT NULL,
75   `c37` varchar(30) DEFAULT NULL,
76   `c38` varchar(30) DEFAULT NULL,
77   `c39` varchar(30) DEFAULT NULL,
78   `c40` varchar(30) DEFAULT NULL,
79   `c41` varchar(30) DEFAULT NULL,
80   `c42` varchar(30) DEFAULT NULL,
81   `c43` varchar(30) DEFAULT NULL,
82   `c44` varchar(30) DEFAULT NULL,
83   `c45` varchar(30) DEFAULT NULL,
84   `c46` varchar(30) DEFAULT NULL,
85   `c47` varchar(30) DEFAULT NULL,
86   `c48` varchar(30) DEFAULT NULL,
87   `c49` varchar(30) DEFAULT NULL,
88   `c50` varchar(30) DEFAULT NULL,
89   `c51` varchar(30) DEFAULT NULL,
90   `c52` varchar(30) DEFAULT NULL,
91   `c53` varchar(30) DEFAULT NULL,
92   `c54` varchar(30) DEFAULT NULL,
93   `c55` varchar(30) DEFAULT NULL,
94   `c56` varchar(30) DEFAULT NULL,
95   `c57` varchar(30) DEFAULT NULL,
96   `c58` varchar(30) DEFAULT NULL,
97   `c59` varchar(30) DEFAULT NULL,
98   `c60` varchar(30) DEFAULT NULL,
99   `c61` varchar(30) DEFAULT NULL,
100   `c62` varchar(30) DEFAULT NULL,
101   `c63` varchar(30) DEFAULT NULL,
102   `c64` varchar(30) DEFAULT NULL,
103   `c65` varchar(30) DEFAULT NULL,
104   `c66` varchar(30) DEFAULT NULL,
105   `c67` varchar(30) DEFAULT NULL,
106   `c68` varchar(30) DEFAULT NULL,
107   `c69` varchar(30) DEFAULT NULL,
108   `c70` varchar(30) DEFAULT NULL,
109   `c71` varchar(30) DEFAULT NULL,
110   `c72` varchar(30) DEFAULT NULL,
111   `c73` varchar(30) DEFAULT NULL,
112   `c74` varchar(30) DEFAULT NULL,
113   `c75` varchar(30) DEFAULT NULL,
114   `c76` varchar(30) DEFAULT NULL,
115   `c77` varchar(30) DEFAULT NULL,
116   `c78` varchar(30) DEFAULT NULL,
117   `c79` varchar(30) DEFAULT NULL,
118   `c80` varchar(30) DEFAULT NULL,
119   `c81` varchar(30) DEFAULT NULL,
120   `c82` varchar(30) DEFAULT NULL,
121   `c83` varchar(30) DEFAULT NULL,
122   `c84` varchar(30) DEFAULT NULL,
123   `c85` varchar(30) DEFAULT NULL,
124   `c86` varchar(30) DEFAULT NULL,
125   `c87` varchar(30) DEFAULT NULL,
126   `c88` varchar(30) DEFAULT NULL,
127   `c89` varchar(30) DEFAULT NULL,
128   `c90` varchar(30) DEFAULT NULL,
129   `c91` varchar(30) DEFAULT NULL,
130   `c92` varchar(30) DEFAULT NULL,
131   `c93` varchar(30) DEFAULT NULL,
132   `c94` varchar(30) DEFAULT NULL,
133   `c95` varchar(30) DEFAULT NULL,
134   `c96` varchar(30) DEFAULT NULL,
135   `c97` varchar(30) DEFAULT NULL,
136   `c98` varchar(30) DEFAULT NULL,
137   `c99` varchar(30) DEFAULT NULL,
138   `c100` varchar(30) DEFAULT NULL,
139   `c101` varchar(30) DEFAULT NULL,
140   `c102` varchar(30) DEFAULT NULL,
141   `c103` varchar(30) DEFAULT NULL,
142   `c104` varchar(30) DEFAULT NULL,
143   `c105` varchar(30) DEFAULT NULL,
144   `c106` varchar(30) DEFAULT NULL,
145   `c107` varchar(30) DEFAULT NULL,
146   `c108` varchar(30) DEFAULT NULL,
147   `c109` varchar(30) DEFAULT NULL,
148   `c110` varchar(30) DEFAULT NULL,
149   `c111` varchar(30) DEFAULT NULL,
150   `c112` varchar(30) DEFAULT NULL,
151   `c113` varchar(30) DEFAULT NULL,
152   `c114` varchar(30) DEFAULT NULL,
153   `c115` varchar(30) DEFAULT NULL,
154   `c116` varchar(30) DEFAULT NULL,
155   `c117` varchar(30) DEFAULT NULL,
156   `c118` varchar(30) DEFAULT NULL,
157   `c119` varchar(30) DEFAULT NULL,
158   `c120` varchar(30) DEFAULT NULL,
159   `c121` varchar(30) DEFAULT NULL,
160   `c122` varchar(30) DEFAULT NULL,
161   `c123` varchar(30) DEFAULT NULL,
162   `c124` varchar(30) DEFAULT NULL,
163   `c125` varchar(30) DEFAULT NULL,
164   `c126` varchar(30) DEFAULT NULL,
165   `c127` varchar(30) DEFAULT NULL,
166   `c128` varchar(30) DEFAULT NULL,
167   `c129` varchar(30) DEFAULT NULL,
168   `c130` varchar(30) DEFAULT NULL,
169   `c131` varchar(30) DEFAULT NULL,
170   `c132` varchar(30) DEFAULT NULL,
171   `c133` varchar(30) DEFAULT NULL,
172   `c134` varchar(30) DEFAULT NULL,
173   `c135` varchar(30) DEFAULT NULL,
174   `c136` varchar(30) DEFAULT NULL,
175   `c137` varchar(30) DEFAULT NULL,
176   `c138` varchar(30) DEFAULT NULL,
177   `c139` varchar(30) DEFAULT NULL,
178   `c140` varchar(30) DEFAULT NULL,
179   `c141` varchar(30) DEFAULT NULL,
180   `c142` varchar(30) DEFAULT NULL,
181   `c143` varchar(30) DEFAULT NULL,
182   `c144` varchar(30) DEFAULT NULL,
183   `c145` varchar(30) DEFAULT NULL,
184   `c146` varchar(30) DEFAULT NULL,
185   PRIMARY KEY (`c1`)
186 ) ENGINE=InnoDB;
188 LOCK TABLES `t1` WRITE;
189 INSERT INTO `t1`(c2) VALUES ('1');
190 FLUSH LOGS;
192 -- sync_slave_with_master
193 -- connection master
195 -- echo ### assertion: the slave replicated event successfully and tables match
196 -- let $diff_tables= master:t1, slave:t1
197 -- source include/diff_tables.inc
199 DROP TABLE `t1`;
201 -- connection master
202 -- sync_slave_with_master
203 -- connection master
205 -- echo === Using mysqlbinlog to detect failure. Before the patch mysqlbinlog would find a corrupted event, thence would fail.
207 -- let $MYSQLD_DATADIR= `SELECT @@datadir`
208 -- exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug42749.binlog
209 -- remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug42749.binlog
211 #############################################################
212 # BUG#50018: binlog corruption when table has many columns
214 # Same test from BUG#42749, but now we generate some SQL which
215 # creates and inserts into tables with metadata size from 249
216 # to 258.
218 # The test works as follows:
219 #  1. SQL for several CREATE TABLE and INSERTS are generated 
220 #     into a file.
221 #  2. This file is then "sourced"
222 #  3. The slave is synchronized with the master
223 #  4. FLUSH LOGS on master
224 #  5. Compare tables on master and slave.
225 #  6. run mysqlbinlog on  master's binary log
227 # Steps #5 and #6 assert that binary log is not corrupted 
228 # in both cases: when slave is replaying events and when
229 # mysqlbinlog is used to read the binary log
231 --source include/rpl_reset.inc
232 -- connection master
234 # Create several tables with field_metadata_size ranging
235 # from 249 to 258 (so that we cover 251 and 255 range).
236 # This should exercise the switch between using 1 or 3
237 # bytes to pack m_field_metadata_size.
239 # Each varchar field takes up to 2 metadata bytes, see:
241 #  Field_varstring::do_save_field_metadata (field.cc)
243 # The float field takes 1 byte, see:
245 #  Field_float::do_save_field_metadata (field.cc)
248 -- let $generated_sql= $MYSQLTEST_VARDIR/tmp/b50018.sql
249 -- let B50018_FILE= $generated_sql
251 -- echo ### action: generating several tables with different metadata 
252 -- echo ###         sizes (resorting to perl)
253 -- perl
254 my $file= $ENV{'B50018_FILE'};
255 open(FILE, ">", "$file") or die "Unable to open bug 50018 generated SQL file: $!" ;
257 my $tables= "";
258 my $ntables= 10;
259 my $base_ncols= 124;
261 for my $i (1..$ntables)
263   my $ncols= $base_ncols + $i;
264   my $metadata_size= $ncols_variable * 2 + 1; 
266   print FILE "-- echo ### testing table with " . ($base_ncols*2 + $i) . " field metadata size.\n";
267   print FILE "CREATE TABLE t$i (\n";
268   for my $n (1..$base_ncols)
269   {
270     print FILE "c$n VARCHAR(30) NOT NULL DEFAULT 'BUG#50018',\n";
271   }
273   for my $n (1..$i)
274   {
275     print FILE "c" . ($base_ncols+$n) . " FLOAT NOT NULL DEFAULT 0";
276     if ($n < $i)
277     {
278       print FILE ",\n";
279     }
280   }
282   print FILE ") Engine=InnoDB;\n";
284   $tables.= " t$i WRITE";
285   if ($i < $ntables)
286   {
287     $tables .=",";
288   }
289     
290   print FILE "LOCK TABLES t$i WRITE;\n";
291   print FILE "INSERT INTO t$i(c". ($base_ncols+1) . ") VALUES (50018);\n";
292   print FILE "UNLOCK TABLES;";
295 close(FILE);
299 ## we don't need this in the result file
300 ## however, for debugging purposes you 
301 ## may want to reactivate query logging
302 -- disable_query_log 
303 -- source $generated_sql
304 -- enable_query_log
306 -- sync_slave_with_master
307 -- connection master
309 FLUSH LOGS;
311 -- let $ntables=10
312 while($ntables)
314   -- echo ### assertion: the slave replicated event successfully and tables match for t$ntables
315   -- let $diff_tables= master:t$ntables, slave:t$ntables
316   -- source include/diff_tables.inc
318   -- connection master
319   -- disable_query_log
320   -- eval DROP TABLE t$ntables
321   -- enable_query_log
322   -- sync_slave_with_master
323   -- connection master
325   -- dec $ntables
328 -- echo ### assertion: check that binlog is not corrupt. Using mysqlbinlog to 
329 -- echo ###            detect failure. Before the patch mysqlbinlog would find 
330 -- echo ###            a corrupted event, thence would fail.
331 -- let $MYSQLD_DATADIR= `SELECT @@datadir`
332 -- exec $MYSQL_BINLOG -v --hex $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug50018.binlog
334 ## clean up
335 ## For debugging purposes you might want not to remove these
336 -- remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug50018.binlog
337 -- remove_file $generated_sql
338 --source include/rpl_end.inc