LTP GCOV extension - code coverage report
Current view: directory - storage/maria - ma_test2.c
Test: mtr_and_unit.info
Date: 2009-03-05 Instrumented lines: 708
Code covered: 74.4 % Executed lines: 527

       1                 : /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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                 : /* Test av isam-databas: stor test */
      17                 : 
      18                 : #ifndef USE_MY_FUNC             /* We want to be able to dbug this !! */
      19                 : #define USE_MY_FUNC
      20                 : #endif
      21                 : #include "maria_def.h"
      22                 : #include "trnman.h"
      23                 : #include <m_ctype.h>
      24                 : #include <my_bit.h>
      25                 : #include "ma_checkpoint.h"
      26                 : 
      27                 : #define STANDARD_LENGTH 37
      28                 : #define MARIA_KEYS 6
      29                 : #define MAX_PARTS 4
      30                 : #if !defined(MSDOS) && !defined(labs)
      31                 : #define labs(a) abs(a)
      32                 : #endif
      33                 : 
      34                 : static void get_options(int argc, char *argv[]);
      35                 : static uint rnd(uint max_value);
      36                 : static void fix_length(uchar *record,uint length);
      37                 : static void put_blob_in_record(uchar *blob_pos,char **blob_buffer,
      38                 :                                ulong *length);
      39                 : static void copy_key(MARIA_HA *info, uint inx, uchar *record, uchar *key);
      40                 : 
      41                 : static int verbose= 0, testflag= 0, first_key= 0, async_io= 0, pagecacheing= 0;
      42                 : static int write_cacheing= 0, do_locking= 0, rec_pointer_size= 0;
      43                 : static int silent= 0, opt_quick_mode= 0, transactional= 0, skip_update= 0;
      44                 : static int die_in_middle_of_transaction= 0, pack_fields= 1;
      45                 : static int pack_seg= HA_SPACE_PACK, pack_type= HA_PACK_KEY, remove_count= -1;
      46                 : static int create_flag= 0, srand_arg= 0, checkpoint= 0;
      47                 : static my_bool opt_versioning= 0;
      48                 : static uint use_blob= 0, update_count= 0;
      49                 : static ulong pagecache_size=8192*32;
      50                 : static enum data_file_type record_type= DYNAMIC_RECORD;
      51                 : 
      52                 : static uint keys=MARIA_KEYS,recant=1000;
      53                 : static uint16 key1[1001],key3[5000];
      54                 : static uchar record[300],record2[300],key[100],key2[100];
      55                 : static uchar read_record[300],read_record2[300],read_record3[300];
      56                 : static HA_KEYSEG glob_keyseg[MARIA_KEYS][MAX_PARTS];
      57                 : 
      58                 :                 /* Test program */
      59                 : 
      60                 : int main(int argc, char *argv[])
      61             153 : {
      62                 :   uint i;
      63                 :   int j,n1,n2,n3,error,k;
      64                 :   uint write_count,update,dupp_keys,opt_delete,start,length,blob_pos,
      65                 :        reclength,ant,found_parts;
      66                 :   my_off_t lastpos;
      67                 :   ha_rows range_records,records;
      68                 :   MARIA_HA *file;
      69                 :   MARIA_KEYDEF keyinfo[10];
      70                 :   MARIA_COLUMNDEF recinfo[10];
      71                 :   MARIA_INFO info;
      72                 :   const char *filename;
      73                 :   char *blob_buffer;
      74                 :   MARIA_CREATE_INFO create_info;
      75                 : 
      76                 : #if defined(SAFE_MUTEX) && defined(THREAD)
      77             153 :   safe_mutex_deadlock_detector= 1;
      78                 : #endif
      79             153 :   MY_INIT(argv[0]);
      80                 : 
      81             153 :   filename= "test2";
      82             153 :   get_options(argc,argv);
      83             153 :   if (! async_io)
      84             153 :     my_disable_async_io=1;
      85                 : 
      86             153 :   maria_data_root= (char *)".";
      87                 :   /* Maria requires that we always have a page cache */
      88             153 :   if (maria_init() ||
      89                 :       (init_pagecache(maria_pagecache, pagecache_size, 0, 0,
      90                 :                       maria_block_size, MY_WME) == 0) ||
      91                 :       ma_control_file_open(TRUE, TRUE) ||
      92                 :       (init_pagecache(maria_log_pagecache,
      93                 :                       TRANSLOG_PAGECACHE_SIZE, 0, 0,
      94                 :                       TRANSLOG_PAGE_SIZE, MY_WME) == 0) ||
      95                 :       translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
      96                 :                     0, 0, maria_log_pagecache,
      97                 :                     TRANSLOG_DEFAULT_FLAGS, 0) ||
      98                 :       (transactional && (trnman_init(0) || ma_checkpoint_init(0))))
      99                 :   {
     100               0 :     fprintf(stderr, "Error in initialization");
     101               0 :     exit(1);
     102                 :   }
     103             153 :   if (opt_versioning)
     104              17 :     init_thr_lock();
     105                 : 
     106             153 :   reclength=STANDARD_LENGTH+60+(use_blob ? 8 : 0);
     107             153 :   blob_pos=STANDARD_LENGTH+60;
     108             153 :   keyinfo[0].seg= &glob_keyseg[0][0];
     109             153 :   keyinfo[0].seg[0].start=0;
     110             153 :   keyinfo[0].seg[0].length=6;
     111             153 :   keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT;
     112             153 :   keyinfo[0].seg[0].language= default_charset_info->number;
     113             153 :   keyinfo[0].seg[0].flag=(uint8) pack_seg;
     114             153 :   keyinfo[0].seg[0].null_bit=0;
     115             153 :   keyinfo[0].seg[0].null_pos=0;
     116             153 :   keyinfo[0].key_alg=HA_KEY_ALG_BTREE;
     117             153 :   keyinfo[0].keysegs=1;
     118             153 :   keyinfo[0].flag = pack_type;
     119             153 :   keyinfo[0].block_length= 0;                   /* Default block length */
     120             153 :   keyinfo[1].seg= &glob_keyseg[1][0];
     121             153 :   keyinfo[1].seg[0].start=7;
     122             153 :   keyinfo[1].seg[0].length=6;
     123             153 :   keyinfo[1].seg[0].type=HA_KEYTYPE_BINARY;
     124             153 :   keyinfo[1].seg[0].flag=0;
     125             153 :   keyinfo[1].seg[0].null_bit=0;
     126             153 :   keyinfo[1].seg[0].null_pos=0;
     127             153 :   keyinfo[1].seg[1].start=0;                    /* two part key */
     128             153 :   keyinfo[1].seg[1].length=6;
     129             153 :   keyinfo[1].seg[1].type=HA_KEYTYPE_NUM;
     130             153 :   keyinfo[1].seg[1].flag=HA_REVERSE_SORT;
     131             153 :   keyinfo[1].seg[1].null_bit=0;
     132             153 :   keyinfo[1].seg[1].null_pos=0;
     133             153 :   keyinfo[1].key_alg=HA_KEY_ALG_BTREE;
     134             153 :   keyinfo[1].keysegs=2;
     135             153 :   keyinfo[1].flag =0;
     136             153 :   keyinfo[1].block_length= MARIA_MIN_KEY_BLOCK_LENGTH;  /* Diff blocklength */
     137             153 :   keyinfo[2].seg= &glob_keyseg[2][0];
     138             153 :   keyinfo[2].seg[0].start=12;
     139             153 :   keyinfo[2].seg[0].length=8;
     140             153 :   keyinfo[2].seg[0].type=HA_KEYTYPE_BINARY;
     141             153 :   keyinfo[2].seg[0].flag=HA_REVERSE_SORT;
     142             153 :   keyinfo[2].seg[0].null_bit=0;
     143             153 :   keyinfo[2].seg[0].null_pos=0;
     144             153 :   keyinfo[2].key_alg=HA_KEY_ALG_BTREE;
     145             153 :   keyinfo[2].keysegs=1;
     146             153 :   keyinfo[2].flag =HA_NOSAME;
     147             153 :   keyinfo[2].block_length= 0;                   /* Default block length */
     148             153 :   keyinfo[3].seg= &glob_keyseg[3][0];
     149             153 :   keyinfo[3].seg[0].start=0;
     150             153 :   keyinfo[3].seg[0].length=reclength-(use_blob ? 8 : 0);
     151             153 :   keyinfo[3].seg[0].type=HA_KEYTYPE_TEXT;
     152             153 :   keyinfo[3].seg[0].language=default_charset_info->number;
     153             153 :   keyinfo[3].seg[0].flag=(uint8) pack_seg;
     154             153 :   keyinfo[3].seg[0].null_bit=0;
     155             153 :   keyinfo[3].seg[0].null_pos=0;
     156             153 :   keyinfo[3].key_alg=HA_KEY_ALG_BTREE;
     157             153 :   keyinfo[3].keysegs=1;
     158             153 :   keyinfo[3].flag = pack_type;
     159             153 :   keyinfo[3].block_length= 0;                   /* Default block length */
     160             153 :   keyinfo[4].seg= &glob_keyseg[4][0];
     161             153 :   keyinfo[4].seg[0].start=0;
     162             153 :   keyinfo[4].seg[0].length=5;
     163             153 :   keyinfo[4].seg[0].type=HA_KEYTYPE_TEXT;
     164             153 :   keyinfo[4].seg[0].language=default_charset_info->number;
     165             153 :   keyinfo[4].seg[0].flag=0;
     166             153 :   keyinfo[4].seg[0].null_bit=0;
     167             153 :   keyinfo[4].seg[0].null_pos=0;
     168             153 :   keyinfo[4].key_alg=HA_KEY_ALG_BTREE;
     169             153 :   keyinfo[4].keysegs=1;
     170             153 :   keyinfo[4].flag = pack_type;
     171             153 :   keyinfo[4].block_length= 0;                   /* Default block length */
     172             153 :   keyinfo[5].seg= &glob_keyseg[5][0];
     173             153 :   keyinfo[5].seg[0].start=0;
     174             153 :   keyinfo[5].seg[0].length=4;
     175             153 :   keyinfo[5].seg[0].type=HA_KEYTYPE_TEXT;
     176             153 :   keyinfo[5].seg[0].language=default_charset_info->number;
     177             153 :   keyinfo[5].seg[0].flag=pack_seg;
     178             153 :   keyinfo[5].seg[0].null_bit=0;
     179             153 :   keyinfo[5].seg[0].null_pos=0;
     180             153 :   keyinfo[5].key_alg=HA_KEY_ALG_BTREE;
     181             153 :   keyinfo[5].keysegs=1;
     182             153 :   keyinfo[5].flag = pack_type;
     183             153 :   keyinfo[5].block_length= 0;                   /* Default block length */
     184                 : 
     185             153 :   recinfo[0].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
     186             153 :   recinfo[0].length=7;
     187             153 :   recinfo[0].null_bit=0;
     188             153 :   recinfo[0].null_pos=0;
     189             153 :   recinfo[1].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
     190             153 :   recinfo[1].length=5;
     191             153 :   recinfo[1].null_bit=0;
     192             153 :   recinfo[1].null_pos=0;
     193             153 :   recinfo[2].type=pack_fields ? FIELD_SKIP_PRESPACE : 0;
     194             153 :   recinfo[2].length=9;
     195             153 :   recinfo[2].null_bit=0;
     196             153 :   recinfo[2].null_pos=0;
     197             153 :   recinfo[3].type=FIELD_NORMAL;
     198             153 :   recinfo[3].length=STANDARD_LENGTH-7-5-9-4;
     199             153 :   recinfo[3].null_bit=0;
     200             153 :   recinfo[3].null_pos=0;
     201             153 :   recinfo[4].type=pack_fields ? FIELD_SKIP_ZERO : 0;
     202             153 :   recinfo[4].length=4;
     203             153 :   recinfo[4].null_bit=0;
     204             153 :   recinfo[4].null_pos=0;
     205             153 :   recinfo[5].type=pack_fields ? FIELD_SKIP_ENDSPACE : 0;
     206             153 :   recinfo[5].length=60;
     207             153 :   recinfo[5].null_bit=0;
     208             153 :   recinfo[5].null_pos=0;
     209             153 :   if (use_blob)
     210                 :   {
     211              67 :     recinfo[6].type=FIELD_BLOB;
     212              67 :     recinfo[6].length=4+portable_sizeof_char_ptr;
     213              67 :     recinfo[6].null_bit=0;
     214              67 :     recinfo[6].null_pos=0;
     215                 :   }
     216                 : 
     217             153 :   write_count=update=dupp_keys=opt_delete=0;
     218             153 :   blob_buffer=0;
     219                 : 
     220             153 :   for (i=1000 ; i>0 ; i--) key1[i]=0;
     221             153 :   for (i=4999 ; i>0 ; i--) key3[i]=0;
     222                 : 
     223             153 :   if (!silent)
     224               0 :     printf("- Creating maria-file\n");
     225             153 :   file= 0;
     226             153 :   bzero((char*) &create_info,sizeof(create_info));
     227             153 :   create_info.max_rows=(ha_rows) (rec_pointer_size ?
     228                 :                                   (1L << (rec_pointer_size*8))/
     229                 :                                   reclength : 0);
     230             153 :   create_info.reloc_rows=(ha_rows) 100;
     231             153 :   create_info.transactional= transactional;
     232             153 :   if (maria_create(filename, record_type, keys,&keyinfo[first_key],
     233                 :                 use_blob ? 7 : 6, &recinfo[0],
     234                 :                 0,(MARIA_UNIQUEDEF*) 0,
     235                 :                 &create_info,create_flag))
     236             153 :     goto err;
     237             153 :   if (!(file=maria_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
     238             153 :     goto err;
     239             153 :   maria_begin(file);
     240             153 :   if (opt_versioning)
     241              17 :     maria_versioning(file, 1);
     242             153 :   if (testflag == 1)
     243             121 :     goto end;
     244             121 :   if (checkpoint == 1 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     245             121 :     goto err;
     246             121 :   if (!silent)
     247               0 :     printf("- Writing key:s\n");
     248             121 :   if (do_locking)
     249              79 :     maria_lock_database(file,F_WRLCK);
     250             121 :   if (write_cacheing)
     251              63 :     maria_extra(file,HA_EXTRA_WRITE_CACHE,0);
     252             121 :   if (opt_quick_mode)
     253               0 :     maria_extra(file,HA_EXTRA_QUICK,0);
     254                 : 
     255          247456 :   for (i=0 ; i < recant ; i++)
     256                 :   {
     257                 :     ulong blob_length;
     258          247336 :     n1=rnd(1000); n2=rnd(100); n3=rnd(5000);
     259          247336 :     sprintf((char*) record,"%6d:%4d:%8d:Pos: %4d    ",n1,n2,n3,write_count);
     260          247336 :     int4store(record+STANDARD_LENGTH-4,(long) i);
     261          247336 :     fix_length(record,(uint) STANDARD_LENGTH+rnd(60));
     262          247336 :     put_blob_in_record(record+blob_pos,&blob_buffer, &blob_length);
     263          247336 :     DBUG_PRINT("test",("record: %d  blob_length: %lu", i, blob_length));
     264                 : 
     265          247336 :     if (maria_write(file,record))
     266                 :     {
     267           93867 :       if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
     268                 :       {
     269               1 :         printf("Error: %d in write at record: %d\n",my_errno,i);
     270               1 :         goto err;
     271                 :       }
     272           93866 :       if (verbose) printf("   Double key: %d at record# %d\n", n3, i);
     273                 :     }
     274                 :     else
     275                 :     {
     276          153469 :       if (key3[n3] == 1 && first_key <3 && first_key+keys >= 3)
     277                 :       {
     278               0 :         printf("Error: Didn't get error when writing second key: '%8d'\n",n3);
     279               0 :         goto err;
     280                 :       }
     281          153469 :       write_count++; key1[n1]++; key3[n3]=1;
     282                 :     }
     283                 : 
     284                 :     /* Check if we can find key without flushing database */
     285          247335 :     if (i % 10 == 0)
     286                 :     {
     287           24734 :       for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
     288           24734 :       if (!j)
     289             150 :         for (j=999 ; j>0 && key1[j] == 0 ; j--) ;
     290           24734 :       sprintf((char*) key,"%6d",j);
     291           24734 :       if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     292                 :       {
     293               0 :         printf("Test in loop: Can't find key: \"%s\"\n",key);
     294               0 :         goto err;
     295                 :       }
     296                 :     }
     297                 :   }
     298             120 :   if (checkpoint == 2 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     299             120 :     goto err;
     300                 : 
     301             120 :   if (write_cacheing)
     302                 :   {
     303              63 :     if (maria_extra(file,HA_EXTRA_NO_CACHE,0))
     304                 :     {
     305               0 :       puts("got error from maria_extra(HA_EXTRA_NO_CACHE)");
     306               0 :       goto err;
     307                 :     }
     308                 :   }
     309                 : 
     310             120 :   if (testflag == 2)
     311             102 :     goto end;
     312                 : 
     313                 : #ifdef REMOVE_WHEN_WE_HAVE_RESIZE
     314                 :   if (pagecacheing)
     315                 :     resize_pagecache(maria_pagecache, maria_block_size,
     316                 :                      pagecache_size * 2, 0, 0);
     317                 : #endif
     318             102 :   if (!silent)
     319               0 :     printf("- Delete\n");
     320             102 :   if (srand_arg)
     321               0 :     srand(srand_arg);
     322             102 :   if (!update_count)
     323             102 :     update_count= recant/10;
     324                 : 
     325           21937 :   for (i=0 ; i < update_count ; i++)
     326                 :   {
     327           21845 :     for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
     328           21845 :     if (j != 0)
     329                 :     {
     330           21845 :       sprintf((char*) key,"%6d",j);
     331           21845 :       if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     332                 :       {
     333               0 :         printf("can't find key1: \"%s\"\n",key);
     334               0 :         goto err;
     335                 :       }
     336           21845 :       if (bcmp(read_record+keyinfo[0].seg[0].start,
     337                 :                key, keyinfo[0].seg[0].length))
     338                 :       {
     339               0 :         printf("Found wrong record when searching for key: \"%s\"\n",key);
     340               0 :         goto err;
     341                 :       }
     342           21845 :       if (opt_delete == (uint) remove_count)            /* While testing */
     343           21835 :         goto end;
     344           21835 :       if (maria_delete(file,read_record))
     345                 :       {
     346               0 :         printf("error: %d; can't delete record: \"%s\"\n", my_errno,read_record);
     347               0 :         goto err;
     348                 :       }
     349           21835 :       opt_delete++;
     350           21835 :       key1[atoi((char*) read_record+keyinfo[0].seg[0].start)]--;
     351           21835 :       key3[atoi((char*) read_record+keyinfo[2].seg[0].start)]=0;
     352                 :     }
     353                 :     else
     354               0 :       puts("Warning: Skipping delete test because no dupplicate keys");
     355                 :   }
     356              92 :   if (testflag == 3)
     357              92 :     goto end;
     358              92 :   if (checkpoint == 3 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     359              92 :     goto err;
     360                 : 
     361              92 :   if (!silent)
     362               0 :     printf("- Update\n");
     363              92 :   if (srand_arg)
     364               0 :     srand(srand_arg);
     365              92 :   if (!update_count)
     366               0 :     update_count= recant/10;
     367                 : 
     368           21917 :   for (i=0 ; i < update_count ; i++)
     369                 :   {
     370           21825 :     n1=rnd(1000); n2=rnd(100); n3=rnd(5000);
     371           21825 :     sprintf((char*) record2,"%6d:%4d:%8d:XXX: %4d     ",n1,n2,n3,update);
     372           21825 :     int4store(record2+STANDARD_LENGTH-4,(long) i);
     373           21825 :     fix_length(record2,(uint) STANDARD_LENGTH+rnd(60));
     374                 : 
     375           21825 :     for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
     376           21825 :     if (j != 0)
     377                 :     {
     378           21815 :       sprintf((char*) key,"%6d",j);
     379           21815 :       if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     380                 :       {
     381               0 :         printf("can't find key1: \"%s\"\n", (char*) key);
     382               0 :         goto err;
     383                 :       }
     384           21815 :       if (bcmp(read_record+keyinfo[0].seg[0].start,
     385                 :                key, keyinfo[0].seg[0].length))
     386                 :       {
     387               0 :         printf("Found wrong record when searching for key: \"%s\"; Found \"%.*s\"\n",
     388                 :                key, keyinfo[0].seg[0].length,
     389                 :                read_record+keyinfo[0].seg[0].start);
     390               0 :         goto err;
     391                 :       }
     392           21815 :       if (use_blob)
     393                 :       {
     394                 :         ulong blob_length;
     395            3265 :         if (i & 1)
     396            1635 :           put_blob_in_record(record2+blob_pos,&blob_buffer, &blob_length);
     397                 :         else
     398            1630 :           bmove(record2+blob_pos, read_record+blob_pos, 4 + sizeof(char*));
     399                 :       }
     400           21815 :       if (skip_update)
     401           21815 :         continue;
     402           21815 :       if (maria_update(file,read_record,record2))
     403                 :       {
     404           11022 :         if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
     405                 :         {
     406               0 :           printf("error: %d; can't update:\nFrom: \"%s\"\nTo:   \"%s\"\n",
     407                 :                  my_errno,read_record,record2);
     408               0 :           goto err;
     409                 :         }
     410           11022 :         if (verbose)
     411               0 :           printf("Double key when tried to update:\nFrom: \"%s\"\nTo:   \"%s\"\n",record,record2);
     412                 :       }
     413                 :       else
     414                 :       {
     415           10793 :         key1[atoi((char*) read_record+keyinfo[0].seg[0].start)]--;
     416           10793 :         key3[atoi((char*) read_record+keyinfo[2].seg[0].start)]=0;
     417           10793 :         key1[n1]++; key3[n3]=1;
     418           10793 :         update++;
     419                 :       }
     420                 :     }
     421                 :   }
     422              92 :   if (testflag == 4)
     423              81 :     goto end;
     424              81 :   if (checkpoint == 4 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     425              81 :     goto err;
     426                 : 
     427           81000 :   for (i=999, dupp_keys=j=0 ; i>0 ; i--)
     428                 :   {
     429           80919 :     if (key1[i] > dupp_keys)
     430                 :     {
     431             288 :       dupp_keys=key1[i]; j=i;
     432                 :     }
     433                 :   }
     434              81 :   sprintf((char*) key,"%6d",j);
     435              81 :   start=keyinfo[0].seg[0].start;
     436              81 :   length=keyinfo[0].seg[0].length;
     437              81 :   if (dupp_keys)
     438                 :   {
     439              81 :     if (!silent)
     440               0 :       printf("- Same key: first - next -> last - prev -> first\n");
     441              81 :     DBUG_PRINT("progpos",("first - next -> last - prev -> first"));
     442              81 :     if (verbose) printf("   Using key: \"%s\"  Keys: %d\n",key,dupp_keys);
     443                 : 
     444              81 :     if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     445              81 :       goto err;
     446              81 :     if (maria_rsame(file,read_record2,-1))
     447              81 :       goto err;
     448              81 :     if (memcmp(read_record,read_record2,reclength) != 0)
     449                 :     {
     450               0 :       printf("maria_rsame didn't find same record\n");
     451               0 :       goto err;
     452                 :     }
     453              81 :     info.recpos=maria_position(file);
     454              81 :     if (maria_rfirst(file,read_record2,0) ||
     455                 :         maria_rsame_with_pos(file,read_record2,0,info.recpos) ||
     456                 :         memcmp(read_record,read_record2,reclength) != 0)
     457                 :     {
     458               0 :       printf("maria_rsame_with_pos didn't find same record\n");
     459               0 :       goto err;
     460                 :     }
     461                 :     {
     462                 :       int skr;
     463              81 :       info.recpos= maria_position(file);
     464              81 :       skr= maria_rnext(file,read_record2,0);
     465              81 :       if ((skr && my_errno != HA_ERR_END_OF_FILE) ||
     466                 :           maria_rprev(file,read_record2,0) ||
     467                 :           memcmp(read_record,read_record2,reclength) != 0 ||
     468                 :           info.recpos != maria_position(file))
     469                 :       {
     470               0 :         printf("maria_rsame_with_pos lost position\n");
     471               0 :         goto err;
     472                 :       }
     473                 :     }
     474              81 :     ant=1;
     475             569 :     while (maria_rnext(file,read_record2,0) == 0 &&
     476             407 :            memcmp(read_record2+start,key,length) == 0) ant++;
     477              81 :     if (ant != dupp_keys)
     478                 :     {
     479               0 :       printf("next: Found: %d keys of %d\n",ant,dupp_keys);
     480               0 :       goto err;
     481                 :     }
     482              81 :     ant=0;
     483             650 :     while (maria_rprev(file,read_record3,0) == 0 &&
     484             488 :            bcmp(read_record3+start,key,length) == 0) ant++;
     485              81 :     if (ant != dupp_keys)
     486                 :     {
     487               0 :       printf("prev: Found: %d records of %d\n",ant,dupp_keys);
     488               0 :       goto err;
     489                 :     }
     490                 : 
     491                 :     /* Check of maria_rnext_same */
     492              81 :     if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     493              81 :       goto err;
     494              81 :     ant=1;
     495             569 :     while (!maria_rnext_same(file,read_record3) && ant < dupp_keys+10)
     496             407 :       ant++;
     497              81 :     if (ant != dupp_keys || my_errno != HA_ERR_END_OF_FILE)
     498                 :     {
     499               0 :       printf("maria_rnext_same: Found: %d records of %d\n",ant,dupp_keys);
     500               0 :       goto err;
     501                 :     }
     502                 :   }
     503                 : 
     504              81 :   if (!silent)
     505               0 :     printf("- All keys: first - next -> last - prev -> first\n");
     506              81 :   DBUG_PRINT("progpos",("All keys: first - next -> last - prev -> first"));
     507              81 :   ant=1;
     508              81 :   if (maria_rfirst(file,read_record,0))
     509                 :   {
     510               0 :     printf("Can't find first record\n");
     511               0 :     goto err;
     512                 :   }
     513           98998 :   while ((error=maria_rnext(file,read_record3,0)) == 0 && ant < write_count+10)
     514           98917 :     ant++;
     515              81 :   if (ant != write_count - opt_delete || error != HA_ERR_END_OF_FILE)
     516                 :   {
     517               0 :     printf("next: I found: %d records of %d (error: %d)\n",
     518                 :            ant, write_count - opt_delete, error);
     519               0 :     goto err;
     520                 :   }
     521              81 :   if (maria_rlast(file,read_record2,0) ||
     522                 :       bcmp(read_record2,read_record3,reclength))
     523                 :   {
     524               0 :     printf("Can't find last record\n");
     525               0 :     DBUG_DUMP("record2", read_record2, reclength);
     526               0 :     DBUG_DUMP("record3", read_record3, reclength);
     527               0 :     goto err;
     528                 :   }
     529              81 :   ant=1;
     530           99079 :   while (maria_rprev(file,read_record3,0) == 0 && ant < write_count+10)
     531           98917 :     ant++;
     532              81 :   if (ant != write_count - opt_delete)
     533                 :   {
     534               0 :     printf("prev: I found: %d records of %d\n",ant,write_count);
     535               0 :     goto err;
     536                 :   }
     537              81 :   if (bcmp(read_record,read_record3,reclength))
     538                 :   {
     539               0 :     printf("Can't find first record\n");
     540               0 :     goto err;
     541                 :   }
     542                 : 
     543              81 :   if (!silent)
     544               0 :     printf("- Test if: Read first - next - prev - prev - next == first\n");
     545              81 :   DBUG_PRINT("progpos",("- Read first - next - prev - prev - next == first"));
     546              81 :   if (maria_rfirst(file,read_record,0) ||
     547                 :       maria_rnext(file,read_record3,0) ||
     548                 :       maria_rprev(file,read_record3,0) ||
     549                 :       maria_rprev(file,read_record3,0) == 0 ||
     550                 :       maria_rnext(file,read_record3,0))
     551                 :       goto err;
     552              81 :   if (bcmp(read_record,read_record3,reclength) != 0)
     553               0 :      printf("Can't find first record\n");
     554                 : 
     555              81 :   if (!silent)
     556               0 :     printf("- Test if: Read last - prev - next - next - prev == last\n");
     557              81 :   DBUG_PRINT("progpos",("Read last - prev - next - next - prev == last"));
     558              81 :   if (maria_rlast(file,read_record2,0) ||
     559                 :       maria_rprev(file,read_record3,0) ||
     560                 :       maria_rnext(file,read_record3,0) ||
     561                 :       maria_rnext(file,read_record3,0) == 0 ||
     562                 :       maria_rprev(file,read_record3,0))
     563                 :       goto err;
     564              81 :   if (bcmp(read_record2,read_record3,reclength))
     565               0 :      printf("Can't find last record\n");
     566                 : #ifdef NOT_ANYMORE
     567                 :   if (!silent)
     568                 :     puts("- Test read key-part");
     569                 :   strmov(key2,key);
     570                 :   for(i=strlen(key2) ; i-- > 1 ;)
     571                 :   {
     572                 :     key2[i]=0;
     573                 : 
     574                 :     /* The following row is just to catch some bugs in the key code */
     575                 :     bzero((char*) file->lastkey,file->s->base.max_key_length*2);
     576                 :     if (maria_rkey(file,read_record,0,key2,(uint) i,HA_READ_PREFIX))
     577                 :       goto err;
     578                 :     if (bcmp(read_record+start,key,(uint) i))
     579                 :     {
     580                 :       puts("Didn't find right record");
     581                 :       goto err;
     582                 :     }
     583                 :   }
     584                 : #endif
     585              81 :   if (dupp_keys > 2)
     586                 :   {
     587              76 :     if (!silent)
     588               0 :       printf("- Read key (first) - next - delete - next -> last\n");
     589              76 :     DBUG_PRINT("progpos",("first - next - delete - next -> last"));
     590              76 :     if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     591              76 :       goto err;
     592              76 :     if (maria_rnext(file,read_record3,0)) goto err;
     593              76 :     if (maria_delete(file,read_record3)) goto err;
     594              76 :     opt_delete++;
     595              76 :     ant=1;
     596             483 :     while (maria_rnext(file,read_record3,0) == 0 &&
     597             331 :            bcmp(read_record3+start,key,length) == 0) ant++;
     598              76 :     if (ant != dupp_keys-1)
     599                 :     {
     600               0 :       printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-1);
     601               0 :       goto err;
     602                 :     }
     603                 :   }
     604              81 :   if (dupp_keys>4)
     605                 :   {
     606              75 :     if (!silent)
     607               0 :       printf("- Read last of key - prev - delete - prev -> first\n");
     608              75 :     DBUG_PRINT("progpos",("last - prev - delete - prev -> first"));
     609              75 :     if (maria_rprev(file,read_record3,0)) goto err;
     610              75 :     if (maria_rprev(file,read_record3,0)) goto err;
     611              75 :     if (maria_delete(file,read_record3)) goto err;
     612              75 :     opt_delete++;
     613              75 :     ant=1;
     614             405 :     while (maria_rprev(file,read_record3,0) == 0 &&
     615             255 :            bcmp(read_record3+start,key,length) == 0) ant++;
     616              75 :     if (ant != dupp_keys-2)
     617                 :     {
     618               0 :       printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-2);
     619               0 :       goto err;
     620                 :     }
     621                 :   }
     622              81 :   if (dupp_keys > 6)
     623                 :   {
     624              15 :     if (!silent)
     625               0 :       printf("- Read first - delete - next -> last\n");
     626              15 :     DBUG_PRINT("progpos",("first - delete - next -> last"));
     627              15 :     if (maria_rkey(file,read_record3,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
     628              15 :       goto err;
     629              15 :     if (maria_delete(file,read_record3)) goto err;
     630              15 :     opt_delete++;
     631              15 :     ant=1;
     632              15 :     if (maria_rnext(file,read_record,0))
     633                 :       goto err;                                 /* Skall finnas poster */
     634             135 :     while (maria_rnext(file,read_record3,0) == 0 &&
     635             120 :            bcmp(read_record3+start,key,length) == 0) ant++;
     636              15 :     if (ant != dupp_keys-3)
     637                 :     {
     638               0 :       printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-3);
     639               0 :       goto err;
     640                 :     }
     641                 : 
     642              15 :     if (!silent)
     643               0 :       printf("- Read last - delete - prev -> first\n");
     644              15 :     DBUG_PRINT("progpos",("last - delete - prev -> first"));
     645              15 :     if (maria_rprev(file,read_record3,0)) goto err;
     646              15 :     if (maria_delete(file,read_record3)) goto err;
     647              15 :     opt_delete++;
     648              15 :     ant=0;
     649             150 :     while (maria_rprev(file,read_record3,0) == 0 &&
     650             120 :            bcmp(read_record3+start,key,length) == 0) ant++;
     651              15 :     if (ant != dupp_keys-4)
     652                 :     {
     653               0 :       printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-4);
     654               0 :       goto err;
     655                 :     }
     656                 :   }
     657                 : 
     658              81 :   if (!silent)
     659               0 :     puts("- Test if: Read rrnd - same");
     660              81 :   DBUG_PRINT("progpos",("Read rrnd - same"));
     661              81 :   assert(maria_scan_init(file) == 0);
     662          120154 :   for (i=0 ; i < write_count ; i++)
     663                 :   {
     664                 :     int tmp;
     665          120073 :     if ((tmp= maria_scan(file,read_record)) &&
     666                 :         tmp != HA_ERR_END_OF_FILE &&
     667                 :         tmp != HA_ERR_RECORD_DELETED)
     668                 :     {
     669               0 :       printf("Got error %d when scanning table\n", tmp);
     670               0 :       break;
     671                 :     }
     672          120073 :     if (!tmp)
     673                 :     {
     674                 :       /* Remember position to last found row */
     675           98817 :       info.recpos= maria_position(file);
     676           98817 :       bmove(read_record2,read_record,reclength);
     677                 :     }
     678                 :   }
     679              81 :   maria_scan_end(file);
     680              81 :   if (i != write_count && i != write_count - opt_delete)
     681                 :   {
     682               0 :     printf("Found wrong number of rows while scanning table\n");
     683               0 :     goto err;
     684                 :   }
     685                 : 
     686              81 :   if (maria_rsame_with_pos(file,read_record,0,info.recpos))
     687              81 :     goto err;
     688              81 :   if (bcmp(read_record,read_record2,reclength) != 0)
     689                 :   {
     690               0 :     printf("maria_rsame_with_pos didn't find same record\n");
     691               0 :     goto err;
     692                 :   }
     693                 : 
     694             324 :   for (i=min(2,keys) ; i-- > 0 ;)
     695                 :   {
     696             162 :     if (maria_rsame(file,read_record2,(int) i)) goto err;
     697             162 :     if (bcmp(read_record,read_record2,reclength) != 0)
     698                 :     {
     699               0 :       printf("maria_rsame didn't find same record\n");
     700               0 :       goto err;
     701                 :     }
     702                 :   }
     703              81 :   if (!silent)
     704               0 :     puts("- Test maria_records_in_range");
     705              81 :   maria_status(file,&info,HA_STATUS_VARIABLE);
     706             567 :   for (i=0 ; i < info.keys ; i++)
     707                 :   {
     708                 :     key_range min_key, max_key;
     709             486 :     if (maria_rfirst(file,read_record,(int) i) ||
     710                 :         maria_rlast(file,read_record2,(int) i))
     711                 :       goto err;
     712             486 :     copy_key(file,(uint) i, read_record,  key);
     713             486 :     copy_key(file,(uint) i, read_record2, key2);
     714             486 :     min_key.key= key;
     715             486 :     min_key.keypart_map= HA_WHOLE_KEY;
     716             486 :     min_key.flag= HA_READ_KEY_EXACT;
     717             486 :     max_key.key= key2;
     718             486 :     max_key.keypart_map= HA_WHOLE_KEY;
     719             486 :     max_key.flag= HA_READ_AFTER_KEY;
     720                 : 
     721             486 :     range_records= maria_records_in_range(file,(int) i, &min_key, &max_key);
     722             486 :     if (range_records < info.records*8/10 ||
     723                 :         range_records > info.records*12/10)
     724                 :     {
     725               0 :       printf("maria_records_range returned %ld; Should be about %ld\n",
     726                 :              (long) range_records,(long) info.records);
     727               0 :       goto err;
     728                 :     }
     729             486 :     if (verbose)
     730                 :     {
     731               0 :       printf("maria_records_range returned %ld;  Exact is %ld  (diff: %4.2g %%)\n",
     732                 :              (long) range_records, (long) info.records,
     733                 :              labs((long) range_records - (long) info.records)*100.0/
     734                 :              info.records);
     735                 :     }
     736                 :   }
     737             486 :   for (i=0 ; i < 5 ; i++)
     738                 :   {
     739             405 :     for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
     740             405 :     for (k=rnd(1000)+1 ; k>0 && key1[k] == 0 ; k--) ;
     741             405 :     if (j != 0 && k != 0)
     742                 :     {
     743                 :       key_range min_key, max_key;
     744             395 :       if (j > k)
     745             131 :         swap_variables(int, j, k);
     746             395 :       sprintf((char*) key,"%6d",j);
     747             395 :       sprintf((char*) key2,"%6d",k);
     748                 : 
     749             395 :       min_key.key= key;
     750             395 :       min_key.keypart_map= HA_WHOLE_KEY;
     751             395 :       min_key.flag= HA_READ_AFTER_KEY;
     752             395 :       max_key.key= key2;
     753             395 :       max_key.keypart_map= HA_WHOLE_KEY;
     754             395 :       max_key.flag= HA_READ_BEFORE_KEY;
     755             395 :       range_records= maria_records_in_range(file, 0, &min_key, &max_key);
     756             395 :       records=0;
     757          128894 :       for (j++ ; j < k ; j++)
     758          128499 :         records+=key1[j];
     759             395 :       if ((long) range_records < (long) records*7/10-2 ||
     760                 :           (long) range_records > (long) records*14/10+2)
     761                 :       {
     762               0 :         printf("maria_records_range for key: %d returned %lu; Should be about %lu\n",
     763                 :                i, (ulong) range_records, (ulong) records);
     764               0 :         goto err;
     765                 :       }
     766             395 :       if (verbose && records)
     767                 :       {
     768               0 :         printf("maria_records_range returned %lu;  Exact is %lu  (diff: %4.2g %%)\n",
     769                 :                (ulong) range_records, (ulong) records,
     770                 :                labs((long) range_records-(long) records)*100.0/records);
     771                 : 
     772                 :       }
     773                 :     }
     774                 :     }
     775                 : 
     776              81 :   if (!silent)
     777               0 :     printf("- maria_info\n");
     778              81 :   maria_status(file,&info,HA_STATUS_VARIABLE | HA_STATUS_CONST);
     779              81 :   if (info.records != write_count-opt_delete || info.deleted > opt_delete + update
     780                 :       || info.keys != keys)
     781                 :   {
     782               0 :     puts("Wrong info from maria_info");
     783               0 :     printf("Got: records: %lu  delete: %lu  i_keys: %d\n",
     784                 :            (ulong) info.records, (ulong) info.deleted, info.keys);
     785               0 :     goto err;
     786                 :   }
     787              81 :   if (verbose)
     788                 :   {
     789                 :     char buff[80];
     790               0 :     get_date(buff,3,info.create_time);
     791               0 :     printf("info: Created %s\n",buff);
     792               0 :     get_date(buff,3,info.check_time);
     793               0 :     printf("info: checked %s\n",buff);
     794               0 :     get_date(buff,3,info.update_time);
     795               0 :     printf("info: Modified %s\n",buff);
     796                 :   }
     797                 : 
     798              81 :   maria_panic(HA_PANIC_WRITE);
     799              81 :   maria_panic(HA_PANIC_READ);
     800              81 :   if (maria_is_changed(file))
     801               0 :     puts("Warning: maria_is_changed reported that datafile was changed");
     802                 : 
     803              81 :   if (!silent)
     804               0 :     printf("- maria_extra(CACHE) + maria_rrnd.... + maria_extra(NO_CACHE)\n");
     805              81 :   if (maria_reset(file) || maria_extra(file,HA_EXTRA_CACHE,0))
     806                 :   {
     807               5 :     if (do_locking || (!use_blob && !pack_fields))
     808                 :     {
     809               0 :       puts("got error from maria_extra(HA_EXTRA_CACHE)");
     810               0 :       goto err;
     811                 :     }
     812                 :   }
     813              81 :   ant=0;
     814              81 :   assert(maria_scan_init(file) == 0);
     815          102471 :   while ((error= maria_scan(file,record)) != HA_ERR_END_OF_FILE &&
     816                 :          ant < write_count + 10)
     817          102390 :     ant+= error ? 0 : 1;
     818              81 :   maria_scan_end(file);
     819              81 :   if (ant != write_count-opt_delete)
     820                 :   {
     821               0 :     printf("scan with cache: I can only find: %d records of %d\n",
     822                 :            ant,write_count-opt_delete);
     823               0 :     maria_scan_end(file);
     824               0 :     goto err;
     825                 :   }
     826              81 :   if (maria_extra(file,HA_EXTRA_NO_CACHE,0))
     827                 :   {
     828               0 :     puts("got error from maria_extra(HA_EXTRA_NO_CACHE)");
     829               0 :     maria_scan_end(file);
     830               0 :     goto err;
     831                 :   }
     832              81 :   maria_scan_end(file);
     833                 : 
     834              81 :   ant=0;
     835              81 :   maria_scan_init(file);
     836          102552 :   while ((error=maria_scan(file,record)) != HA_ERR_END_OF_FILE &&
     837                 :          ant < write_count + 10)
     838          102390 :         ant+= error ? 0 : 1;
     839              81 :   if (ant != write_count-opt_delete)
     840                 :   {
     841               0 :     printf("scan with cache: I can only find: %d records of %d\n",
     842                 :            ant,write_count-opt_delete);
     843               0 :     maria_scan_end(file);
     844               0 :     goto err;
     845                 :   }
     846              81 :   maria_scan_end(file);
     847                 : 
     848              81 :   if (testflag == 5)
     849              81 :     goto end;
     850              81 :   if (checkpoint == 5 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     851              81 :     goto err;
     852                 : 
     853              81 :   if (!silent)
     854               0 :     printf("- Removing keys\n");
     855              81 :   DBUG_PRINT("progpos",("Removing keys"));
     856              81 :   lastpos = HA_OFFSET_ERROR;
     857                 :   /* DBUG_POP(); */
     858              81 :   maria_reset(file);
     859              81 :   found_parts=0;
     860              81 :   maria_scan_init(file);
     861          101629 :   while ((error= maria_scan(file,read_record)) != HA_ERR_END_OF_FILE)
     862                 :   {
     863          101470 :     info.recpos=maria_position(file);
     864          101470 :     if (lastpos >= info.recpos && lastpos != HA_OFFSET_ERROR)
     865                 :     {
     866               0 :       printf("maria_rrnd didn't advance filepointer; old: %ld, new: %ld\n",
     867                 :              (long) lastpos, (long) info.recpos);
     868               0 :       goto err;
     869                 :     }
     870          101470 :     lastpos=info.recpos;
     871          101470 :     if (error == 0)
     872                 :     {
     873           97897 :       if (opt_delete == (uint) remove_count)            /* While testing */
     874           97894 :         goto end;
     875           97894 :       if (rnd(2) == 1 && maria_rsame(file,read_record,-1))
     876                 :       {
     877               0 :         printf("can't find record %lx\n",(long) info.recpos);
     878               0 :         goto err;
     879                 :       }
     880           97894 :       if (use_blob)
     881                 :       {
     882                 :         ulong blob_length,pos;
     883                 :         uchar *ptr;
     884           20435 :         memcpy_fixed(&ptr, read_record+blob_pos+4, sizeof(ptr));
     885           20435 :         blob_length= uint4korr(read_record+blob_pos);
     886        55127759 :         for (pos=0 ; pos < blob_length ; pos++)
     887                 :         {
     888        55107324 :           if (ptr[pos] != (uchar) (blob_length+pos))
     889                 :           {
     890               0 :             printf("Found blob with wrong info at %ld\n",(long) lastpos);
     891               0 :             maria_scan_end(file);
     892               0 :             my_errno= 0;
     893               0 :             goto err;
     894                 :           }
     895                 :         }
     896                 :       }
     897           97894 :       if (maria_delete(file,read_record))
     898                 :       {
     899               0 :         printf("can't delete record: %6.6s, delete_count: %d\n",
     900                 :                read_record, opt_delete);
     901               0 :         maria_scan_end(file);
     902               0 :         goto err;
     903                 :       }
     904           97894 :       opt_delete++;
     905                 :     }
     906                 :     else
     907            3573 :       found_parts++;
     908                 :   }
     909              78 :   if (my_errno != HA_ERR_END_OF_FILE && my_errno != HA_ERR_RECORD_DELETED)
     910               0 :     printf("error: %d from maria_rrnd\n",my_errno);
     911              78 :   if (write_count != opt_delete)
     912                 :   {
     913               0 :     printf("Deleted only %d of %d records (%d parts)\n",opt_delete,write_count,
     914                 :            found_parts);
     915               0 :     maria_scan_end(file);
     916               0 :     goto err;
     917                 :   }
     918              78 :   if (testflag == 6)
     919              62 :     goto end;
     920              62 :   if (checkpoint == 6 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
     921             152 :     goto err;
     922                 : 
     923             152 : end:
     924             152 :   maria_scan_end(file);
     925             152 :   if (die_in_middle_of_transaction)
     926                 :   {
     927                 :     /* As commit record is not done, UNDO entries needs to be rolled back */
     928              35 :     switch (die_in_middle_of_transaction) {
     929                 :     case 1:
     930                 :       /*
     931                 :         Flush changed data and index pages go to disk
     932                 :         That will also flush log. Recovery will skip REDOs and apply UNDOs.
     933                 :       */
     934              11 :       _ma_flush_table_files(file, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX,
     935                 :                             FLUSH_RELEASE, FLUSH_RELEASE);
     936              11 :       break;
     937                 :     case 2:
     938                 :       /*
     939                 :         Just flush log. Pages are likely to not be on disk. Recovery will
     940                 :         then execute REDOs and UNDOs.
     941                 :       */
     942               8 :       if (translog_flush(file->trn->undo_lsn))
     943                 :         goto err;
     944                 :       break;
     945                 :     case 3:
     946                 :       /*
     947                 :         Flush nothing. Pages and log are likely to not be on disk. Recovery
     948                 :         will then do nothing.
     949                 :       */
     950                 :       break;
     951                 :     case 4:
     952                 :       /*
     953                 :         Flush changed data pages go to disk. Changed index pages are not
     954                 :         flushed. Recovery will skip some REDOs and apply UNDOs.
     955                 :       */
     956               8 :       _ma_flush_table_files(file, MARIA_FLUSH_DATA, FLUSH_RELEASE,
     957                 :                             FLUSH_RELEASE);
     958                 :       /*
     959                 :         We have to flush log separately as the redo for the last key page
     960                 :         may not be flushed
     961                 :       */
     962               8 :       if (translog_flush(file->trn->undo_lsn))
     963              35 :         goto err;
     964                 :       break;
     965                 :     }
     966              35 :     printf("Dying on request without maria_commit()/maria_close()\n");
     967              35 :     exit(0);
     968                 :   }
     969             117 :   if (maria_commit(file))
     970             117 :     goto err;
     971             117 :   if (maria_close(file))
     972                 :   {
     973               0 :     file= 0;
     974               0 :     goto err;
     975                 :   }
     976             117 :   file= 0;
     977             117 :   maria_panic(HA_PANIC_CLOSE);                  /* Should close log */
     978             117 :   if (!silent)
     979                 :   {
     980               0 :     printf("\nFollowing test have been made:\n");
     981               0 :     printf("Write records: %d\nUpdate records: %d\nSame-key-read: %d\nDelete records: %d\n", write_count,update,dupp_keys,opt_delete);
     982               0 :     if (rec_pointer_size)
     983               0 :       printf("Record pointer size:  %d\n",rec_pointer_size);
     984               0 :     printf("maria_block_size:    %lu\n", maria_block_size);
     985               0 :     if (write_cacheing)
     986               0 :       puts("Key cache resized");
     987               0 :     if (write_cacheing)
     988               0 :       puts("Write cacheing used");
     989               0 :     if (write_cacheing)
     990               0 :       puts("quick mode");
     991               0 :     if (async_io && do_locking)
     992               0 :       puts("Asyncron io with locking used");
     993               0 :     else if (do_locking)
     994               0 :       puts("Locking used");
     995               0 :     if (use_blob)
     996               0 :       puts("blobs used");
     997               0 :     printf("key cache status: \n\
     998                 : blocks used:%10lu\n\
     999                 : not flushed:%10lu\n\
    1000                 : w_requests: %10lu\n\
    1001                 : writes:     %10lu\n\
    1002                 : r_requests: %10lu\n\
    1003                 : reads:      %10lu\n",
    1004                 :            maria_pagecache->blocks_used,
    1005                 :            maria_pagecache->global_blocks_changed,
    1006                 :            (ulong) maria_pagecache->global_cache_w_requests,
    1007                 :            (ulong) maria_pagecache->global_cache_write,
    1008                 :            (ulong) maria_pagecache->global_cache_r_requests,
    1009                 :            (ulong) maria_pagecache->global_cache_read);
    1010                 :   }
    1011             117 :   maria_end();
    1012             117 :   my_free(blob_buffer, MYF(MY_ALLOW_ZERO_PTR));
    1013             117 :   my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO);
    1014             117 :   return(0);
    1015               1 : err:
    1016               1 :   printf("got error: %d when using MARIA-database\n",my_errno);
    1017               1 :   if (file)
    1018                 :   {
    1019               1 :     if (maria_commit(file))
    1020               1 :       goto err;
    1021               1 :     VOID(maria_close(file));
    1022                 :   }
    1023               1 :   maria_end();
    1024               1 :   return(1);
    1025                 : } /* main */
    1026                 : 
    1027                 : 
    1028                 : /* Read options */
    1029                 : 
    1030                 : static void get_options(int argc, char **argv)
    1031             153 : {
    1032                 :   char *pos,*progname;
    1033                 : 
    1034             153 :   progname= argv[0];
    1035                 : 
    1036            1551 :   while (--argc >0 && *(pos = *(++argv)) == '-' ) {
    1037            1245 :     switch(*++pos) {
    1038                 :     case 'B':
    1039              10 :       pack_type= HA_BINARY_PACK_KEY;
    1040              10 :       break;
    1041                 :     case 'b':
    1042              67 :       use_blob= 1000;
    1043              67 :       if (*++pos)
    1044              65 :         use_blob= atol(pos);
    1045                 :       break;
    1046                 :     case 'K':                           /* Use key cacheing */
    1047             116 :       pagecacheing=1;
    1048             116 :       if (*++pos)
    1049               0 :         pagecache_size=atol(pos);
    1050                 :       break;
    1051                 :     case 'W':                           /* Use write cacheing */
    1052              95 :       write_cacheing=1;
    1053              95 :       if (*++pos)
    1054               0 :         my_default_record_cache_size=atoi(pos);
    1055                 :       break;
    1056                 :     case 'd':
    1057              13 :       remove_count= atoi(++pos);
    1058              13 :       break;
    1059                 :     case 'i':
    1060               0 :       if (*++pos)
    1061               0 :         srand(srand_arg= atoi(pos));
    1062                 :       break;
    1063                 :     case 'L':
    1064             111 :       do_locking=1;
    1065             111 :       break;
    1066                 :     case 'a':                           /* use asyncron io */
    1067               0 :       async_io=1;
    1068               0 :       if (*++pos)
    1069               0 :         my_default_record_cache_size=atoi(pos);
    1070                 :       break;
    1071                 :     case 'v':                           /* verbose */
    1072               0 :       verbose=1;
    1073               0 :       break;
    1074                 :     case 'm':                           /* records */
    1075              27 :       if ((recant=atoi(++pos)) < 10 && testflag > 2)
    1076                 :       {
    1077               0 :         fprintf(stderr,"record count must be >= 10 (if testflag > 2)\n");
    1078               0 :         exit(1);
    1079                 :       }
    1080                 :       break;
    1081                 :     case 'e':                           /* maria_block_length */
    1082                 :     case 'E':
    1083              20 :       if ((maria_block_size= atoi(++pos)) < MARIA_MIN_KEY_BLOCK_LENGTH ||
    1084                 :           maria_block_size > MARIA_MAX_KEY_BLOCK_LENGTH)
    1085                 :       {
    1086               0 :         fprintf(stderr,"Wrong maria_block_length\n");
    1087               0 :         exit(1);
    1088                 :       }
    1089              20 :       maria_block_size= my_round_up_to_next_power(maria_block_size);
    1090              20 :       break;
    1091                 :     case 'f':
    1092               0 :       if ((first_key=atoi(++pos)) < 0 || first_key >= MARIA_KEYS)
    1093               0 :         first_key=0;
    1094                 :       break;
    1095                 :     case 'H':
    1096              32 :       checkpoint= atoi(++pos);
    1097              32 :       break;
    1098                 :     case 'k':
    1099               0 :       if ((keys=(uint) atoi(++pos)) < 1 ||
    1100                 :            keys > (uint) (MARIA_KEYS-first_key))
    1101               0 :         keys=MARIA_KEYS-first_key;
    1102                 :       break;
    1103                 :     case 'M':
    1104             124 :       record_type= BLOCK_RECORD;
    1105             124 :       break;
    1106                 :     case 'P':
    1107             100 :       pack_type=0;                      /* Don't use DIFF_LENGTH */
    1108             100 :       pack_seg=0;
    1109             100 :       break;
    1110                 :     case 'R':                           /* Length of record pointer */
    1111               7 :       rec_pointer_size=atoi(++pos);
    1112               7 :       if (rec_pointer_size > 7)
    1113               0 :         rec_pointer_size=0;
    1114                 :       break;
    1115                 :     case 'S':
    1116              17 :       pack_fields=0;                    /* Static-length-records */
    1117              17 :       record_type= STATIC_RECORD;
    1118              17 :       break;
    1119                 :     case 's':
    1120             153 :       silent=1;
    1121             153 :       break;
    1122                 :     case 't':
    1123              77 :       testflag=atoi(++pos);             /* testmod */
    1124              77 :       break;
    1125                 :     case 'T':
    1126             108 :       transactional= 1;
    1127             108 :       break;
    1128                 :     case 'A':
    1129              40 :       die_in_middle_of_transaction= atoi(++pos);
    1130              40 :       break;
    1131                 :     case 'u':
    1132               0 :       update_count=atoi(++pos);
    1133               0 :       if (!update_count)
    1134               0 :         skip_update= 1;
    1135                 :       break;
    1136                 :     case 'q':
    1137               0 :       opt_quick_mode=1;
    1138               0 :       break;
    1139                 :     case 'c':
    1140             106 :       create_flag|= HA_CREATE_CHECKSUM | HA_CREATE_PAGE_CHECKSUM;
    1141             106 :       break;
    1142                 :     case 'D':
    1143               5 :       create_flag|=HA_CREATE_DELAY_KEY_WRITE;
    1144               5 :       break;
    1145                 :     case 'g':
    1146               0 :       skip_update= TRUE;
    1147               0 :       break;
    1148                 :     case 'C':
    1149              17 :       opt_versioning= 1;
    1150              17 :       break;
    1151                 :     case '?':
    1152                 :     case 'I':
    1153                 :     case 'V':
    1154               0 :       printf("%s  Ver 1.2 for %s at %s\n",progname,SYSTEM_TYPE,MACHINE_TYPE);
    1155               0 :       puts("By Monty, for testing Maria\n");
    1156               0 :       printf("Usage: %s [-?AbBcCDIKLPRqSsTVWltv] [-k#] [-f#] [-m#] [-e#] [-E#] [-t#]\n",
    1157                 :              progname);
    1158               0 :       exit(0);
    1159                 :     case '#':
    1160               0 :       DBUG_PUSH (++pos);
    1161               0 :       break;
    1162                 :     default:
    1163               0 :       printf("Illegal option: '%c'\n",*pos);
    1164                 :       break;
    1165                 :     }
    1166                 :   }
    1167                 :   return;
    1168                 : } /* get options */
    1169                 : 
    1170                 :         /* Get a random value 0 <= x <= n */
    1171                 : 
    1172                 : static uint rnd(uint max_value)
    1173         1292778 : {
    1174         1292778 :   return (uint) ((rand() & 32767)/32767.0*max_value);
    1175                 : } /* rnd */
    1176                 : 
    1177                 : 
    1178                 :         /* Create a variable length record */
    1179                 : 
    1180                 : static void fix_length(uchar *rec, uint length)
    1181          269161 : {
    1182          269161 :   bmove(rec+STANDARD_LENGTH,
    1183                 :         "0123456789012345678901234567890123456789012345678901234567890",
    1184                 :         length-STANDARD_LENGTH);
    1185          269161 :   strfill((char*) rec+length,STANDARD_LENGTH+60-length,' ');
    1186                 : } /* fix_length */
    1187                 : 
    1188                 : 
    1189                 : /* Put maybe a blob in record */
    1190                 : 
    1191                 : static int first_entry;
    1192                 : 
    1193                 : static void put_blob_in_record(uchar *blob_pos, char **blob_buffer,
    1194                 :                                ulong *blob_length)
    1195          248971 : {
    1196                 :   ulong i,length;
    1197          248971 :   *blob_length= 0;
    1198          248971 :   if (use_blob)
    1199                 :   {
    1200           44385 :     if (! *blob_buffer &&
    1201                 :         !(*blob_buffer=my_malloc((uint) use_blob,MYF(MY_WME))))
    1202                 :     {
    1203               0 :       use_blob= 0;
    1204               0 :       return;
    1205                 :     }
    1206           44385 :     if (rnd(10) == 0)
    1207                 :     {
    1208            4692 :       if (first_entry++ == 0)
    1209                 :       {
    1210                 :         /* Ensure we have at least one blob of max length in file */
    1211              51 :         length= use_blob;
    1212                 :       }
    1213                 :       else
    1214            4641 :         length=rnd(use_blob);
    1215       105112049 :       for (i=0 ; i < length ; i++)
    1216       105107357 :         (*blob_buffer)[i]=(char) (length+i);
    1217            4692 :       int4store(blob_pos,length);
    1218            4692 :       memcpy_fixed(blob_pos+4,(char*) blob_buffer,sizeof(char*));
    1219            4692 :       *blob_length= length;
    1220                 :     }
    1221                 :     else
    1222                 :     {
    1223           39693 :       int4store(blob_pos,0);
    1224                 :     }
    1225                 :   }
    1226                 :   return;
    1227                 : }
    1228                 : 
    1229                 : 
    1230                 : static void copy_key(MARIA_HA *info,uint inx,uchar *rec,uchar *key_buff)
    1231             972 : {
    1232                 :   HA_KEYSEG *keyseg;
    1233                 : 
    1234            2106 :   for (keyseg=info->s->keyinfo[inx].seg ; keyseg->type ; keyseg++)
    1235                 :   {
    1236            1134 :     memcpy(key_buff,rec+keyseg->start,(size_t) keyseg->length);
    1237            1134 :     key_buff+=keyseg->length;
    1238                 :   }
    1239                 :   return;
    1240                 : }

Generated by: LTP GCOV extension version 1.4