~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/maria/unittest/ma_test_loghandler_multigroup-t.c

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "sequence_storage.h"
 
22
#include <my_getopt.h>
 
23
 
 
24
extern my_bool maria_log_remove();
 
25
extern void translog_example_table_init();
 
26
 
 
27
#ifndef DBUG_OFF
 
28
static const char *default_dbug_option;
 
29
#endif
 
30
static TRN *trn= &dummy_transaction_object;
 
31
 
 
32
 
 
33
#ifndef READONLY_TEST
 
34
 
 
35
#define PCACHE_SIZE (1024*1024*10)
 
36
#define LONG_BUFFER_SIZE ((1024L*1024L*1024L) + (1024L*1024L*512))
 
37
#define MIN_REC_LENGTH (1024L*1024L + 1024L*512L + 1)
 
38
#define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
 
39
#define ITERATIONS 2
 
40
#define READONLY 0
 
41
 
 
42
#else
 
43
 
 
44
#define PCACHE_SIZE (1024*1024*10)
 
45
#define LONG_BUFFER_SIZE (1024L*1024L)
 
46
#define MIN_REC_LENGTH (1024L)
 
47
#define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
 
48
#define ITERATIONS 2
 
49
#define READONLY 1
 
50
 
 
51
#endif /*READONLY_TEST*/
 
52
 
 
53
 
 
54
/*
 
55
#define LOG_FILE_SIZE 1024L*1024L*3L
 
56
#define ITERATIONS 1600
 
57
*/
 
58
/*
 
59
#define LOG_FILE_SIZE 1024L*1024L*100L
 
60
#define ITERATIONS 65000
 
61
*/
 
62
 
 
63
 
 
64
/*
 
65
  Check that the buffer filled correctly
 
66
 
 
67
  SYNOPSIS
 
68
    check_content()
 
69
    ptr                  Pointer to the buffer
 
70
    length               length of the buffer
 
71
 
 
72
  RETURN
 
73
    0 - OK
 
74
    1 - Error
 
75
*/
 
76
 
 
77
static my_bool check_content(uchar *ptr, ulong length)
 
78
{
 
79
  ulong i;
 
80
  uchar buff[4];
 
81
  DBUG_ENTER("check_content");
 
82
  for (i= 0; i < length; i++)
 
83
  {
 
84
    if (i % 4 == 0)
 
85
      int4store(buff, (i >> 2));
 
86
    if (ptr[i] != buff[i % 4])
 
87
    {
 
88
      fprintf(stderr, "Byte # %lu is %x instead of %x",
 
89
              i, (uint) ptr[i], (uint) buff[i % 4]);
 
90
      DBUG_DUMP("mem", ptr +(ulong) (i > 16 ? i - 16 : 0),
 
91
                (i > 16 ? 16 : i) + (i + 16 < length ? 16 : length - i));
 
92
      DBUG_RETURN(1);
 
93
    }
 
94
  }
 
95
  DBUG_RETURN(0);
 
96
}
 
97
 
 
98
 
 
99
/*
 
100
  Read whole record content, and check content (put with offset)
 
101
 
 
102
  SYNOPSIS
 
103
    read_and_check_content()
 
104
    rec                  The record header buffer
 
105
    buffer               The buffer to read the record in
 
106
    skip                 Skip this number of bytes ot the record content
 
107
 
 
108
  RETURN
 
109
    0 - OK
 
110
    1 - Error
 
111
*/
 
112
 
 
113
static my_bool read_and_check_content(TRANSLOG_HEADER_BUFFER *rec,
 
114
                                      uchar *buffer, uint skip)
 
115
{
 
116
  int res= 0;
 
117
  translog_size_t len;
 
118
  DBUG_ENTER("read_and_check_content");
 
119
  DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2);
 
120
  if ((len= translog_read_record(rec->lsn, 0, rec->record_length,
 
121
                                 buffer, NULL)) != rec->record_length)
 
122
  {
 
123
    fprintf(stderr, "Requested %lu byte, read %lu\n",
 
124
            (ulong) rec->record_length, (ulong) len);
 
125
    res= 1;
 
126
  }
 
127
  res|= check_content(buffer + skip, rec->record_length - skip);
 
128
  DBUG_RETURN(res);
 
129
}
 
130
 
 
131
static const char *load_default_groups[]= {"ma_unit_loghandler", 0};
 
