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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
15
16/* Testing of the basic functions of a MARIA table */
17
18#include "maria_def.h"
19#include <my_getopt.h>
20#include <m_string.h>
21#include "ma_control_file.h"
22#include "ma_loghandler.h"
23#include "ma_checkpoint.h"
24#include "trnman.h"
25
26extern PAGECACHE *maria_log_pagecache;
27extern char *maria_data_root;
28
29#define MAX_REC_LENGTH 1024
30
31static void usage();
32
33static int rec_pointer_size=0, flags[50], testflag, checkpoint;
34static int key_field=FIELD_SKIP_PRESPACE,extra_field=FIELD_SKIP_ENDSPACE;
35static int key_type=HA_KEYTYPE_NUM;
36static int create_flag=0;
37static ulong blob_length;
38static enum data_file_type record_type= DYNAMIC_RECORD;
39
40static uint insert_count, update_count, remove_count;
41static uint pack_keys=0, pack_seg=0, key_length;
42static uint unique_key=HA_NOSAME;
43static uint die_in_middle_of_transaction;
44static my_bool pagecacheing, null_fields, silent, skip_update, opt_unique;
45static my_bool verbose, skip_delete, transactional;
46static my_bool opt_versioning= 0;
47static MARIA_COLUMNDEF recinfo[4];
48static MARIA_KEYDEF keyinfo[10];
49static HA_KEYSEG keyseg[10];
50static HA_KEYSEG uniqueseg[10];
51
52static int run_test(const char *filename);
53static void get_options(int argc, char *argv[]);
54static void create_key(uchar *key,uint rownr);
55static void create_record(uchar *record,uint rownr);
56static void update_record(uchar *record);
57
58/*
59 These are here only for testing of recovery with undo. We are not
60 including maria_def.h here as this test is also to be an example of
61 how to use maria outside of the maria directory
62*/
63
64extern int _ma_flush_table_files(MARIA_HA *info, uint flush_data_or_index,
65 enum flush_type flush_type_for_data,
66 enum flush_type flush_type_for_index);
67#define MARIA_FLUSH_DATA 1
68
69
70int main(int argc,char *argv[])
71{
72 char buff[FN_REFLEN];
73#ifdef SAFE_MUTEX
74 safe_mutex_deadlock_detector= 1;
75#endif
76 MY_INIT(argv[0]);
77 maria_data_root= (char *)".";
78 get_options(argc,argv);
79 /* Maria requires that we always have a page cache */
80 if (maria_init() ||
81 (init_pagecache(maria_pagecache, maria_block_size * 16, 0, 0,
82 maria_block_size, 0, MY_WME) == 0) ||
83 ma_control_file_open(TRUE, TRUE) ||
84 (init_pagecache(maria_log_pagecache,
85 TRANSLOG_PAGECACHE_SIZE, 0, 0,
86 TRANSLOG_PAGE_SIZE, 0, MY_WME) == 0) ||
87 translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
88 0, 0, maria_log_pagecache,
89 TRANSLOG_DEFAULT_FLAGS, 0) ||
90 (transactional && (trnman_init(0) || ma_checkpoint_init(0))))
91 {
92 fprintf(stderr, "Error in initialization\n");
93 exit(1);
94 }
95 if (opt_versioning)
96 init_thr_lock();
97
98 exit(run_test(fn_format(buff, "test1", maria_data_root, "", MYF(0))));
99}
100
101
102static int run_test(const char *filename)
103{
104 MARIA_HA *file;
105 int i,j= 0,error,deleted,rec_length,uniques=0;
106 uint offset_to_key;
107 ha_rows found,row_count;
108 uchar record[MAX_REC_LENGTH],key[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH];
109 MARIA_UNIQUEDEF uniquedef;
110 MARIA_CREATE_INFO create_info;
111
112 if (die_in_middle_of_transaction)
113 null_fields= 1;
114
115 bzero((char*) recinfo,sizeof(recinfo));
116 bzero((char*) &create_info,sizeof(create_info));
117
118 /* First define 2 columns */
119 create_info.null_bytes= 1;
120 recinfo[0].type= key_field;
121 recinfo[0].length= (key_field == FIELD_BLOB ? 4+portable_sizeof_char_ptr :
122 key_length);
123 if (key_field == FIELD_VARCHAR)
124 recinfo[0].length+= HA_VARCHAR_PACKLENGTH(key_length);
125 recinfo[1].type=extra_field;
126 recinfo[1].length= (extra_field == FIELD_BLOB ? 4 + portable_sizeof_char_ptr : 24);
127 if (extra_field == FIELD_VARCHAR)
128 recinfo[1].length+= HA_VARCHAR_PACKLENGTH(recinfo[1].length);
129 recinfo[1].null_bit= null_fields ? 2 : 0;
130
131 if (opt_unique)
132 {
133 recinfo[2].type=FIELD_CHECK;
134 recinfo[2].length=MARIA_UNIQUE_HASH_LENGTH;
135 }
136 rec_length= recinfo[0].length + recinfo[1].length + recinfo[2].length +
137 create_info.null_bytes;
138
139 if (key_type == HA_KEYTYPE_VARTEXT1 &&
140 key_length > 255)
141 key_type= HA_KEYTYPE_VARTEXT2;
142
143 /* Define a key over the first column */
144 keyinfo[0].seg=keyseg;
145 keyinfo[0].keysegs=1;
146 keyinfo[0].block_length= 0; /* Default block length */
147 keyinfo[0].key_alg=HA_KEY_ALG_BTREE;
148 keyinfo[0].seg[0].type= key_type;
149 keyinfo[0].seg[0].flag= pack_seg;
150 keyinfo[0].seg[0].start=1;
151 keyinfo[0].seg[0].length=key_length;
152 keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0;
153 keyinfo[0].seg[0].null_pos=0;
154 keyinfo[0].seg[0].language= default_charset_info->number;
155 if (pack_seg & HA_BLOB_PART)
156 {
157 keyinfo[0].seg[0].bit_start=4; /* Length of blob length */
158 }
159 keyinfo[0].flag = (uint8) (pack_keys | unique_key);
160
161 bzero((uchar*) flags,sizeof(flags));
162 if (opt_unique)
163 {
164 uint start;
165 uniques=1;
166 bzero((char*) &uniquedef,sizeof(uniquedef));
167 bzero((char*) uniqueseg,sizeof(uniqueseg));
168 uniquedef.seg=uniqueseg;
169 uniquedef.keysegs=2;
170
171 /* Make a unique over all columns (except first NULL fields) */
172 for (i=0, start=1 ; i < 2 ; i++)
173 {
174 uniqueseg[i].start=start;
175 start+=recinfo[i].length;
176 uniqueseg[i].length=recinfo[i].length;
177 uniqueseg[i].language= default_charset_info->number;
178 }
179 uniqueseg[0].type= key_type;
180 uniqueseg[0].null_bit= null_fields ? 2 : 0;
181 uniqueseg[1].type= HA_KEYTYPE_TEXT;
182 if (extra_field == FIELD_BLOB)
183 {
184 uniqueseg[1].length=0; /* The whole blob */
185 uniqueseg[1].bit_start=4; /* long blob */
186 uniqueseg[1].flag|= HA_BLOB_PART;
187 }
188 else if (extra_field == FIELD_VARCHAR)
189 {
190 uniqueseg[1].flag|= HA_VAR_LENGTH_PART;
191 uniqueseg[1].type= (HA_VARCHAR_PACKLENGTH(recinfo[1].length-1) == 1 ?
192 HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2);
193 }
194 }
195 else
196 uniques=0;
197
198 offset_to_key= MY_TEST(null_fields);
199 if (key_field == FIELD_BLOB || key_field == FIELD_VARCHAR)
200 offset_to_key+= 2;
201
202 if (!silent)
203 printf("- Creating maria file\n");
204 create_info.max_rows=(ulong) (rec_pointer_size ?
205 (1L << (rec_pointer_size*8))/40 :
206 0);
207 create_info.transactional= transactional;
208 if (maria_create(filename, record_type, 1, keyinfo,2+opt_unique,recinfo,
209 uniques, &uniquedef, &create_info,
210 create_flag))
211 goto err;
212 if (!(file=maria_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
213 goto err;
214 if (!silent)
215 printf("- Writing key:s\n");
216
217 if (maria_begin(file))
218 goto err;
219 if (opt_versioning)
220 maria_versioning(file, 1);
221 my_errno=0;
222 row_count=deleted=0;
223 for (i=49 ; i>=1 ; i-=2 )
224 {
225 if (insert_count-- == 0)
226 {
227 if (testflag)
228 break;
229 maria_close(file);
230 exit(0);
231 }
232 j=i%25 +1;
233 create_record(record,j);
234 error=maria_write(file,record);
235 if (!error)
236 row_count++;
237 flags[j]=1;
238 if (verbose || error)
239 printf("J= %2d maria_write: %d errno: %d\n", j,error,my_errno);
240 }
241
242 if (maria_commit(file) || maria_begin(file))
243 goto err;
244
245 if (checkpoint == 1 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
246 goto err;
247
248 if (testflag == 1)
249 goto end;
250
251 /* Insert 2 rows with null values */
252 if (null_fields)
253 {
254 create_record(record,0);
255 error=maria_write(file,record);
256 if (!error)
257 row_count++;
258 if (verbose || error)
259 printf("J= NULL maria_write: %d errno: %d\n", error,my_errno);
260 error=maria_write(file,record);
261 if (!error)
262 row_count++;
263 if (verbose || error)
264 printf("J= NULL maria_write: %d errno: %d\n", error,my_errno);
265 flags[0]=2;
266 }
267
268 if (checkpoint == 2 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
269 goto err;
270
271 if (testflag == 2)
272 {
273 printf("Terminating after inserts\n");
274 goto end;
275 }
276
277 if (maria_commit(file) || maria_begin(file))
278 goto err;
279
280 if (!skip_update)
281 {
282 if (opt_unique)
283 {
284 if (!silent)
285 printf("- Checking unique constraint\n");
286 create_record(record,j); /* Check last created row */
287 if (!maria_write(file,record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE)
288 {
289 printf("unique check failed\n");
290 }
291 }
292 if (!silent)
293 printf("- Updating rows\n");
294
295 /* Update first last row to force extend of file */
296 if (maria_rsame(file,read_record,-1))
297 {
298 printf("Can't find last row with maria_rsame\n");
299 }
300 else
301 {
302 memcpy(record,read_record,rec_length);
303 update_record(record);
304 if (maria_update(file,read_record,record))
305 {
306 printf("Can't update last row: %.*s\n",
307 keyinfo[0].seg[0].length,read_record+1);
308 }
309 }
310
311 /* Read through all rows and update them */
312 maria_scan_init(file);
313
314 found=0;
315 while ((error= maria_scan(file,read_record)) == 0)
316 {
317 if (--update_count == 0) { maria_close(file); exit(0) ; }
318 memcpy(record,read_record,rec_length);
319 update_record(record);
320 if (maria_update(file,read_record,record))
321 {
322 printf("Can't update row: %.*s, error: %d\n",
323 keyinfo[0].seg[0].length,record+1,my_errno);
324 }
325 found++;
326 }
327 if (found != row_count)
328 printf("Found %ld of %ld rows\n", (ulong) found, (ulong) row_count);
329 maria_scan_end(file);
330 }
331
332 if (checkpoint == 3 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
333 goto err;
334
335 if (testflag == 3)
336 {
337 printf("Terminating after updates\n");
338 goto end;
339 }
340 if (!silent)
341 printf("- Reopening file\n");
342 if (maria_commit(file))
343 goto err;
344 if (maria_close(file))
345 goto err;
346 if (!(file=maria_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
347 goto err;
348 if (maria_begin(file))
349 goto err;
350 if (opt_versioning)
351 maria_versioning(file, 1);
352 if (!skip_delete)
353 {
354 if (!silent)
355 printf("- Removing keys\n");
356
357 for (i=0 ; i <= 10 ; i++)
358 {
359 /*
360 If you want to debug the problem in ma_test_recovery with BLOBs
361 (see @todo there), you can break out of the loop after just one
362 delete, it is enough, like this:
363 if (i==1) break;
364 */
365 /* testing */
366 if (remove_count-- == 0)
367 {
368 fprintf(stderr,
369 "delete-rows number of rows deleted; Going down hard!\n");
370 goto end;
371 }
372 j=i*2;
373 if (!flags[j])
374 continue;
375 create_key(key,j);
376 my_errno=0;
377 if ((error = maria_rkey(file, read_record, 0, key,
378 HA_WHOLE_KEY, HA_READ_KEY_EXACT)))
379 {
380 if (verbose || (flags[j] >= 1 ||
381 (error && my_errno != HA_ERR_KEY_NOT_FOUND)))
382 printf("key: '%.*s' maria_rkey: %3d errno: %3d\n",
383 (int) key_length,key+offset_to_key,error,my_errno);
384 }
385 else
386 {
387 error=maria_delete(file,read_record);
388 if (verbose || error)
389 printf("key: '%.*s' maria_delete: %3d errno: %3d\n",
390 (int) key_length, key+offset_to_key, error, my_errno);
391 if (! error)
392 {
393 deleted++;
394 flags[j]--;
395 }
396 }
397 }
398 }
399
400 if (checkpoint == 4 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE))
401 goto err;
402
403 if (testflag == 4)
404 {
405 printf("Terminating after deletes\n");
406 goto end;
407 }
408
409 if (!silent)
410 printf("- Reading rows with key\n");
411 record[1]= 0; /* For nicer printf */
412
413 if (record_type == NO_RECORD)
414 maria_extra(file, HA_EXTRA_KEYREAD, 0);
415
416 for (i=0 ; i <= 25 ; i++)
417 {
418 create_key(key,i);
419 my_errno=0;
420 error=maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT);
421 if (verbose ||
422 (error == 0 && flags[i] == 0 && unique_key) ||
423 (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND)))
424 {
425 printf("key: '%.*s' maria_rkey: %3d errno: %3d record: %s\n",
426 (int) key_length,key+offset_to_key,error,my_errno,record+1);
427 }
428 }
429 if (record_type == NO_RECORD)
430 {
431 maria_extra(file, HA_EXTRA_NO_KEYREAD, 0);
432 goto end;
433 }
434
435 if (!silent)
436 printf("- Reading rows with position\n");
437
438 if (maria_scan_init(file))
439 {
440 fprintf(stderr, "maria_scan_init failed\n");
441 goto err;
442 }
443
444 for (i=1,found=0 ; i <= 30 ; i++)
445 {
446 my_errno=0;
447 if ((error= maria_scan(file, read_record)) == HA_ERR_END_OF_FILE)
448 {
449 if (found != row_count-deleted)
450 printf("Found only %ld of %ld rows\n", (ulong) found,
451 (ulong) (row_count - deleted));
452 break;
453 }
454 if (!error)
455 found++;
456 if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED &&
457 error != HA_ERR_END_OF_FILE))
458 {
459 printf("pos: %2d maria_rrnd: %3d errno: %3d record: %s\n",
460 i-1,error,my_errno,read_record+1);
461 }
462 }
463 maria_scan_end(file);
464
465end:
466 if (die_in_middle_of_transaction)
467 {
468 /* As commit record is not done, UNDO entries needs to be rolled back */
469 switch (die_in_middle_of_transaction) {
470 case 1:
471 /*
472 Flush changed pages go to disk. That will also flush log. Recovery
473 will skip REDOs and apply UNDOs.
474 */
475 _ma_flush_table_files(file, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX,
476 FLUSH_RELEASE, FLUSH_RELEASE);
477 break;
478 case 2:
479 /*
480 Just flush log. Pages are likely to not be on disk. Recovery will
481 then execute REDOs and UNDOs.
482 */
483 if (translog_flush(file->trn->undo_lsn))
484 goto err;
485 break;
486 case 3:
487 /*
488 Flush nothing. Pages and log are likely to not be on disk. Recovery
489 will then do nothing.
490 */
491 break;
492 case 4:
493 /*
494 Flush changed data pages go to disk. Changed index pages are not
495 flushed. Recovery will skip some REDOs and apply UNDOs.
496 */
497 _ma_flush_table_files(file, MARIA_FLUSH_DATA, FLUSH_RELEASE,
498 FLUSH_RELEASE);
499 /*
500 We have to flush log separately as the redo for the last key page
501 may not be flushed
502 */
503 if (translog_flush(file->trn->undo_lsn))
504 goto err;
505 break;
506 }
507 printf("Dying on request without maria_commit()/maria_close()\n");
508 sf_leaking_memory= 1;
509 exit(0);
510 }
511
512 if (maria_commit(file))
513 goto err;
514 if (maria_close(file))
515 goto err;
516 maria_end();
517 my_uuid_end();
518 my_end(MY_CHECK_ERROR);
519
520 return (0);
521err:
522 printf("got error: %3d when using maria-database\n",my_errno);
523 return 1; /* skip warning */
524}
525
526
527static void create_key_part(uchar *key,uint rownr)
528{
529 if (!unique_key)
530 rownr&=7; /* Some identical keys */
531 if (keyinfo[0].seg[0].type == HA_KEYTYPE_NUM)
532 {
533 sprintf((char*) key,"%*d",keyinfo[0].seg[0].length,rownr);
534 }
535 else if (keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT1 ||
536 keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT2)
537 { /* Alpha record */
538 /* Create a key that may be easily packed */
539 bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B');
540 sprintf((char*) key+keyinfo[0].seg[0].length-2,"%-2d",rownr);
541 if ((rownr & 7) == 0)
542 {
543 /* Change the key to force a unpack of the next key */
544 bfill(key+3,keyinfo[0].seg[0].length-5,rownr < 10 ? 'a' : 'b');
545 }
546 }
547 else
548 { /* Alpha record */
549 if (keyinfo[0].seg[0].flag & HA_SPACE_PACK)
550 sprintf((char*) key,"%-*d",keyinfo[0].seg[0].length,rownr);
551 else
552 {
553 /* Create a key that may be easily packed */
554 bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B');
555 sprintf((char*) key+keyinfo[0].seg[0].length-2,"%-2d",rownr);
556 if ((rownr & 7) == 0)
557 {
558 /* Change the key to force a unpack of the next key */
559 key[1]= (rownr < 10 ? 'a' : 'b');
560 }
561 }
562 }
563}
564
565
566static void create_key(uchar *key,uint rownr)
567{
568 if (keyinfo[0].seg[0].null_bit)
569 {
570 if (rownr == 0)
571 {
572 key[0]=1; /* null key */
573 key[1]=0; /* For easy print of key */
574 return;
575 }
576 *key++=0;
577 }
578 if (keyinfo[0].seg[0].flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART))
579 {
580 size_t tmp;
581 create_key_part(key+2,rownr);
582 tmp=strlen((char*) key+2);
583 int2store(key,tmp);
584 }
585 else
586 create_key_part(key,rownr);
587}
588
589
590static uchar blob_key[MAX_REC_LENGTH];
591static uchar blob_record[MAX_REC_LENGTH+20*20];
592
593
594static void create_record(uchar *record,uint rownr)
595{
596 uchar *pos;
597 bzero((char*) record,MAX_REC_LENGTH);
598 record[0]=1; /* delete marker */
599 if (rownr == 0 && keyinfo[0].seg[0].null_bit)
600 record[0]|=keyinfo[0].seg[0].null_bit; /* Null key */
601
602 pos=record+1;
603 if (recinfo[0].type == FIELD_BLOB)
604 {
605 size_t tmp;
606 uchar *ptr;
607 create_key_part(blob_key,rownr);
608 tmp=strlen((char*) blob_key);
609 int4store(pos,tmp);
610 ptr=blob_key;
611 memcpy(pos+4,&ptr,sizeof(char*));
612 pos+=recinfo[0].length;
613 }
614 else if (recinfo[0].type == FIELD_VARCHAR)
615 {
616 size_t tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[0].length-1);
617 create_key_part(pos+pack_length,rownr);
618 tmp= strlen((char*) pos+pack_length);
619 if (pack_length == 1)
620 *(uchar*) pos= (uchar) tmp;
621 else
622 int2store(pos,tmp);
623 pos+= recinfo[0].length;
624 }
625 else
626 {
627 create_key_part(pos,rownr);
628 pos+=recinfo[0].length;
629 }
630 if (recinfo[1].type == FIELD_BLOB)
631 {
632 size_t tmp;
633 uchar *ptr;;
634 sprintf((char*) blob_record,"... row: %d", rownr);
635 strappend((char*) blob_record,MY_MAX(MAX_REC_LENGTH-rownr,10),' ');
636 tmp=strlen((char*) blob_record);
637 int4store(pos,tmp);
638 ptr=blob_record;
639 memcpy(pos+4,&ptr,sizeof(char*));
640 }
641 else if (recinfo[1].type == FIELD_VARCHAR)
642 {
643 size_t tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
644 sprintf((char*) pos+pack_length, "... row: %d", rownr);
645 tmp= strlen((char*) pos+pack_length);
646 if (pack_length == 1)
647 *pos= (uchar) tmp;
648 else
649 int2store(pos,tmp);
650 }
651 else
652 {
653 sprintf((char*) pos,"... row: %d", rownr);
654 strappend((char*) pos,recinfo[1].length,' ');
655 }
656}
657
658/* change row to test re-packing of rows and reallocation of keys */
659
660static void update_record(uchar *record)
661{
662 uchar *pos=record+1;
663 if (recinfo[0].type == FIELD_BLOB)
664 {
665 uchar *column,*ptr;
666 int length;
667 length=uint4korr(pos); /* Long blob */
668 memcpy(&column,pos+4,sizeof(char*));
669 memcpy(blob_key,column,length); /* Move old key */
670 ptr=blob_key;
671 memcpy(pos+4,&ptr,sizeof(char*)); /* Store pointer to new key */
672 if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
673 default_charset_info->cset->casedn(default_charset_info,
674 (char*) blob_key, length,
675 (char*) blob_key, length);
676 pos+=recinfo[0].length;
677 }
678 else if (recinfo[0].type == FIELD_VARCHAR)
679 {
680 uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[0].length-1);
681 uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
682 default_charset_info->cset->casedn(default_charset_info,
683 (char*) pos + pack_length, length,
684 (char*) pos + pack_length, length);
685 pos+=recinfo[0].length;
686 }
687 else
688 {
689 if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
690 default_charset_info->cset->casedn(default_charset_info,
691 (char*) pos, keyinfo[0].seg[0].length,
692 (char*) pos, keyinfo[0].seg[0].length);
693 pos+=recinfo[0].length;
694 }
695
696 if (recinfo[1].type == FIELD_BLOB)
697 {
698 uchar *column;
699 int length;
700 length=uint4korr(pos);
701 memcpy(&column,pos+4,sizeof(char*));
702 memcpy(blob_record,column,length);
703 bfill(blob_record+length,20,'.'); /* Make it larger */
704 length+=20;
705 int4store(pos,length);
706 column=blob_record;
707 memcpy(pos+4,&column,sizeof(char*));
708 }
709 else if (recinfo[1].type == FIELD_VARCHAR)
710 {
711 /* Second field is longer than 10 characters */
712 uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
713 uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
714 pos= record+ recinfo[1].offset;
715 bfill(pos+pack_length+length,recinfo[1].length-length-pack_length,'.');
716 length=recinfo[1].length-pack_length;
717 if (pack_length == 1)
718 *(uchar*) pos= (uchar) length;
719 else
720 int2store(pos,length);
721 }
722 else
723 {
724 bfill(pos+recinfo[1].length-10,10,'.');
725 }
726}
727
728
729static struct my_option my_long_options[] =
730{
731 {"checkpoint", 'H', "Checkpoint at specified stage", (uchar**) &checkpoint,
732 (uchar**) &checkpoint, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
733 {"checksum", 'c', "Undocumented",
734 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
735#ifndef DBUG_OFF
736 {"debug", '#', "Undocumented",
737 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
738#endif
739 {"datadir", 'h', "Path to the database root.", &maria_data_root,
740 &maria_data_root, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
741 {"delete-rows", 'd', "Abort after this many rows has been deleted",
742 (uchar**) &remove_count, (uchar**) &remove_count, 0, GET_UINT, REQUIRED_ARG,
743 1000, 0, 0, 0, 0, 0},
744 {"help", '?', "Display help and exit",
745 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
746 {"insert-rows", 'i', "Undocumented", (uchar**) &insert_count,
747 (uchar**) &insert_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
748 {"key-alpha", 'a', "Use a key of type HA_KEYTYPE_TEXT",
749 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
750 {"key-binary-pack", 'B', "Undocumented",
751 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
752 {"key-blob", 'b', "Undocumented",
753 (uchar**) &blob_length, (uchar**) &blob_length,
754 0, GET_ULONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
755 {"key-cache", 'K', "Undocumented", (uchar**) &pagecacheing,
756 (uchar**) &pagecacheing, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
757 {"key-length", 'k', "Undocumented", (uchar**) &key_length,
758 (uchar**) &key_length, 0, GET_UINT, REQUIRED_ARG, 6, 0, 0, 0, 0, 0},
759 {"key-multiple", 'm', "Don't use unique keys",
760 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
761 {"key-prefix_pack", 'P', "Undocumented",
762 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
763 {"key-space_pack", 'p', "Undocumented",
764 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
765 {"key-varchar", 'w', "Test VARCHAR keys",
766 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
767 {"null-fields", 'N', "Define fields with NULL",
768 (uchar**) &null_fields, (uchar**) &null_fields, 0, GET_BOOL, NO_ARG,
769 0, 0, 0, 0, 0, 0},
770 {"row-fixed-size", 'S', "Fixed size records",
771 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
772 {"rows-in-block", 'M', "Store rows in block format",
773 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
774 {"rows-no-data", 'n', "Don't store any data, only keys",
775 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
776 {"row-pointer-size", 'R', "Undocumented", (uchar**) &rec_pointer_size,
777 (uchar**) &rec_pointer_size, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
778 {"silent", 's', "Undocumented",
779 (uchar**) &silent, (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
780 0, 0},
781 {"skip-delete", 'D', "Don't test deletes", (uchar**) &skip_delete,
782 (uchar**) &skip_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
783 {"skip-update", 'U', "Don't test updates", (uchar**) &skip_update,
784 (uchar**) &skip_update, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
785 {"testflag", 't', "Stop test at specified stage", (uchar**) &testflag,
786 (uchar**) &testflag, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
787 {"test-undo", 'A',
788 "Abort hard. Used for testing recovery with undo",
789 (uchar**) &die_in_middle_of_transaction,
790 (uchar**) &die_in_middle_of_transaction,
791 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
792 {"transactional", 'T',
793 "Test in transactional mode. (Only works with block format)",
794 (uchar**) &transactional, (uchar**) &transactional, 0, GET_BOOL, NO_ARG,
795 0, 0, 0, 0, 0, 0},
796 {"unique", 'E', "Check unique handling", (uchar**) &opt_unique,
797 (uchar**) &opt_unique, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
798 {"update-rows", 'u', "Max number of rows to update", (uchar**) &update_count,
799 (uchar**) &update_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
800 {"verbose", 'v', "Be more verbose", (uchar**) &verbose,
801 (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
802 {"version", 'V', "Print version number and exit",
803 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
804 {"versioning", 'C', "Use row versioning (only works with block format)",
805 (uchar**) &opt_versioning, (uchar**) &opt_versioning, 0, GET_BOOL,
806 NO_ARG, 0, 0, 0, 0, 0, 0},
807 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
808};
809
810
811static my_bool
812get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
813 char *argument __attribute__((unused)))
814{
815 switch(optid) {
816 case 'a':
817 key_type= HA_KEYTYPE_TEXT;
818 break;
819 case 'c':
820 create_flag|= HA_CREATE_CHECKSUM | HA_CREATE_PAGE_CHECKSUM;
821 break;
822 case 'R': /* Length of record pointer */
823 if (rec_pointer_size > 3)
824 rec_pointer_size=0;
825 break;
826 case 'P':
827 pack_keys= HA_PACK_KEY; /* Use prefix compression */
828 break;
829 case 'B':
830 pack_keys= HA_BINARY_PACK_KEY; /* Use binary compression */
831 break;
832 case 'M':
833 record_type= BLOCK_RECORD;
834 break;
835 case 'n':
836 record_type= NO_RECORD;
837 break;
838 case 'S':
839 if (key_field == FIELD_VARCHAR)
840 {
841 create_flag=0; /* Static sized varchar */
842 record_type= STATIC_RECORD;
843 }
844 else if (key_field != FIELD_BLOB)
845 {
846 key_field=FIELD_NORMAL; /* static-size record */
847 extra_field=FIELD_NORMAL;
848 record_type= STATIC_RECORD;
849 }
850 break;
851 case 'p':
852 pack_keys=HA_PACK_KEY; /* Use prefix + space packing */
853 pack_seg=HA_SPACE_PACK;
854 key_type=HA_KEYTYPE_TEXT;
855 break;
856 case 'm':
857 unique_key=0;
858 break;
859 case 'b':
860 key_field=FIELD_BLOB; /* blob key */
861 extra_field= FIELD_BLOB;
862 pack_seg|= HA_BLOB_PART;
863 key_type= HA_KEYTYPE_VARTEXT1;
864 if (record_type == STATIC_RECORD)
865 record_type= DYNAMIC_RECORD;
866 break;
867 case 'k':
868 if (key_length < 4 || key_length > HA_MAX_KEY_LENGTH)
869 {
870 fprintf(stderr,"Wrong key length\n");
871 exit(1);
872 }
873 break;
874 case 'w':
875 key_field=FIELD_VARCHAR; /* varchar keys */
876 extra_field= FIELD_VARCHAR;
877 key_type= HA_KEYTYPE_VARTEXT1;
878 pack_seg|= HA_VAR_LENGTH_PART;
879 if (record_type == STATIC_RECORD)
880 record_type= DYNAMIC_RECORD;
881 break;
882 case 'K': /* Use key cacheing */
883 pagecacheing=1;
884 break;
885 case 'V':
886 printf("test1 Ver 1.2 \n");
887 exit(0);
888 case '#':
889 DBUG_PUSH(argument);
890 break;
891 case '?':
892 usage();
893 exit(1);
894 }
895 return 0;
896}
897
898
899/* Read options */
900
901static void get_options(int argc, char *argv[])
902{
903 int ho_error;
904
905 if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
906 exit(ho_error);
907 if (transactional)
908 record_type= BLOCK_RECORD;
909 if (record_type == NO_RECORD)
910 skip_update= skip_delete= 1;
911
912
913 return;
914} /* get options */
915
916
917static void usage()
918{
919 printf("Usage: %s [options]\n\n", my_progname);
920 my_print_help(my_long_options);
921 my_print_variables(my_long_options);
922}
923
924#include "ma_check_standalone.h"
925
926