1 : /* Copyright (C) 2006-2008 MySQL AB
2 :
3 : This program is free software; you can redistribute it and/or modify
4 : it under the terms of the GNU General Public License as published by
5 : the Free Software Foundation; version 2 of the License.
6 :
7 : This program is distributed in the hope that it will be useful,
8 : but WITHOUT ANY WARRANTY; without even the implied warranty of
9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 : GNU General Public License for more details.
11 :
12 : You should have received a copy of the GNU General Public License
13 : along with this program; if not, write to the Free Software
14 : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15 :
16 : #include "../maria_def.h"
17 : #include <stdio.h>
18 : #include <errno.h>
19 : #include <tap.h>
20 : #include "../trnman.h"
21 :
22 : extern my_bool maria_log_remove();
23 : extern void example_loghandler_init();
24 :
25 : #ifndef DBUG_OFF
26 : static const char *default_dbug_option;
27 : #endif
28 : static TRN *trn= &dummy_transaction_object;
29 :
30 : #define PCACHE_SIZE (1024*1024*10)
31 :
32 : #define LONG_BUFFER_SIZE (100 * 1024)
33 :
34 : #ifdef LONG_LOG_TEST
35 : #define LOG_FLAGS 0
36 : #define LOG_FILE_SIZE (1024L*1024L*8)
37 : #define ITERATIONS (1600*4)
38 :
39 : #else
40 : #undef SKIP_BIG_TESTS
41 : #define SKIP_BIG_TESTS(X) /* no-op */
42 : #define LOG_FLAGS (TRANSLOG_SECTOR_PROTECTION | TRANSLOG_PAGE_CRC)
43 : #define LOG_FILE_SIZE (1024L*1024L*8L)
44 : #define ITERATIONS 1600
45 : #endif
46 :
47 : /*
48 : #define LOG_FLAGS 0
49 : #define LOG_FILE_SIZE 1024L*1024L*1024L
50 : #define ITERATIONS 181000
51 : */
52 :
53 : /*
54 : #define LOG_FLAGS 0
55 : #define LOG_FILE_SIZE 1024L*1024L*3L
56 : #define ITERATIONS 1600
57 : */
58 :
59 : /*
60 : #define LOG_FLAGS 0
61 : #define LOG_FILE_SIZE 1024L*1024L*100L
62 : #define ITERATIONS 65000
63 : */
64 :
65 : /*
66 : Generate random value in the range (0,LONG_BUFFER_SIZE)
67 : */
68 : static uint32 rand_buffer_size()
69 6396 : {
70 6396 : return (uint32)((ulonglong)rand()*(LONG_BUFFER_SIZE + 1)/RAND_MAX);
71 : }
72 :
73 : /*
74 : Check that the buffer filled correctly
75 :
76 : SYNOPSIS
77 : check_content()
78 : ptr Pointer to the buffer
79 : length length of the buffer
80 :
81 : RETURN
82 : 0 - OK
83 : 1 - Error
84 : */
85 :
86 :
87 : static my_bool check_content(uchar *ptr, ulong length)
88 6396 : {
89 : ulong i;
90 : uchar buff[2];
91 164787314 : for (i= 0; i < length; i++)
92 : {
93 164780918 : if (i % 2 == 0)
94 82392872 : int2store(buff, i >> 1);
95 164780918 : if (ptr[i] != buff[i % 2])
96 : {
97 0 : fprintf(stderr, "Byte # %lu is %x instead of %x",
98 : i, (uint) ptr[i], (uint) buff[i % 2]);
99 0 : return 1;
100 : }
101 : }
102 6396 : return 0;
103 : }
104 :
105 :
106 : /*
107 : Report OK for read operation
108 :
109 : SYNOPSIS
110 : read_ok()
111 : rec the record header
112 : */
113 :
114 : void read_ok(TRANSLOG_HEADER_BUFFER *rec)
115 6397 : {
116 : char buff[80];
117 6397 : my_snprintf(buff, sizeof(buff), "read record type: %u LSN: (%lu,0x%lx)",
118 : rec->type, LSN_IN_PARTS(rec->lsn));
119 6397 : ok(1, buff);
120 : }
121 :
122 : /*
123 : Read whole record content, and check content (put with offset)
124 :
125 : SYNOPSIS
126 : read_and_check_content()
127 : rec The record header buffer
128 : buffer The buffer to read the record in
129 : skip Skip this number of bytes ot the record content
130 :
131 : RETURN
132 : 0 - OK
133 : 1 - Error
134 : */
135 :
136 : static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
137 : uchar *buffer, uint skip)
138 3198 : {
139 3198 : DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE * 2 + 7 * 2 + 2);
140 3198 : if (translog_read_record(rec->lsn, 0, rec->record_length, buffer, NULL) !=
141 : rec->record_length)
142 0 : return 1;
143 3198 : return check_content(buffer + skip, rec->record_length - skip);
144 : }
145 :
146 :
147 : int main(int argc __attribute__((unused)), char *argv[])
148 2 : {
149 : uint32 i;
150 : uint32 rec_len;
151 : uint pagen;
152 : uchar long_tr_id[6];
153 : uchar lsn_buff[23]=
154 : {
155 : 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
156 : 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
157 : 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55
158 2 : };
159 : uchar long_buffer[LONG_BUFFER_SIZE * 2 + LSN_STORE_SIZE * 2 + 2];
160 : PAGECACHE pagecache;
161 : LSN lsn, lsn_base, first_lsn;
162 : TRANSLOG_HEADER_BUFFER rec;
163 : LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 3];
164 : struct st_translog_scanner_data scanner;
165 : int rc;
166 :
167 2 : MY_INIT(argv[0]);
168 :
169 2 : if (my_set_max_open_files(100) < 100)
170 : {
171 0 : fprintf(stderr, "can't allocate 100 file descriptors\n");
172 0 : exit(1);
173 : }
174 2 : bzero(&pagecache, sizeof(pagecache));
175 2 : maria_data_root= (char *)".";
176 2 : if (maria_log_remove())
177 0 : exit(1);
178 :
179 102418 : for (i= 0; i < (LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2); i+= 2)
180 : {
181 102416 : int2store(long_buffer + i, (i >> 1));
182 : /* long_buffer[i]= (i & 0xFF); */
183 : }
184 :
185 2 : bzero(long_tr_id, 6);
186 : #ifndef DBUG_OFF
187 : #if defined(__WIN__)
188 : default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
189 : #else
190 2 : default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
191 : #endif
192 2 : if (argc > 1)
193 : {
194 0 : DBUG_SET(default_dbug_option);
195 0 : DBUG_SET_INITIAL(default_dbug_option);
196 : }
197 : #endif
198 :
199 2 : if (ma_control_file_open(TRUE, TRUE))
200 : {
201 0 : fprintf(stderr, "Can't init control file (%d)\n", errno);
202 0 : exit(1);
203 : }
204 2 : if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
205 : TRANSLOG_PAGE_SIZE, 0)) == 0)
206 : {
207 0 : fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
208 0 : exit(1);
209 : }
210 2 : if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
211 : LOG_FLAGS, 0, &translog_example_table_init,
212 : 0))
213 : {
214 0 : fprintf(stderr, "Can't init loghandler (%d)\n", errno);
215 0 : exit(1);
216 : }
217 : /* Suppressing of automatic record writing */
218 2 : trn->first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
219 :
220 2 : plan(((ITERATIONS - 1) * 4 + 1)*2 + ITERATIONS - 1 + 1);
221 :
222 1 : SKIP_BIG_TESTS(((ITERATIONS - 1) * 4 + 1)*2 + ITERATIONS - 1 + 1)
223 : {
224 :
225 1 : srand(122334817L);
226 :
227 1 : long_tr_id[5]= 0xff;
228 :
229 1 : int4store(long_tr_id, 0);
230 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
231 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
232 1 : trn->short_id= 0;
233 1 : trn->first_undo_lsn= TRANSACTION_LOGGED_LONG_ID;
234 1 : if (translog_write_record(&lsn,
235 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
236 : trn, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1,
237 : parts, NULL, NULL))
238 : {
239 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
240 0 : translog_destroy();
241 0 : ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
242 0 : exit(1);
243 : }
244 1 : ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
245 1 : lsn_base= first_lsn= lsn;
246 :
247 1600 : for (i= 1; i < ITERATIONS; i++)
248 : {
249 1599 : trn->short_id= i % 0xFFFF;
250 1599 : if (i % 2)
251 : {
252 800 : lsn_store(lsn_buff, lsn_base);
253 800 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
254 800 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
255 : /* check auto-count feature */
256 800 : parts[TRANSLOG_INTERNAL_PARTS + 1].str= NULL;
257 800 : parts[TRANSLOG_INTERNAL_PARTS + 1].length= 0;
258 800 : if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_1LSN_EXAMPLE, trn,
259 : NULL, LSN_STORE_SIZE, 0, parts, NULL, NULL))
260 : {
261 0 : fprintf(stderr, "1 Can't write reference defore record #%lu\n",
262 : (ulong) i);
263 0 : translog_destroy();
264 0 : ok(0, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
265 0 : exit(1);
266 : }
267 800 : ok(1, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
268 800 : lsn_store(lsn_buff, lsn_base);
269 800 : if ((rec_len= rand_buffer_size()) < 12)
270 0 : rec_len= 12;
271 800 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
272 800 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
273 800 : parts[TRANSLOG_INTERNAL_PARTS + 1].str= long_buffer;
274 800 : parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
275 : /* check record length auto-counting */
276 800 : if (translog_write_record(&lsn,
277 : LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
278 : trn, NULL, 0, TRANSLOG_INTERNAL_PARTS + 2,
279 : parts, NULL, NULL))
280 : {
281 0 : fprintf(stderr, "1 Can't write var reference defore record #%lu\n",
282 : (ulong) i);
283 0 : translog_destroy();
284 0 : ok(0, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
285 0 : exit(1);
286 : }
287 800 : ok(1, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
288 : }
289 : else
290 : {
291 799 : lsn_store(lsn_buff, lsn_base);
292 799 : lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
293 799 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
294 799 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 23;
295 799 : if (translog_write_record(&lsn,
296 : LOGREC_FIXED_RECORD_2LSN_EXAMPLE,
297 : trn, NULL, 23, TRANSLOG_INTERNAL_PARTS + 1,
298 : parts, NULL, NULL))
299 : {
300 0 : fprintf(stderr, "0 Can't write reference defore record #%lu\n",
301 : (ulong) i);
302 0 : translog_destroy();
303 0 : ok(0, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
304 0 : exit(1);
305 : }
306 799 : ok(1, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
307 799 : lsn_store(lsn_buff, lsn_base);
308 799 : lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
309 799 : if ((rec_len= rand_buffer_size()) < 19)
310 0 : rec_len= 19;
311 799 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
312 799 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 14;
313 799 : parts[TRANSLOG_INTERNAL_PARTS + 1].str= long_buffer;
314 799 : parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
315 799 : if (translog_write_record(&lsn,
316 : LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE,
317 : trn, NULL, 14 + rec_len,
318 : TRANSLOG_INTERNAL_PARTS + 2, parts, NULL,
319 : NULL))
320 : {
321 0 : fprintf(stderr, "0 Can't write var reference defore record #%lu\n",
322 : (ulong) i);
323 0 : translog_destroy();
324 0 : ok(0, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
325 0 : exit(1);
326 : }
327 799 : ok(1, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
328 : }
329 1599 : int4store(long_tr_id, i);
330 1599 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
331 1599 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
332 1599 : if (translog_write_record(&lsn,
333 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
334 : trn, NULL, 6,
335 : TRANSLOG_INTERNAL_PARTS + 1,
336 : parts, NULL, NULL))
337 : {
338 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) i);
339 0 : translog_destroy();
340 0 : ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
341 0 : exit(1);
342 : }
343 1599 : ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
344 :
345 1599 : lsn_base= lsn;
346 :
347 1599 : if ((rec_len= rand_buffer_size()) < 9)
348 0 : rec_len= 9;
349 1599 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_buffer;
350 1599 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= rec_len;
351 1599 : if (translog_write_record(&lsn,
352 : LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE,
353 : trn, NULL, rec_len,
354 : TRANSLOG_INTERNAL_PARTS + 1,
355 : parts, NULL, NULL))
356 : {
357 0 : fprintf(stderr, "Can't write variable record #%lu\n", (ulong) i);
358 0 : translog_destroy();
359 0 : ok(0, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
360 0 : exit(1);
361 : }
362 1599 : ok(1, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
363 1599 : if (translog_flush(lsn))
364 : {
365 0 : fprintf(stderr, "Can't flush #%lu\n", (ulong) i);
366 0 : translog_destroy();
367 0 : ok(0, "flush");
368 0 : exit(1);
369 : }
370 1599 : ok(1, "flush");
371 : }
372 :
373 1 : if (translog_flush(translog_get_horizon()))
374 : {
375 0 : fprintf(stderr, "Can't flush up to horizon\n");
376 0 : translog_destroy();
377 0 : ok(0, "flush");
378 0 : exit(1);
379 : }
380 1 : ok(1, "flush");
381 :
382 1 : srand(122334817L);
383 :
384 1 : rc= 1;
385 :
386 : {
387 1 : int len= translog_read_record_header(first_lsn, &rec);
388 1 : if (len == RECHEADER_READ_ERROR)
389 : {
390 0 : fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
391 0 : goto err;
392 : }
393 1 : if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 ||
394 : rec.record_length != 6 || uint4korr(rec.header) != 0 ||
395 : ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF ||
396 : first_lsn != rec.lsn)
397 : {
398 0 : fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
399 : "data read(0)\n"
400 : "type %u, strid %u, len %u, i: %u, 4: %u 5: %u, "
401 : "lsn(%lu,0x%lx)\n",
402 : (uint) rec.type, (uint) rec.short_trid, (uint) rec.record_length,
403 : (uint) uint4korr(rec.header), (uint) rec.header[4],
404 : (uint) rec.header[5],
405 : LSN_IN_PARTS(rec.lsn));
406 0 : goto err;
407 : }
408 1 : read_ok(&rec);
409 1 : translog_free_record_header(&rec);
410 1 : lsn= first_lsn;
411 1 : if (translog_scanner_init(first_lsn, 1, &scanner, 0))
412 : {
413 0 : fprintf(stderr, "scanner init failed\n");
414 0 : goto err;
415 : }
416 1600 : for (i= 1;; i++)
417 : {
418 1600 : len= translog_read_next_record_header(&scanner, &rec);
419 1600 : if (len == RECHEADER_READ_ERROR)
420 : {
421 0 : fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
422 : i, errno);
423 0 : goto err;
424 : }
425 1600 : if (len == RECHEADER_READ_EOF)
426 : {
427 1 : if (i != ITERATIONS)
428 : {
429 0 : fprintf(stderr, "EOL met at iteration %u instead of %u\n",
430 : i, ITERATIONS);
431 0 : goto err;
432 : }
433 : break;
434 : }
435 1599 : if (i % 2)
436 : {
437 : LSN ref;
438 800 : ref= lsn_korr(rec.header);
439 800 : if (rec.type != LOGREC_FIXED_RECORD_1LSN_EXAMPLE ||
440 : rec.short_trid != (i % 0xFFFF) ||
441 : rec.record_length != 7 || ref != lsn)
442 : {
443 0 : fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_1LSN_EXAMPLE "
444 : "data read(%d) "
445 : "type: %u strid: %u len: %u"
446 : "ref: (%lu,0x%lx) (%lu,0x%lx) "
447 : "lsn(%lu,0x%lx)\n",
448 : i, (uint) rec.type, (uint) rec.short_trid,
449 : (uint) rec.record_length,
450 : LSN_IN_PARTS(ref), LSN_IN_PARTS(lsn),
451 : LSN_IN_PARTS(rec.lsn));
452 0 : goto err;
453 : }
454 : }
455 : else
456 : {
457 : LSN ref1, ref2;
458 799 : ref1= lsn_korr(rec.header);
459 799 : ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
460 799 : if (rec.type != LOGREC_FIXED_RECORD_2LSN_EXAMPLE ||
461 : rec.short_trid != (i % 0xFFFF) ||
462 : rec.record_length != 23 ||
463 : ref1 != lsn ||
464 : ref2 != first_lsn ||
465 : ((uchar)rec.header[22]) != 0x55 ||
466 : ((uchar)rec.header[21]) != 0xAA ||
467 : ((uchar)rec.header[20]) != 0x55 ||
468 : ((uchar)rec.header[19]) != 0xAA ||
469 : ((uchar)rec.header[18]) != 0x55 ||
470 : ((uchar)rec.header[17]) != 0xAA ||
471 : ((uchar)rec.header[16]) != 0x55 ||
472 : ((uchar)rec.header[15]) != 0xAA ||
473 : ((uchar)rec.header[14]) != 0x55)
474 : {
475 0 : fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_2LSN_EXAMPLE "
476 : "data read(%d) "
477 : "type %u, strid %u, len %u, ref1(%lu,0x%lx), "
478 : "ref2(%lu,0x%lx) %x%x%x%x%x%x%x%x%x "
479 : "lsn(%lu,0x%lx)\n",
480 : i, (uint) rec.type, (uint) rec.short_trid,
481 : (uint) rec.record_length,
482 : LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
483 : (uint) rec.header[14], (uint) rec.header[15],
484 : (uint) rec.header[16], (uint) rec.header[17],
485 : (uint) rec.header[18], (uint) rec.header[19],
486 : (uint) rec.header[20], (uint) rec.header[21],
487 : (uint) rec.header[22],
488 : LSN_IN_PARTS(rec.lsn));
489 0 : goto err;
490 : }
491 : }
492 1599 : read_ok(&rec);
493 1599 : translog_free_record_header(&rec);
494 :
495 1599 : len= translog_read_next_record_header(&scanner, &rec);
496 1599 : if (len == RECHEADER_READ_ERROR)
497 : {
498 0 : fprintf(stderr, "1-%d translog_read_next_record_header (var) "
499 : "failed (%d)\n", i, errno);
500 0 : goto err;
501 : }
502 1599 : if (len == RECHEADER_READ_EOF)
503 : {
504 0 : fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
505 : "instead of beginning of %u\n", i, ITERATIONS);
506 0 : goto err;
507 : }
508 1599 : if (i % 2)
509 : {
510 : LSN ref;
511 800 : ref= lsn_korr(rec.header);
512 800 : if ((rec_len= rand_buffer_size()) < 12)
513 0 : rec_len= 12;
514 800 : if (rec.type != LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE ||
515 : rec.short_trid != (i % 0xFFFF) ||
516 : rec.record_length != rec_len + LSN_STORE_SIZE ||
517 : len != 12 || ref != lsn ||
518 : check_content(rec.header + LSN_STORE_SIZE, len - LSN_STORE_SIZE))
519 : {
520 0 : fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
521 : "data read(%d)"
522 : "type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
523 : "hdr len: %u (%d), "
524 : "ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
525 : i, (uint) rec.type,
526 : rec.type != LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
527 : (uint) rec.short_trid,
528 : rec.short_trid != (i % 0xFFFF),
529 : (ulong) rec.record_length, (ulong) rec_len,
530 : rec.record_length != rec_len + LSN_STORE_SIZE,
531 : (uint) len,
532 : len != 12,
533 : LSN_IN_PARTS(ref), LSN_IN_PARTS(rec.lsn),
534 : (len != 12 || ref != lsn),
535 : check_content(rec.header + LSN_STORE_SIZE,
536 : len - LSN_STORE_SIZE));
537 0 : goto err;
538 : }
539 800 : if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE))
540 : {
541 0 : fprintf(stderr,
542 : "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
543 : "in whole rec read lsn(%lu,0x%lx)\n",
544 : LSN_IN_PARTS(rec.lsn));
545 0 : goto err;
546 : }
547 : }
548 : else
549 : {
550 : LSN ref1, ref2;
551 799 : ref1= lsn_korr(rec.header);
552 799 : ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
553 799 : if ((rec_len= rand_buffer_size()) < 19)
554 0 : rec_len= 19;
555 799 : if (rec.type != LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE ||
556 : rec.short_trid != (i % 0xFFFF) ||
557 : rec.record_length != rec_len + LSN_STORE_SIZE * 2 ||
558 : len != 19 ||
559 : ref1 != lsn ||
560 : ref2 != first_lsn ||
561 : check_content(rec.header + LSN_STORE_SIZE * 2,
562 : len - LSN_STORE_SIZE * 2))
563 : {
564 0 : fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
565 : "data read(%d) "
566 : "type %u, strid %u, len %lu != %lu + 14, hdr len: %d, "
567 : "ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
568 : "lsn(%lu,0x%lx)\n",
569 : i, (uint) rec.type, (uint) rec.short_trid,
570 : (ulong) rec.record_length, (ulong) rec_len,
571 : len, LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
572 : LSN_IN_PARTS(rec.lsn));
573 0 : goto err;
574 : }
575 799 : if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE * 2))
576 : {
577 0 : fprintf(stderr,
578 : "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
579 : "in whole rec read lsn(%lu,0x%lx)\n",
580 : LSN_IN_PARTS(rec.lsn));
581 0 : goto err;
582 : }
583 : }
584 1599 : read_ok(&rec);
585 1599 : translog_free_record_header(&rec);
586 :
587 1599 : len= translog_read_next_record_header(&scanner, &rec);
588 1599 : if (len == RECHEADER_READ_ERROR)
589 : {
590 0 : fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
591 : i, errno);
592 0 : goto err;
593 : }
594 1599 : if (len == RECHEADER_READ_EOF)
595 : {
596 0 : fprintf(stderr, "EOL met at the middle of iteration %u "
597 : "instead of beginning of %u\n", i, ITERATIONS);
598 0 : goto err;
599 : }
600 1599 : if (rec.type != LOGREC_FIXED_RECORD_0LSN_EXAMPLE ||
601 : rec.short_trid != (i % 0xFFFF) ||
602 : rec.record_length != 6 || uint4korr(rec.header) != i ||
603 : ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF)
604 : {
605 0 : fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
606 : "data read(%d)\n"
607 : "type %u, strid %u, len %u, i: %u, 4: %u 5: %u "
608 : "lsn(%lu,0x%lx)\n",
609 : i, (uint) rec.type, (uint) rec.short_trid,
610 : (uint) rec.record_length,
611 : (uint) uint4korr(rec.header), (uint) rec.header[4],
612 : (uint) rec.header[5],
613 : LSN_IN_PARTS(rec.lsn));
614 0 : goto err;
615 : }
616 1599 : lsn= rec.lsn;
617 1599 : read_ok(&rec);
618 1599 : translog_free_record_header(&rec);
619 :
620 1599 : len= translog_read_next_record_header(&scanner, &rec);
621 1599 : if ((rec_len= rand_buffer_size()) < 9)
622 0 : rec_len= 9;
623 1599 : if (rec.type != LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE ||
624 : rec.short_trid != (i % 0xFFFF) ||
625 : rec.record_length != rec_len ||
626 : len != 9 || check_content(rec.header, (uint)len))
627 : {
628 0 : fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
629 : "data read(%d) "
630 : "type %u, strid %u, len %lu != %lu, hdr len: %d, "
631 : "lsn(%lu,0x%lx)\n",
632 : i, (uint) rec.type, (uint) rec.short_trid,
633 : (ulong) rec.record_length, (ulong) rec_len,
634 : len, LSN_IN_PARTS(rec.lsn));
635 0 : goto err;
636 : }
637 1599 : if (read_and_check_content(&rec, long_buffer, 0))
638 : {
639 0 : fprintf(stderr,
640 : "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
641 : "in whole rec read lsn(%lu,0x%lx)\n",
642 : LSN_IN_PARTS(rec.lsn));
643 0 : goto err;
644 : }
645 1599 : read_ok(&rec);
646 1599 : translog_free_record_header(&rec);
647 1599 : }
648 : }
649 :
650 1 : rc= 0;
651 1 : err:
652 1 : if (rc)
653 0 : ok(0, "read record");
654 : } /* SKIP_BIG_TESTS */
655 2 : translog_destroy();
656 2 : end_pagecache(&pagecache, 1);
657 2 : ma_control_file_end();
658 :
659 2 : if (maria_log_remove())
660 0 : exit(1);
661 :
662 2 : return(test(exit_status()));
663 : }
|