132
#ifndef DBUG_OFF
 
133
static const char *default_dbug_option=
 
134
  IF_WIN("d:t:i:O,\\ma_test_loghandler.trace",
 
135
         "d:t:i:o,/tmp/ma_test_loghandler.trace");
 
136
#endif
 
137
static const char *opt_wfile= NULL;
 
138
static const char *opt_rfile= NULL;
 
139
static struct my_option my_long_options[] =
 
140
{
 
141
#ifndef DBUG_OFF
 
142
  {"debug", '#', "Output debug log. Often the argument is 'd:t:o,filename'.",
 
143
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
144
#endif
 
145
  {"write-seq", 'w', "Path to file in which \"random\" sequence  used in the test will be written",
 
146
    (uchar**) &opt_wfile, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
147
  {"read-seq", 'r', "Path to file from which \"random\" sequence  used in the test will be read",
 
148
    (uchar**) &opt_rfile, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
149
  {"help", '?', "Display this help and exit.",
 
150
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
151
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
152
};
 
153
static SEQ_STORAGE seq;
 
154
 
 
155
static uint32 get_len()
 
156
{
 
157
  uint32 res;
 
158
  DBUG_ENTER("get_len");
 
159
  if (opt_rfile)
 
160
    res= seq_storage_next(&seq);
 
161
  else
 
162
  {
 
163
    res= (uint32)
 
164
      ((ulonglong) rand() *
 
165
       (LONG_BUFFER_SIZE - MIN_REC_LENGTH - 1) / RAND_MAX) + MIN_REC_LENGTH;
 
166
    if (opt_wfile &&
 
167
        seq_storage_write(opt_wfile, res))
 
168
      exit(1);
 
169
  }
 
170
  DBUG_PRINT("info", ("length value : %lu", (ulong) res));
 
171
  DBUG_RETURN(res);
 
172
}
 
173
 
 
174
static void usage(void)
 
175
{
 
176
  puts("Copyright (C) 2008 MySQL AB");
 
177
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,");
 
178
  puts("and you are welcome to modify and redistribute it under the GPL license\n");
 
179
 
 
180
  puts("Unit test of maria engine");
 
181
  (void)(printf("\nUsage: %s [OPTIONS]\n", my_progname_short));
 
182
  my_print_help(my_long_options);
 
183
  print_defaults("my", load_default_groups);
 
184
  my_print_variables(my_long_options);
 
185
}
 
186
 
 
187
 
 
188
static my_bool
 
189
get_one_option(int optid __attribute__((unused)),
 
190
               const struct my_option *opt __attribute__((unused)),
 
191
               char *argument __attribute__((unused)))
 
192
{
 
193
  switch (optid) {
 
194
  case '?':
 
195
    usage();
 
196
    exit(0);
 
197
#ifndef DBUG_OFF
 
198
  case '#':
 
199
    DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
 
200
    break;
 
201
#endif
 
202
  }
 
203
  return 0;
 
204
}
 
205
 
 
206
 
 
207
static void get_options(int *argc,char ***argv)
 
208
{
 
209
  int ho_error;
 
210
 
 
211
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
 
212
    exit(ho_error);
 
213
 
 
214
  if (opt_rfile && opt_wfile)
 
215
  {
 
216
    usage();
 
217
    exit(1);
 
218
  }
 
219
}
 
220
 
 
221
 
 
222
int main(int argc __attribute__((unused)), char *argv[])
 
223
{
 
224
  uint32 i;
 
225
  uint32 rec_len;
 
226
  uint pagen;
 
227
  uchar long_tr_id[6];
 
228
  uchar lsn_buff[23]=
 
229
  {
 
230
    0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
 
231
    0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
 
232
    0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55
 
233
  };
 
234
  uchar *long_buffer= malloc(LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2);
 
235
  char **default_argv;
 
236
  PAGECACHE pagecache;
 
237
  LSN lsn, lsn_base, first_lsn;
 
238
  TRANSLOG_HEADER_BUFFER rec;
 
239
  LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 2];
 
240
  struct st_translog_scanner_data scanner;
 
241
  int rc;
 
242
 
 
243
  MY_INIT(argv[0]);
 
244
 
 
245
  bzero(&pagecache, sizeof(pagecache));
 
246
  maria_data_root= (char *)".";
 
247
  load_defaults("my", load_default_groups, &argc, &argv);
 
248
  default_argv= argv;
 
249
  get_options(&argc, &argv);
 
250
 
 
251
  if (maria_log_remove())
 
252
    exit(1);
 
253
 
 
254
  {
 
255
    uchar buff[4];
 
256
    for (i= 0; i < (LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2); i++)
 
257
    {
 
258
      if (i % 4 == 0)
 
259
        int4store(buff, (i >> 2));
 
260
      long_buffer[i]= buff[i % 4];
 
261
    }
 
262
  }
 
263
 
 
264
  bzero(long_tr_id, 6);
 
265
 
 
266
  if (ma_control_file_open(TRUE, TRUE))
 
267
  {
 
268
    fprintf(stderr, "Can't init control file (%d)\n", errno);
 
269
    exit(1);
 
270
  }
 
271
  if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
 
272
                             TRANSLOG_PAGE_SIZE, 0)) == 0)
 
273
  {
 
274
    fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
 
275
    exit(1);
 
276
  }
 
277
  if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
 
278
                               0, 0, &translog_example_table_init, 0))
 
