LTP GCOV extension - code coverage report
Current view: directory - storage/maria/unittest - ma_test_loghandler_multigroup-t.c
Test: mtr_and_unit.info
Date: 2009-03-05 Instrumented lines: 292
Code covered: 50.0 % Executed lines: 146

       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               8 : {
      79                 :   ulong i;
      80                 :   uchar buff[4];
      81               8 :   DBUG_ENTER("check_content");
      82      1095640653 :   for (i= 0; i < length; i++)
      83                 :   {
      84      1095640645 :     if (i % 4 == 0)
      85       273910165 :       int4store(buff, (i >> 2));
      86      1095640645 :     if (ptr[i] != buff[i % 4])
      87                 :     {
      88               0 :       fprintf(stderr, "Byte # %lu is %x instead of %x",
      89                 :               i, (uint) ptr[i], (uint) buff[i % 4]);
      90               0 :       DBUG_DUMP("mem", ptr +(ulong) (i > 16 ? i - 16 : 0),
      91                 :                 (i > 16 ? 16 : i) + (i + 16 < length ? 16 : length - i));
      92               0 :       DBUG_RETURN(1);
      93                 :     }
      94                 :   }
      95               8 :   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               4 : {
     116               4 :   int res= 0;
     117                 :   translog_size_t len;
     118               4 :   DBUG_ENTER("read_and_check_content");
     119               4 :   DBUG_ASSERT(rec->record_length < LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2);
     120               4 :   if ((len= translog_read_record(rec->lsn, 0, rec->record_length,
     121                 :                                  buffer, NULL)) != rec->record_length)
     122                 :   {
     123               0 :     fprintf(stderr, "Requested %lu byte, read %lu\n",
     124                 :             (ulong) rec->record_length, (ulong) len);
     125               0 :     res= 1;
     126                 :   }
     127               4 :   res|= check_content(buffer + skip, rec->record_length - skip);
     128               4 :   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               8 : {
     157                 :   uint32 res;
     158               8 :   DBUG_ENTER("get_len");
     159               8 :   if (opt_rfile)
     160               0 :     res= seq_storage_next(&seq);
     161                 :   else
     162                 :   {
     163               8 :     res= (uint32)
     164                 :       ((ulonglong) rand() *
     165                 :        (LONG_BUFFER_SIZE - MIN_REC_LENGTH - 1) / RAND_MAX) + MIN_REC_LENGTH;
     166               8 :     if (opt_wfile &&
     167                 :         seq_storage_write(opt_wfile, res))
     168               0 :       exit(1);
     169                 :   }
     170               8 :   DBUG_PRINT("info", ("length value : %lu", (ulong) res));
     171               8 :   DBUG_RETURN(res);
     172                 : }
     173                 : 
     174                 : static void usage(void)
     175               0 : {
     176               0 :   puts("Copyright (C) 2008 MySQL AB");
     177               0 :   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,");
     178               0 :   puts("and you are welcome to modify and redistribute it under the GPL license\n");
     179                 : 
     180               0 :   puts("Unit test of maria engine");
     181               0 :   VOID(printf("\nUsage: %s [OPTIONS]\n", my_progname_short));
     182               0 :   my_print_help(my_long_options);
     183               0 :   print_defaults("my", load_default_groups);
     184               0 :   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               0 : {
     193               0 :   switch (optid) {
     194                 :   case '?':
     195               0 :     usage();
     196               0 :     exit(0);
     197                 : #ifndef DBUG_OFF
     198                 :   case '#':
     199               0 :     DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
     200                 :     break;
     201                 : #endif
     202                 :   }
     203               0 :   return 0;
     204                 : }
     205                 : 
     206                 : 
     207                 : static void get_options(int *argc,char ***argv)
     208               2 : {
     209                 :   int ho_error;
     210                 : 
     211               2 :   if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
     212               0 :     exit(ho_error);
     213                 : 
     214               2 :   if (opt_rfile && opt_wfile)
     215                 :   {
     216               0 :     usage();
     217               0 :     exit(1);
     218                 :   }
     219                 : }
     220                 : 
     221                 : 
     222                 : int main(int argc __attribute__((unused)), char *argv[])
     223               2 : {
     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               2 :   };
     234               2 :   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               2 :   MY_INIT(argv[0]);
     244                 : 
     245               2 :   bzero(&pagecache, sizeof(pagecache));
     246               2 :   maria_data_root= (char *)".";
     247               2 :   load_defaults("my", load_default_groups, &argc, &argv);
     248               2 :   default_argv= argv;
     249               2 :   get_options(&argc, &argv);
     250                 : 
     251               2 :   if (maria_log_remove())
     252               0 :     exit(1);
     253                 : 
     254                 :   {
     255                 :     uchar buff[4];
     256      1611661346 :     for (i= 0; i < (LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2); i++)
     257                 :     {
     258      1611661344 :       if (i % 4 == 0)
     259       402915336 :         int4store(buff, (i >> 2));
     260      1611661344 :       long_buffer[i]= buff[i % 4];
     261                 :     }
     262                 :   }
     263                 : 
     264               2 :   bzero(long_tr_id, 6);
     265                 : 
     266               2 :   if (ma_control_file_open(TRUE, TRUE))
     267                 :   {
     268               0 :     fprintf(stderr, "Can't init control file (%d)\n", errno);
     269               0 :     exit(1);
     270                 :   }
     271               2 :   if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
     272                 :                              TRANSLOG_PAGE_SIZE, 0)) == 0)
     273                 :   {
     274               0 :     fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
     275               0 :     exit(1);
     276                 :   }
     277               2 :   if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
     278                 :                                0, 0, &translog_example_table_init, 0))
     279                 :   {
     280               0 :     fprintf(stderr, "Can't init loghandler (%d)\n", errno);
     281               0 :     exit(1);
     282                 :   }
     283                 :   /* Suppressing of automatic record writing */
     284               2 :   trn->first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
     285                 : 
     286               2 :   plan(((ITERATIONS - 1) * 4 + 1) * 2);
     287                 : 
     288               2 :   if (opt_rfile &&
     289                 :       seq_storage_reader_init(&seq, opt_rfile))
     290               0 :     exit(1);
     291               2 :   srand(122334817L);
     292                 : 
     293               2 :   long_tr_id[5]= 0xff;
     294                 : 
     295               2 :   int4store(long_tr_id, 0);
     296               2 :   parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
     297               2 :   parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
     298               2 :   trn->short_id= 0;
     299               2 :   trn->first_undo_lsn= TRANSACTION_LOGGED_LONG_ID;
     300               2 :   if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
     301                 :                             trn, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts,
     302                 :                             NULL, NULL))
     303                 :   {
     304               0 :     fprintf(stderr, "Can't write record #%u\n", 0);
     305               0 :     translog_destroy();
     306               0 :     ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
     307               0 :     exit(1);
     308                 :   }
     309               2 :   ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
     310               2 :   lsn_base= first_lsn= lsn;
     311                 : 
     312               4 :   for (i= 1; i < ITERATIONS; i++)
     313                 :   {
     314               2 :     if (i % 2)
     315                 :     {
     316               2 :       lsn_store(lsn_buff, lsn_base);
     317               2 :       parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
     318               2 :       parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
     319               2 :       trn->short_id= i % 0xFFFF;
     320               2 :       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               0 :         fprintf(stderr, "1 Can't write reference before record #%u\n", i);
     326               0 :         translog_destroy();
     327               0 :         ok(0, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
     328               0 :         exit(1);
     329                 :       }
     330               2 :       ok(1, "write LOGREC_FIXED_RECORD_1LSN_EXAMPLE");
     331               2 :       lsn_store(lsn_buff, lsn_base);
     332               2 :       rec_len= get_len();
     333               2 :       parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
     334               2 :       parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE;
     335               2 :       parts[TRANSLOG_INTERNAL_PARTS + 1].str= long_buffer;
     336               2 :       parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
     337               2 :       trn->short_id= i % 0xFFFF;
     338               2 :       if (translog_write_record(&lsn,
     339                 :                                 LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
     340                 :                                 trn, NULL, LSN_STORE_SIZE + rec_len,
     341                 :                                 TRANSLOG_INTERNAL_PARTS + 2,
     342                 :                                 parts, NULL, NULL))
     343                 :       {
     344               0 :         fprintf(stderr, "1 Can't write var reference before record #%u\n", i);
     345               0 :         translog_destroy();
     346               0 :         ok(0, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
     347               0 :         exit(1);
     348                 :       }
     349               2 :       ok(1, "write LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE");
     350                 :     }
     351                 :     else
     352                 :     {
     353               0 :       lsn_store(lsn_buff, lsn_base);
     354               0 :       lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
     355               0 :       parts[TRANSLOG_INTERNAL_PARTS + 1].str= lsn_buff;
     356               0 :       parts[TRANSLOG_INTERNAL_PARTS + 1].length= 23;
     357               0 :       trn->short_id= i % 0xFFFF;
     358               0 :       if (translog_write_record(&lsn,
     359                 :                                 LOGREC_FIXED_RECORD_2LSN_EXAMPLE,
     360                 :                                 trn, NULL, 23, TRANSLOG_INTERNAL_PARTS + 1,
     361                 :                                 parts, NULL, NULL))
     362                 :       {
     363               0 :         fprintf(stderr, "0 Can't write reference before record #%u\n", i);
     364               0 :         translog_destroy();
     365               0 :         ok(0, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
     366               0 :         exit(1);
     367                 :       }
     368               0 :       ok(1, "write LOGREC_FIXED_RECORD_2LSN_EXAMPLE");
     369               0 :       lsn_store(lsn_buff, lsn_base);
     370               0 :       lsn_store(lsn_buff + LSN_STORE_SIZE, first_lsn);
     371               0 :       rec_len= get_len();
     372               0 :       parts[TRANSLOG_INTERNAL_PARTS + 0].str= lsn_buff;
     373               0 :       parts[TRANSLOG_INTERNAL_PARTS + 0].length= LSN_STORE_SIZE * 2;
     374               0 :       parts[TRANSLOG_INTERNAL_PARTS + 1].str= long_buffer;
     375               0 :       parts[TRANSLOG_INTERNAL_PARTS + 1].length= rec_len;
     376               0 :       trn->short_id= i % 0xFFFF;
     377               0 :       if (translog_write_record(&lsn,
     378                 :                                 LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE,
     379                 :                                 trn, NULL, LSN_STORE_SIZE * 2 + rec_len,
     380                 :                                 TRANSLOG_INTERNAL_PARTS + 2,
     381                 :                                 parts, NULL, NULL))
     382                 :       {
     383               0 :         fprintf(stderr, "0 Can't write var reference before record #%u\n", i);
     384               0 :         translog_destroy();
     385               0 :         ok(0, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
     386               0 :         exit(1);
     387                 :       }
     388               0 :       ok(1, "write LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE");
     389                 :     }
     390               2 :     int4store(long_tr_id, i);
     391               2 :     parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
     392               2 :     parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
     393               2 :     trn->short_id= i % 0xFFFF;
     394               2 :     if (translog_write_record(&lsn,
     395                 :                               LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
     396                 :                               trn, NULL, 6,
     397                 :                               TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
     398                 :     {
     399               0 :       fprintf(stderr, "Can't write record #%u\n", i);
     400               0 :       translog_destroy();
     401               0 :       ok(0, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
     402               0 :       exit(1);
     403                 :     }
     404               2 :     ok(1, "write LOGREC_FIXED_RECORD_0LSN_EXAMPLE");
     405                 : 
     406               2 :     lsn_base= lsn;
     407                 : 
     408               2 :     rec_len= get_len();
     409               2 :     parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_buffer;
     410               2 :     parts[TRANSLOG_INTERNAL_PARTS + 0].length= rec_len;
     411               2 :     trn->short_id= i % 0xFFFF;
     412               2 :     if (translog_write_record(&lsn,
     413                 :                               LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE,
     414                 :                               trn, NULL, rec_len,
     415                 :                               TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
     416                 :     {
     417               0 :       fprintf(stderr, "Can't write variable record #%u\n", i);
     418               0 :       translog_destroy();
     419               0 :       ok(0, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
     420               0 :       exit(1);
     421                 :     }
     422               2 :     ok(1, "write LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE");
     423                 :   }
     424                 : 
     425               2 :   translog_destroy();
     426               2 :   end_pagecache(&pagecache, 1);
     427               2 :   ma_control_file_end();
     428                 : 
     429               2 :   if (ma_control_file_open(TRUE,TRUE))
     430                 :   {
     431               0 :     fprintf(stderr, "pass2: Can't init control file (%d)\n", errno);
     432               0 :     exit(1);
     433                 :   }
     434               2 :   if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
     435                 :                              TRANSLOG_PAGE_SIZE, 0)) == 0)
     436                 :   {
     437               0 :     fprintf(stderr, "pass2: Got error: init_pagecache() (errno: %d)\n", errno);
     438               0 :     exit(1);
     439                 :   }
     440               2 :   if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
     441                 :                                0, READONLY, &translog_example_table_init, 0))
     442                 :   {
     443               0 :     fprintf(stderr, "pass2: Can't init loghandler (%d)\n", errno);
     444               0 :     exit(1);
     445                 :   }
     446                 : 
     447                 : 
     448                 :   /* If we were writing sequence we need it only once */
     449               2 :   opt_wfile= NULL;
     450               2 :   if (opt_rfile)
     451               0 :     seq_storage_rewind(&seq);
     452               2 :   srand(122334817L);
     453                 : 
     454               2 :   rc= 1;
     455                 : 
     456                 :   {
     457               2 :     int len= translog_read_record_header(first_lsn, &rec);
     458               2 :     if (len == RECHEADER_READ_ERROR)
     459                 :     {
     460               0 :       fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
     461               0 :       translog_free_record_header(&rec);
     462               0 :       goto err;
     463                 :     }
     464               2 :     if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 ||
     465                 :         rec.record_length != 6 || uint4korr(rec.header) != 0 ||
     466                 :         ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF ||
     467                 :         first_lsn != rec.lsn)
     468                 :     {
     469               0 :       fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
     470                 :               "data read(0)\n"
     471                 :               "type %u, strid %u, len %u, i: %u, 4: %u 5: %u, "
     472                 :               "lsn(0x%lu,0x%lx)\n",
     473                 :               (uint) rec.type, (uint) rec.short_trid, (uint) rec.record_length,
     474                 :               (uint)uint4korr(rec.header), (uint) rec.header[4],
     475                 :               (uint) rec.header[5],
     476                 :               LSN_IN_PARTS(rec.lsn));
     477               0 :       translog_free_record_header(&rec);
     478               0 :       goto err;
     479                 :     }
     480               2 :     ok(1, "read record");
     481               2 :     translog_free_record_header(&rec);
     482               2 :     lsn= first_lsn;
     483               2 :     if (translog_scanner_init(first_lsn, 1, &scanner, 0))
     484                 :     {
     485               0 :       fprintf(stderr, "scanner init failed\n");
     486               0 :       goto err;
     487                 :     }
     488               4 :     for (i= 1;; i++)
     489                 :     {
     490               4 :       len= translog_read_next_record_header(&scanner, &rec);
     491               4 :       if (len == RECHEADER_READ_ERROR)
     492                 :       {
     493               0 :         fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
     494                 :                 i, errno);
     495               0 :         translog_free_record_header(&rec);
     496               0 :         goto err;
     497                 :       }
     498               4 :       if (len == RECHEADER_READ_EOF)
     499                 :       {
     500               2 :         if (i != ITERATIONS)
     501                 :         {
     502               0 :           fprintf(stderr, "EOL met at iteration %u instead of %u\n",
     503                 :                   i, ITERATIONS);
     504               0 :           translog_free_record_header(&rec);
     505               0 :           goto err;
     506                 :         }
     507                 :         break;
     508                 :       }
     509                 : 
     510               2 :       if (i % 2)
     511                 :       {
     512                 :         LSN ref;
     513               2 :         ref= lsn_korr(rec.header);
     514               2 :         if (rec.type != LOGREC_FIXED_RECORD_1LSN_EXAMPLE ||
     515                 :             rec.short_trid != (i % 0xFFFF) ||
     516                 :             rec.record_length != LSN_STORE_SIZE || ref != lsn)
     517                 :         {
     518               0 :           fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_1LSN_EXAMPLE "
     519                 :                   "data read(%d)"
     520                 :                   "type %u, strid %u, len %u, ref(%lu,0x%lx), lsn(%lu,0x%lx)\n",
     521                 :                   i, (uint) rec.type, (uint) rec.short_trid,
     522                 :                   (uint) rec.record_length,
     523                 :                   LSN_IN_PARTS(ref), LSN_IN_PARTS(rec.lsn));
     524               0 :           translog_free_record_header(&rec);
     525               0 :           goto err;
     526                 :         }
     527                 :       }
     528                 :       else
     529                 :       {
     530                 :         LSN ref1, ref2;
     531               0 :         ref1= lsn_korr(rec.header);
     532               0 :         ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
     533               0 :         if (rec.type != LOGREC_FIXED_RECORD_2LSN_EXAMPLE ||
     534                 :             rec.short_trid != (i % 0xFFFF) ||
     535                 :             rec.record_length != 23 ||
     536                 :             ref1 != lsn ||
     537                 :             ref2 != first_lsn ||
     538                 :             ((uchar)rec.header[22]) != 0x55 ||
     539                 :             ((uchar)rec.header[21]) != 0xAA ||
     540                 :             ((uchar)rec.header[20]) != 0x55 ||
     541                 :             ((uchar)rec.header[19]) != 0xAA ||
     542                 :             ((uchar)rec.header[18]) != 0x55 ||
     543                 :             ((uchar)rec.header[17]) != 0xAA ||
     544                 :             ((uchar)rec.header[16]) != 0x55 ||
     545                 :             ((uchar)rec.header[15]) != 0xAA ||
     546                 :             ((uchar)rec.header[14]) != 0x55)
     547                 :         {
     548               0 :           fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_2LSN_EXAMPLE "
     549                 :                   "data read(%d) "
     550                 :                   "type %u, strid %u, len %u, ref1(%lu,0x%lx), "
     551                 :                   "ref2(%lu,0x%lx) %x%x%x%x%x%x%x%x%x "
     552                 :                   "lsn(%lu,0x%lx)\n",
     553                 :                   i, (uint) rec.type, (uint) rec.short_trid,
     554                 :                   (uint) rec.record_length,
     555                 :                   LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
     556                 :                   (uint) rec.header[14], (uint) rec.header[15],
     557                 :                   (uint) rec.header[16], (uint) rec.header[17],
     558                 :                   (uint) rec.header[18], (uint) rec.header[19],
     559                 :                   (uint) rec.header[20], (uint) rec.header[21],
     560                 :                   (uint) rec.header[22],
     561                 :                   LSN_IN_PARTS(rec.lsn));
     562               0 :           translog_free_record_header(&rec);
     563               0 :           DBUG_ASSERT(0);
     564                 :           goto err;
     565                 :         }
     566                 :       }
     567               2 :       ok(1, "read record");
     568               2 :       translog_free_record_header(&rec);
     569                 : 
     570               2 :       len= translog_read_next_record_header(&scanner, &rec);
     571               2 :       if (len == RECHEADER_READ_ERROR)
     572                 :       {
     573               0 :         fprintf(stderr, "1-%d translog_read_next_record_header (var) "
     574                 :                 "failed (%d)\n", i, errno);
     575               0 :         goto err;
     576                 :       }
     577               2 :       if (len == RECHEADER_READ_EOF)
     578                 :       {
     579               0 :         fprintf(stderr, "EOL met at the middle of iteration (first var) %u "
     580                 :                 "instead of beginning of %u\n", i, ITERATIONS);
     581               0 :         goto err;
     582                 :       }
     583               2 :       if (i % 2)
     584                 :       {
     585                 :         LSN ref;
     586               2 :         ref= lsn_korr(rec.header);
     587               2 :         rec_len= get_len();
     588               2 :         if (rec.type !=LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE ||
     589                 :             rec.short_trid != (i % 0xFFFF) ||
     590                 :             rec.record_length != rec_len + LSN_STORE_SIZE ||
     591                 :             len != 12 || ref != lsn ||
     592                 :             check_content(rec.header + LSN_STORE_SIZE, len - LSN_STORE_SIZE))
     593                 :         {
     594               0 :           fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
     595                 :                   "data read(%d)"
     596                 :                   "type %u (%d), strid %u (%d), len %lu, %lu + 7 (%d), "
     597                 :                   "hdr len: %d (%d), "
     598                 :                   "ref(%lu,0x%lx), lsn(%lu,0x%lx) (%d), content: %d\n",
     599                 :                   i, (uint) rec.type,
     600                 :                   rec.type !=LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE,
     601                 :                   (uint) rec.short_trid,
     602                 :                   rec.short_trid != (i % 0xFFFF),
     603                 :                   (ulong) rec.record_length, (ulong) rec_len,
     604                 :                   rec.record_length != rec_len + LSN_STORE_SIZE,
     605                 :                   len,
     606                 :                   len != 12,
     607                 :                   LSN_IN_PARTS(ref), LSN_IN_PARTS(rec.lsn),
     608                 :                   (ref != lsn),
     609                 :                   check_content(rec.header + LSN_STORE_SIZE,
     610                 :                                 len - LSN_STORE_SIZE));
     611               0 :           translog_free_record_header(&rec);
     612               0 :           goto err;
     613                 :         }
     614               2 :         if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE))
     615                 :         {
     616               0 :           fprintf(stderr,
     617                 :                   "Incorrect LOGREC_VARIABLE_RECORD_1LSN_EXAMPLE "
     618                 :                   "in whole rec read lsn(%lu,0x%lx)\n",
     619                 :                   LSN_IN_PARTS(rec.lsn));
     620               0 :           translog_free_record_header(&rec);
     621               0 :           goto err;
     622                 :         }
     623                 :       }
     624                 :       else
     625                 :       {
     626                 :         LSN ref1, ref2;
     627               0 :         ref1= lsn_korr(rec.header);
     628               0 :         ref2= lsn_korr(rec.header + LSN_STORE_SIZE);
     629               0 :         rec_len= get_len();
     630               0 :         if (rec.type != LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE ||
     631                 :             rec.short_trid != (i % 0xFFFF) ||
     632                 :             rec.record_length != rec_len + LSN_STORE_SIZE * 2 ||
     633                 :             len != 19 ||
     634                 :             ref1 != lsn ||
     635                 :             ref2 != first_lsn ||
     636                 :             check_content(rec.header + LSN_STORE_SIZE * 2,
     637                 :                           len - LSN_STORE_SIZE * 2))
     638                 :         {
     639               0 :           fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
     640                 :                   " data read(%d) "
     641                 :                   "type %u, strid %u, len %lu != %lu + 14, hdr len: %d, "
     642                 :                   "ref1(%lu,0x%lx), ref2(%lu,0x%lx), "
     643                 :                   "lsn(%lu,0x%lx)\n",
     644                 :                   i, (uint) rec.type, (uint) rec.short_trid,
     645                 :                   (ulong) rec.record_length, (ulong) rec_len,
     646                 :                   len,
     647                 :                   LSN_IN_PARTS(ref1), LSN_IN_PARTS(ref2),
     648                 :                   LSN_IN_PARTS(rec.lsn));
     649               0 :           translog_free_record_header(&rec);
     650               0 :           goto err;
     651                 :         }
     652               0 :         if (read_and_check_content(&rec, long_buffer, LSN_STORE_SIZE * 2))
     653                 :         {
     654               0 :           fprintf(stderr,
     655                 :                   "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
     656                 :                   "in whole rec read lsn(%lu,0x%lx)\n",
     657                 :                   LSN_IN_PARTS(rec.lsn));
     658               0 :           translog_free_record_header(&rec);
     659               0 :           goto err;
     660                 :         }
     661                 :       }
     662               2 :       ok(1, "read record");
     663               2 :       translog_free_record_header(&rec);
     664                 : 
     665               2 :       len= translog_read_next_record_header(&scanner, &rec);
     666               2 :       if (len == RECHEADER_READ_ERROR)
     667                 :       {
     668               0 :         fprintf(stderr, "1-%d translog_read_next_record_header failed (%d)\n",
     669                 :                 i, errno);
     670               0 :         translog_free_record_header(&rec);
     671               0 :         goto err;
     672                 :       }
     673               2 :       if (len == RECHEADER_READ_EOF)
     674                 :       {
     675               0 :         fprintf(stderr, "EOL met at the middle of iteration %u "
     676                 :                 "instead of beginning of %u\n", i, ITERATIONS);
     677               0 :         translog_free_record_header(&rec);
     678               0 :         goto err;
     679                 :       }
     680               2 :       if (rec.type != LOGREC_FIXED_RECORD_0LSN_EXAMPLE ||
     681                 :           rec.short_trid != (i % 0xFFFF) ||
     682                 :           rec.record_length != 6 || uint4korr(rec.header) != i ||
     683                 :           ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF)
     684                 :       {
     685               0 :         fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
     686                 :                 "data read(%d)\n"
     687                 :                 "type %u, strid %u, len %u, i: %u, 4: %u 5: %u "
     688                 :                 "lsn(%lu,0x%lx)\n",
     689                 :                 i, (uint) rec.type, (uint) rec.short_trid,
     690                 :                 (uint) rec.record_length,
     691                 :                 (uint)uint4korr(rec.header), (uint) rec.header[4],
     692                 :                 (uint) rec.header[5],
     693                 :                 LSN_IN_PARTS(rec.lsn));
     694               0 :         translog_free_record_header(&rec);
     695               0 :         goto err;
     696                 :       }
     697               2 :       ok(1, "read record");
     698               2 :       translog_free_record_header(&rec);
     699                 : 
     700               2 :       lsn= rec.lsn;
     701                 : 
     702               2 :       len= translog_read_next_record_header(&scanner, &rec);
     703               2 :       rec_len= get_len();
     704               2 :       if (rec.type != LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE ||
     705                 :           rec.short_trid != (i % 0xFFFF) ||
     706                 :           rec.record_length != rec_len ||
     707                 :           len != 9 || check_content(rec.header, len))
     708                 :       {
     709               0 :         fprintf(stderr, "Incorrect LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE "
     710                 :                 "data read(%d) "
     711                 :                 "type %u, strid %u, len %lu != %lu, hdr len: %d, "
     712                 :                 "lsn(%lu,0x%lx)\n",
     713                 :                 i, (uint) rec.type, (uint) rec.short_trid,
     714                 :                 (ulong) rec.record_length, (ulong) rec_len,
     715                 :                 len, LSN_IN_PARTS(rec.lsn));
     716               0 :         translog_free_record_header(&rec);
     717               0 :         goto err;
     718                 :       }
     719               2 :       if (read_and_check_content(&rec, long_buffer, 0))
     720                 :       {
     721               0 :         fprintf(stderr,
     722                 :                 "Incorrect LOGREC_VARIABLE_RECORD_2LSN_EXAMPLE "
     723                 :                 "in whole rec read lsn(%lu,0x%lx)\n",
     724                 :                 LSN_IN_PARTS(rec.lsn));
     725               0 :         translog_free_record_header(&rec);
     726               0 :         goto err;
     727                 :       }
     728               2 :       ok(1, "read record");
     729               2 :       translog_free_record_header(&rec);
     730               2 :     }
     731                 :   }
     732                 : 
     733               2 :   rc= 0;
     734               2 : err:
     735               2 :   if (rc)
     736               0 :     ok(0, "read record");
     737               2 :   translog_destroy();
     738               2 :   end_pagecache(&pagecache, 1);
     739               2 :   ma_control_file_end();
     740               2 :   free_defaults(default_argv);
     741               2 :   seq_storage_destroy(&seq);
     742               2 :   if (maria_log_remove())
     743               0 :     exit(1);
     744                 : 
     745               2 :   return (test(exit_status()));
     746                 : }

Generated by: LTP GCOV extension version 1.4