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