279
  {
 
280
    fprintf(stderr, "Can't init loghandler (%d)\n", errno);
 
281
    exit(1);
 
282
  }
 
283
  /* Suppressing of automatic record writing */
 
284
  trn->first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
 
285
 
 
286
  plan(((ITERATIONS - 1) * 4 + 1) * 2);
 
287
 
 
288
  if (opt_rfile &&
 
289
      seq_storage_reader_init(&seq, opt_rfile))
 
290
    exit(1);
 
291
  srand(122334817L);
 
292
 
 
293
  long_tr_id[5]= 0xff;
 
294
 
 
295
  int4store(long_tr_id, 0);
 
296
  parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id;
 
297
  parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
 
298
  trn->short_id= 0;
 
299
  trn->first_undo_lsn= TRANSACTION_LOGGED_LONG_ID;
 
300
  if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
 
301
                            trn, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts,
 
302
                            NULL, NULL))
 
303
  {
 
304
    fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
 
305
    translog_destroy();
 
306
    ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
 
307
    exit(1);
 
308
  }
 
309
  ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
 
310
  lsn_base= first_lsn= lsn;
 
311
 
 
312
  for (i= 1; i < ITERATIONS; i++)
 
313
  {
 
314
    if (i % 2)
 
315
    {
 
316
      lsn_store(lsn_buff, lsn_base);
 
317
      parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)lsn_buff;
 
318
      parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
 
319
      trn->short_id= i % 0xFFFF;
 
320
      if (translog_write_record(&lsn,
 
321
                                LOGREC_FIXED_RECORD_1LSN_EXAMPLE, trn, NULL,
 
322
                                LSN_STORE_SIZE, TRANSLOG_INTERNAL_PARTS + 1,
 
323
                                parts, NULL, NULL))
 
324
      {
 
325
        fprintf(stderr, "1 Can't write reference before record #%lu\n",
 
326
                (ulong) i);
 
327
        translog_destroy();
 
328
        ok(0, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
 
329
        exit(1);
 
330
      }
 
331
      ok(1, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
 
332
      lsn_store(lsn_buff, lsn_base);
 
333
      rec_len= get_len();
 
334
      parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)lsn_buff;
 
335
      parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
 
336
      parts[TRANSLOG_INTERNAL_PARTS + 1].str= (char*)long_buffer;
 
337
      parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
 
338
      trn->short_id= i % 0xFFFF;
 
339
      if (translog_write_record(&lsn,
 
340
                                LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
 
341
                                trn, NULL, LSN_STORE_SIZE + rec_len,
 
342
                                TRANSLOG_INTERNAL_PARTS + 2,
 
343
                                parts, NULL, NULL))
 
344
      {
 
345
        fprintf(stderr, "1 Can't write var reference before record #%lu\n",
 
346
                (ulong) i);
 
347
        translog_destroy();
 
348
        ok(0, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
 
349
        exit(1);
 
350
      }
 
351
      ok(1, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
 
352
    }
 
353
    else
 
354
    {
 
355
      lsn_store(lsn_buff, lsn_base);
 
356
      lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
 
357
      parts[TRANSLOG_INTERNAL_PARTS + 1].str= (char*)lsn_buff;
 
358
      parts[TRANSLOG_INTERNAL_PARTS + 1].length= 23;
 
359
      trn->short_id= i % 0xFFFF;
 
360
      if (translog_write_record(&lsn,
 
361
                                LOGREC_FIXED_RECORD_2LSN_EXAMPLE,
 
362
                                trn, NULL, 23, TRANSLOG_INTERNAL_PARTS + 1,
 
363
                                parts, NULL, NULL))
 
364
      {
 
365
        fprintf(stderr, "0 Can't write reference before record #%lu\n",
 
366
                (ulong) i);
 
367
        translog_destroy();
 
368
        ok(0, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
 
369
        exit(1);
 
370
      }
 
371
      ok(1, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
 
372
      lsn_store(lsn_buff, lsn_base);
 
373
      lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
 
374
      rec_len= get_len();
 
375
      parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)lsn_buff;
 
376
      parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE * 2;
 
377
      parts[TRANSLOG_INTERNAL_PARTS + 1].str= (char*)long_buffer;
 
378
      parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
 
379
      trn->short_id= i % 0xFFFF;
 
380
      if (translog_write_record(&lsn,
 
381
                                LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE,
 
382
                                trn, NULL, LSN_STORE_SIZE * 2 + rec_len,
 
383
                                TRANSLOG_INTERNAL_PARTS + 2,
 
384
                                parts, NULL, NULL))
 
385
      {
 
386
        fprintf(stderr, "0 Can't write var reference before record #%lu\n",
 
387
                (ulong) i);
 
388
        translog_destroy();
 
389
        ok(0, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
 
390
        exit(1);
 
391
      }
 
392
      ok(1, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
 
393
    }
 
394
    int4store(long_tr_id, i);
 
395
    parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_tr_id;
 
396
    parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
 
397
    trn->short_id= i % 0xFFFF;
 
398
    if (translog_write_record(&lsn,
 
399
                              LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
 
400
                              trn, NULL, 6,
 
401
                              TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
 
402
    {
 
403
      fprintf(stderr, "Can't write record #%lu\n", (ulong) i);
 
404
      translog_destroy();
 
405
      ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
 
406
      exit(1);
 
407
    }
 
408
    ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
 
409
 
 
410
    lsn_base= lsn;
 
411
 
 
412
    rec_len= get_len();
 
413
    parts[TRANSLOG_INTERNAL_PARTS + 0].str= (char*)long_buffer;
 
414
    parts[TRANSLOG_INTERNAL_PARTS + 0].length= rec_len;
 
415
    trn->short_id= i % 0xFFFF;
 
416
    if (translog_write_record(&lsn,
 
417
                              LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE,
 
418
                              trn, NULL, rec_len,
 
419
                              TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
 
420
    {
 
421
      fprintf(stderr, "Can't write variable record #%lu\n", (ulong) i);
 
422
      translog_destroy();
 
423
      ok(0, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
 
424
      exit(1);
 
425
    }
 
426
    ok(1, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
 
427
  }
 
428
 
 
429
  translog_destroy();
 
430
  end_pagecache(&pagecache, 1);
 
431
  ma_control_file_end();
 
432
 
 
433
  if (ma_control_file_open(TRUE,TRUE))
 
434
  {
 
435
    fprintf(stderr, "pass2: Can't init control file (%d)\n", errno);
 
436
    exit(1);
 
437
  }
 
438
  if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
 
439
                             TRANSLOG_PAGE_SIZE, 0)) == 0)
 
440
  {
 
441
    fprintf(stderr, "pass2: Got error: init_pagecache() (errno: %d)\n", errno);
 
442
    exit(1);
 
443
  }
 
444
  if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
 
445
                               0, READONLY, &translog_example_table_init, 0))
 
446
  {
 
447
    fprintf(stderr, "pass2: Can't init loghandler (%d)\n", errno);
 
448
    exit(1);
 
449
  }
 
450
 
 
451
 
 
452
  /* If we were writing sequence we need it only once */
 
453
  opt_wfile= NULL;
 
454
  if (opt_rfile)
 
455
    seq_storage_rewind(&seq);
 
456
  srand(122334817L);
 
457
 
 
458
  rc= 1;
 
459
 
 
460
  {
 
461
    int len= translog_read_record_header(first_lsn, &rec);
 
462
    if (len == RECHEADER_READ_ERROR)
 
463
    {
 
464
      fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
 
465
      translog_free_record_header(&rec);
 
466
      goto err;
 
467
    }
 
468
    if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 ||
 
469
        rec.record_length != 6 || uint4korr(rec.header) != 0 ||
 
470
        ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF ||
 
471
        first_lsn != rec.lsn)
 
472
    {
 
473
      fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
 
474
              "data read(0)\n"
 
475
              "type %u, strid %u, len %u, i: %u, 4: %u 5: %u, "
 
476
              "lsn(0x%lu,0x%lx)\n",
 
477
              (uint) rec.type, (uint) rec.short_trid, (uint) rec.record_length,
 
478
              (uint)uint4korr(rec.header), (uint) rec.header[4],
 
479
              (uint) rec.header[5],
 
480
              LSN_IN_PARTS(rec.lsn));
 
481
      translog_free_record_header(&rec);
 
482
      goto err;
 
483
    }
 
484
    ok(1, "read record");
 
485
    translog_free_record_header(&rec);
 
486
    lsn= first_lsn;
 
487
    if (translog_scanner_init(first_lsn, 1, &scanner, 0))
 
488
    {
 
489
      fprintf(stderr, "scanner init failed\n");
 
490
      goto err;
 
491
    }
 
492
    for (i= 1;; i++)
 
493
    {
 
494
      len= translog_read_next_record_header(&scanner, &rec);
 
495
      if (len == RECHEADER_READ_ERROR)
 
496
      {
 
497
        fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
 
498
                i, errno);
 
499
        translog_free_record_header(&rec);
 
500
        goto err;
 
501
      }
 
502
      if (len == RECHEADER_READ_EOF)
 
503
      {
 
504
        if (i != ITERATIONS)
 
505
        {
 
506
          fprintf(stderr, "EOL met at iteration %u instead of %u\n",
 
507
                  i, ITERATIONS);
 
508
          translog_free_record_header(&rec);
 
509
          goto err;
 
510
        }
 
511
        break;
 
512
      }
 
513
 
 
514
      if (i % 2)
 
515
      {
 
516
        LSN ref;
 
517
        ref= lsn_korr(rec.header);
 
518
        if (rec.type != LOGREC_FIXED_RECORD_1LSN_EXAMPLE ||
 
519
            rec.short_trid != (i % 0xFFFF) ||
 
520
            rec.record_length != LSN_STORE_SIZE || ref != lsn)
 
521
        {
 
522
          fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_1LSN_EXAMPLE "
 
523
                  "data read(%d)"
 
524
                  "type %u, strid %u, len %u, ref(%lu,0x%lx), lsn(%lu,0x%lx)\n",
 
525
                  i, (uint) rec.type, (uint) rec.short_trid,
 
526
                  (uint) rec.record_length,
 
527
                  LSN_IN_PARTS(ref), LSN_IN_PARTS(rec.lsn));
 
528
          translog_free_record_header(&rec);
 
529
          goto err;
 
530
        }
 
531
      }
 
532
      else
 
533
      {
 
534
        LSN ref1, ref2;
 
535
        ref1= lsn_korr(rec.header);
 
536
        ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
 
537
        if (rec.type != LOGREC_FIXED_RECORD_2LSN_EXAMPLE ||
 
538
            rec.short_trid != (i % 0xFFFF) ||
 
539
            rec.record_length != 23 ||
 
540
            ref1 != lsn ||
 
541
            ref2 != first_lsn ||
 
542
            ((uchar)rec.header[22]) != 0x55 ||
 
543
            ((uchar)rec.header[21]) != 0xAA ||
 
544
            ((uchar)rec.header[20]) != 0x55 ||
 
545
            ((uchar)rec.header[19]) != 0xAA ||
 
546
            ((uchar)rec.header[18]) != 0x55 ||
 
547
            ((uchar)rec.header[17]) != 0xAA ||
 
548
            ((uchar)rec.header[16]) != 0x55 ||
 
549
            ((uchar)rec.header[15]) != 0xAA ||
 
550
            ((uchar)rec.header[14]) != 0x55)
 
551
        {
 
552
          fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_2LSN_EXAMPLE "
 
553
                  "data read(%d) "
 
554
                  "type %u, strid %u, len %u, ref1(%lu,0x%lx), "
 
555
                  "ref2(%lu,0x%lx) %x%x%x%x%x%x%x%x%x "
 
556
                  "lsn(%lu,0x%lx)\n",
 
557
                  i, (uint) rec.type, (uint) rec.short_trid,
 
558
                  (uint) rec.record_length,
 
559
                  LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
 
560
                  (uint) rec.header[14], (uint) rec.header[15],
 
561
                  (uint) rec.header[16], (uint) rec.header[17],
 
562
                  (uint) rec.header[18], (uint) rec.header[19],
 
563
                  (uint) rec.header[20], (uint) rec.header[21],
 
564
                  (uint) rec.header[22],
 
565
                  LSN_IN_PARTS(rec.lsn));
 
566
          translog_free_record_header(&rec);
 
567
          DBUG_ASSERT(0);
 
568
          goto err;
 
569
        }
 
570
      }
 
571
      ok(1, "read record");
 
572
      translog_free_record_header(&rec);
 
573
 
 
574
      len= translog_read_next_record_header(&scanner, &rec);
 
575
      if (len == RECHEADER_READ_ERROR)
 
576
      {
 
577
        fprintf(stderr, "1-%d translog_read_next_record_header (var) "
 
578
                "failed (%d)\n", i, errno);
 
579
        goto err;
 
580
      }
 
581
      if (len == RECHEADER_READ_EOF)
 
582
      {
 
583
        fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
 
584
                "instead of beginning of %u\n", i, ITERATIONS);
 
585
        goto err;
 
586
      }
 
587
      if (i % 2)
 
588
      {
 
589
        LSN ref;
 
590
        ref= lsn_korr(rec.header);
 
591
        rec_len= get_len();
 
592
        if (rec.type !=LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE ||
 
593
            rec.short_trid != (i % 0xFFFF) ||
 
594
            rec.record_length != rec_len + LSN_STORE_SIZE ||
 
595
            len != 12 || ref != lsn ||
 
596
            check_content(rec.header + LSN_STORE_SIZE, len - LSN_STORE_SIZE))
 
597
        {
 
598
          fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
 
599
                  "data read(%d)"
 
600
                  "type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
 
601
                  "hdr len: %d (%d), "
 
602
                  "ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
 
603
                  i, (uint) rec.type,
 
604
                  rec.type !=LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
 
605
                  (uint) rec.short_trid,
 
606
                  rec.short_trid != (i % 0xFFFF),
 
607
                  (ulong) rec.record_length, (ulong) rec_len,
 
608
                  rec.record_length != rec_len + LSN_STORE_SIZE,
 
609
                  len,
 
610
                  len != 12,
 
611
                  LSN_IN_PARTS(ref), LSN_IN_PARTS(rec.lsn),
 
612
                  (ref != lsn),
 
613
                  check_content(rec.header + LSN_STORE_SIZE,
 
614
                                len - LSN_STORE_SIZE));
 
615
          translog_free_record_header(&rec);
 
616
          goto err;
 
617
        }
 
618
        if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE))
 
619
        {
 
620
          fprintf(stderr,
 
621
                  "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
 
622
                  "in whole rec read lsn(%lu,0x%lx)\n",
 
623
                  LSN_IN_PARTS(rec.lsn));
 
624
          translog_free_record_header(&rec);
 
625
          goto err;
 
626
        }
 
627
      }
 
628
      else
 
629
      {
 
630
        LSN ref1, ref2;
 
631
        ref1= lsn_korr(rec.header);
 
632
        ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
 
633
        rec_len= get_len();
 
634
        if (rec.type != LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE ||
 
635
            rec.short_trid != (i % 0xFFFF) ||
 
636
            rec.record_length != rec_len + LSN_STORE_SIZE * 2 ||
 
637
            len != 19 ||
 
638
            ref1 != lsn ||
 
639
            ref2 != first_lsn ||
 
640
            check_content(rec.header + LSN_STORE_SIZE * 2,
 
641
                          len - LSN_STORE_SIZE * 2))
 
642
        {
 
643
          fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
 
644
                  " data read(%d) "
 
645
                  "type %u, strid %u, len %lu != %lu + 14, hdr len: %d, "
 
646
                  "ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
 
647
                  "lsn(%lu,0x%lx)\n",
 
648
                  i, (uint) rec.type, (uint) rec.short_trid,
 
649
                  (ulong) rec.record_length, (ulong) rec_len,
 
650
                  len,
 
651
                  LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
 
652
                  LSN_IN_PARTS(rec.lsn));
 
653
          translog_free_record_header(&rec);
 
654
          goto err;
 
655
        }
 
656
        if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE * 2))
 
657
        {
 
658
          fprintf(stderr,
 
659
                  "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
 
660
                  "in whole rec read lsn(%lu,0x%lx)\n",
 
661
                  LSN_IN_PARTS(rec.lsn));
 
662
          translog_free_record_header(&rec);
 
663
          goto err;
 
664
        }
 
665
      }
 
666
      ok(1, "read record");
 
667
      translog_free_record_header(&rec);
 
668
 
 
669
      len= translog_read_next_record_header(&scanner, &rec);
 
670
      if (len == RECHEADER_READ_ERROR)
 
671
      {
 
672
        fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
 
673
                i, errno);
 
674
        translog_free_record_header(&rec);
 
675
        goto err;
 
676
      }
 
677
      if (len == RECHEADER_READ_EOF)
 
678
      {
 
679
        fprintf(stderr, "EOL met at the middle of iteration %u "
 
680
                "instead of beginning of %u\n", i, ITERATIONS);
 
681
        translog_free_record_header(&rec);
 
682
        goto err;
 
683
      }
 
684
      if (rec.type != LOGREC_FIXED_RECORD_0LSN_EXAMPLE ||
 
685
          rec.short_trid != (i % 0xFFFF) ||
 
686
          rec.record_length != 6 || uint4korr(rec.header) != i ||
 
687
          ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF)
 
688
      {
 
689
        fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
 
690
                "data read(%d)\n"
 
691
                "type %u, strid %u, len %u, i: %u, 4: %u 5: %u "
 
692
                "lsn(%lu,0x%lx)\n",
 
693
                i, (uint) rec.type, (uint) rec.short_trid,
 
694
                (uint) rec.record_length,
 
695
                (uint)uint4korr(rec.header), (uint) rec.header[4],
 
696
                (uint) rec.header[5],
 
697
                LSN_IN_PARTS(rec.lsn));
 
698
        translog_free_record_header(&rec);
 
699
        goto err;
 
700
      }
 
701
      ok(1, "read record");
 
702
      translog_free_record_header(&rec);
 
703
 
 
704
      lsn= rec.lsn;
 
705
 
 
706
      len= translog_read_next_record_header(&scanner, &rec);
 
707
      rec_len= get_len();
 
708
      if (rec.type != LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE ||
 
709
          rec.short_trid != (i % 0xFFFF) ||
 
710
          rec.record_length != rec_len ||
 
711
          len != 9 || check_content(rec.header, len))
 
712
      {
 
713
        fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
 
714
                "data read(%d) "
 
715
                "type %u, strid %u, len %lu != %lu, hdr len: %d, "
 
716
                "lsn(%lu,0x%lx)\n",
 
717
                i, (uint) rec.type, (uint) rec.short_trid,
 
718
                (ulong) rec.record_length, (ulong) rec_len,
 
719
                len, LSN_IN_PARTS(rec.lsn));
 
720
        translog_free_record_header(&rec);
 
721
        goto err;
 
722
      }
 
723
      if (read_and_check_content(&rec, long_buffer, 0))
 
724
      {
 
725
        fprintf(stderr,
 
726
                "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
 
727
                "in whole rec read lsn(%lu,0x%lx)\n",
 
728
                LSN_IN_PARTS(rec.lsn));
 
729
        translog_free_record_header(&rec);
 
730
        goto err;
 
731
      }
 
732
      ok(1, "read record");
 
733
      translog_free_record_header(&rec);
 
734
    }
 
735
  }
 
736
 
 
737
  rc= 0;
 
738
err:
 
739
  if (rc)
 
740
    ok(0, "read record");
 
741
  translog_destroy();
 
742
  end_pagecache(&pagecache, 1);
 
743
  ma_control_file_end();
 
744
  free_defaults(default_argv);
 
745
  seq_storage_destroy(&seq);
 
746
  if (maria_log_remove())
 
747
    exit(1);
 
748
 
 
749
  return (test(exit_status()));
 
750
}
 
751
 
 
752
#include "../ma_check_standalone.h"