mariadb/storage/heap/hp_test2.c
unknown 09a53f28a7 Fixed a lot of compiler warnings and errors detected by Forte C++ on Solaris
Faster thr_alarm()
Added 'Opened_files' status variable to track calls to my_open()
Don't give warnings when running mysql_install_db
Added option --source-install to mysql_install_db

I had to do the following renames() as used polymorphism didn't work with Forte compiler on 64 bit systems
index_read()      -> index_read_map()
index_read_idx()  -> index_read_idx_map()
index_read_last() -> index_read_last_map()


BUILD/compile-solaris-sparc-forte:
  Updated script to current Solaris installations
  Now we compile by default for 64 bits
client/mysql.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
client/mysql_upgrade.c:
  Fixed compiler warning (on Forte)
client/mysqladmin.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
client/mysqlcheck.c:
  Fixed compiler warning (on Forte)
client/mysqldump.c:
  Fixed compiler warning (on Forte)
client/mysqlslap.c:
  Fixed compiler warning (on Forte)
client/mysqltest.c:
  Fixed compiler warning (on Forte)
client/sql_string.cc:
  Avoid compiler warnings when using C function pointers in C++
configure.in:
  Added detection of mtmalloc and ieeefp.h
extra/replace.c:
  Fixed compiler warning (on Forte)
include/m_ctype.h:
  Added some typedef's to make it easy to use C function pointers in C++
include/my_sys.h:
  Added my_file_total_opened (counter for calls to my_open())
include/myisam.h:
  Fixed compiler warning (on Forte)
libmysql/libmysql.c:
  Fixed compiler warning (on Forte) by adding casts and change types
libmysql/manager.c:
  Fixed compiler warning (on Forte) by adding casts and change types
mysql-test/r/ctype_cp932_binlog_stm.result:
  Updated positions
  (Needed because we didn't before correctly restore collation_database after running stored procedure
mysys/my_fopen.c:
  Count number of opened files
mysys/my_open.c:
  Count number of opened files
mysys/my_static.c:
  Count number of opened files
mysys/thr_alarm.c:
  Optimization to do less alarm() and pthread_sigmask() calls.
  Idea is to remember time for next pending alarm and not reschedule a new alarm if it's after the current one.
  Before we only did this if there was other pending alarms.
  We don't have to use pthread_sigmask() in case of 'USE_ONE_SIGNAL_HAND' as the alarm()
  signal will be blocked for the calling thread anyway and no other thread will have the alarm() signal enabled to call process_alarm()
regex/regcomp.c:
  Fixed compiler warning (on Forte) by adding casts and change types
scripts/mysql_install_db.sh:
  Added option --source-install to allow one to create a mysql database from the source tree without installing MySQL
  Don't give (unnecessary) warnings
server-tools/instance-manager/angel.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
server-tools/instance-manager/thread_registry.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/event_db_repository.cc:
  index_read() -> index_read_map()
sql/event_queue.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/field.cc:
  Fixed compiler warnings about hidden fields
sql/ha_partition.cc:
  Fixed compiler warnings about hidden fields
  index_read() -> index_read_map()
sql/ha_partition.h:
  index_read() -> index_read_map()
sql/handler.cc:
  Added PAGE option to row types (to prepare for future)
  index_read() -> index_read_map()
sql/handler.h:
  Added ROW_TYPE_PAGE (for future)
  Added flag to signal if table was to be created transactionally
  I had to do the following renames() as used polymorphism didn't work with Forte compiler on 64 bit systems
  index_read()      -> index_read_map()
  index_read_idx()  -> index_read_idx_map()
  index_read_last() -> index_read_last_map()
sql/item.cc:
  Fixed indentation
  Renamed local variable to avoid hiding class variable
sql/item_cmpfunc.cc:
  Renamed local variable to avoid hiding class variable
sql/item_cmpfunc.h:
  Removed not used variable
sql/item_func.cc:
  Renamed local variable to avoid hiding class variable
sql/item_strfunc.cc:
  Moved functions from Item_strfunc.cc
sql/item_strfunc.h:
  Move functions to item_strfunc.cc
  Use C function pointer type to avoid compiler warnings (with Forte)
sql/item_subselect.cc:
  index_read() -> index_read_map()
sql/item_xmlfunc.cc:
  Renamed local variable to avoid hiding class variable
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/key.cc:
  Fixed indentation
sql/log.cc:
  Renamed local variable to avoid hiding class variable
sql/log_event.cc:
  Removed call to my_time() when creating class instance of Log_event() as this may have static instances.
  (One can't call my_time() before my_init())
  index_read() -> index_read_map()
  Renamed local variable to avoid hiding class variable
sql/log_event_old.cc:
  Renamed local variable to avoid hiding class variable
sql/mysql_priv.h:
  Made all create_backup_ctx() declarations identical.
  This lifted up a bug where wrong create_backup_ctx() was called in some cases.
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/mysqld.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
  Fixed indentation
  Don't call end_thr_alarm() when calling unireg_abort() as unireg_abort() already calls end_thr_alarm()
  Added variable 'Opened_files' (number of calls to my_open() or my_fopen())
  Don't print 'loose' warnings when using --bootstrap (to avoid warnings when running mysql_install_db)
  Fixed compiler warnings
sql/opt_range.cc:
  index_read() -> index_read_map()
sql/opt_sum.cc:
  index_read() -> index_read_map()
sql/partition_info.cc:
  Renamed local variable to avoid hiding class variable
sql/rpl_filter.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/set_var.cc:
  Renamed local variable to avoid hiding class variable
  Added 'process_key_cache_t' type to avoid compiler warning (on Forte)
sql/set_var.h:
  Added 'process_key_cache_t' type to avoid compiler warning (on Forte)
sql/sp.cc:
  More debugging
  index_read() -> index_read_map()
sql/sp_cache.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/sp_head.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
  Moved 'saved_creation_ctx' higher up to be able to free objects allocated by create_backup_ctx()
sql/sql_acl.cc:
  index_read() -> index_read_map()
sql/sql_class.cc:
  Renamed local variable to avoid hiding class variable
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/sql_class.h:
  Renamed local variable to avoid hiding class variable
sql/sql_db.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
sql/sql_delete.cc:
  Renamed local variable to avoid hiding class variable
sql/sql_handler.cc:
  index_read() -> index_read_map()
sql/sql_help.cc:
  index_read() -> index_read_map()
sql/sql_insert.cc:
  index_read() -> index_read_map()
  Renamed local variable to avoid hiding class variable
sql/sql_lex.cc:
  Renamed local variable to avoid hiding class variable
sql/sql_plugin.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
  index_read() -> index_read_map()
  Don't give warnings about not used plugins if we are using --warnings=0
sql/sql_select.cc:
  index_read() -> index_read_map()
sql-common/client.c:
  Fixed compiler warning (on Forte)
sql-common/my_time.c:
  Removed never accessed code
  Fixed compiler warning (on Forte)
sql/sql_servers.cc:
  index_read() -> index_read_map()
sql/sql_show.cc:
  Added TRANSACTIONAL to SHOW CREATE
  Fixed ROW_TYPE_PAGE
sql/sql_string.cc:
  Avoid compiler warnings when using C function pointers in C++
sql/sql_table.cc:
  Set create_info->transactional if we used TRANSACTIONAL=1
sql/sql_udf.cc:
  index_read() -> index_read_map()
sql/sql_yacc.yy:
  Added TRANSACTIONAL=0|1 to CREATE (for future)
  Added row type PAGE (was only partionally handled before)
sql/strfunc.cc:
  Avoid compiler warnings when using C function pointers in C++
sql/table.cc:
  More DBUG statements
  Declare all create_backup_ctx() functions identically
  Remember if table was created with TRANSACTIONAL flag or not (future safe)
  Renamed local variable to avoid hiding class variable
sql/table.h:
  Remember if table was created with TRANSACTIONAL=1
sql/tztime.cc:
  index_read() -> index_read_map()
sql-common/pack.c:
  Fixed compiler warning (on Forte)
storage/archive/archive_reader.c:
  Fixed compiler warning (on Forte)
storage/archive/azio.c:
  Fixed compiler warning (on Forte)
storage/blackhole/ha_blackhole.cc:
  index_read() -> index_read_map()
storage/blackhole/ha_blackhole.h:
  index_read() -> index_read_map()
storage/csv/ha_tina.cc:
  Declare functions sent to C code with extern "C" to avoid compiler warnings (on Forte)
storage/example/ha_example.cc:
  index_read() -> index_read_map()
storage/example/ha_example.h:
  index_read() -> index_read_map()
storage/heap/ha_heap.cc:
  index_read() -> index_read_map()
storage/heap/ha_heap.h:
  index_read() -> index_read_map()
storage/heap/hp_test1.c:
  Fixed compiler warning (on Forte)
storage/heap/hp_test2.c:
  Fixed compiler warning (on Forte)
storage/myisam/ft_boolean_search.c:
  Fixed compiler warning (on Forte)
storage/myisam/ft_nlq_search.c:
  Fixed compiler warning (on Forte)
storage/myisam/ft_parser.c:
  Fixed compiler warning (on Forte)
storage/myisam/ft_stopwords.c:
  Fixed compiler warning (on Forte)
storage/myisam/ha_myisam.cc:
  index_read() -> index_read_map()
storage/myisam/ha_myisam.h:
  index_read() -> index_read_map()
storage/myisam/mi_check.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_delete.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_dynrec.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_extra.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_key.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_keycache.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_locking.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_log.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_open.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_packrec.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_page.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_rkey.c:
  Added comment
storage/myisam/mi_search.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_statrec.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_test1.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_test2.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_test3.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_update.c:
  Fixed compiler warning (on Forte)
storage/myisam/mi_write.c:
  Fixed compiler warning (on Forte)
storage/myisam/myisamdef.h:
  Fixed that file_read/file_write returns type size_t
  Changed some functions to use uchar * as argument/return value instead of char*
  This fixed some compiler warnings on Forte
storage/myisam/myisamlog.c:
  Fixed compiler warning (on Forte)
storage/myisam/myisampack.c:
  Fixed compiler warning (on Forte)
storage/myisam/rt_test.c:
  Fixed compiler warning (on Forte)
storage/myisam/sort.c:
  Fixed compiler warning (on Forte) by adding casts or changing variables to uchar*
storage/myisam/sp_test.c:
  Fixed compiler warning (on Forte) by adding casts or changing variables to uchar*
storage/myisammrg/ha_myisammrg.cc:
  index_read() -> index_read_map()
storage/myisammrg/ha_myisammrg.h:
  index_read() -> index_read_map()
storage/myisammrg/myrg_create.c:
  Fixed compiler warning (on Forte) by adding casts or changing variable types
storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp:
  Tdummy -> align  (as in other part of cluster code)
storage/ndb/src/kernel/vm/DynArr256.cpp:
  Removed not used variable
storage/ndb/src/ndbapi/Ndb.cpp:
  Removed not used variable
strings/strtod.c:
  Include ieeefp.h to avoid compiler warning
tests/bug25714.c:
  Fixed compiler warning
tests/mysql_client_test.c:
  Remove not used variable
  Fixed indentation
  Removed never reached code
  Fixed compiler warning (on Forte) by adding casts or changing variable types
vio/viosocket.c:
  Fixed compiler warning (on Forte) by adding casts or changing variable types
2007-08-13 16:11:25 +03:00

696 lines
18 KiB
C

/* Copyright (C) 2000-2003, 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Test av isam-databas: stor test */
#ifndef USE_MY_FUNC /* We want to be able to dbug this !! */
#define USE_MY_FUNC
#endif
#ifdef DBUG_OFF
#undef DBUG_OFF
#endif
#ifndef SAFEMALLOC
#define SAFEMALLOC
#endif
#include "heapdef.h" /* Because of hp_find_block */
#include <signal.h>
#define MAX_RECORDS 100000
#define MAX_KEYS 4
static int get_options(int argc, char *argv[]);
static int rnd(int max_value);
static sig_handler endprog(int sig_number);
static uint flag=0,verbose=0,testflag=0,recant=10000,silent=0;
static uint keys=MAX_KEYS;
static uint16 key1[1001];
static my_bool key3[MAX_RECORDS];
static int reclength=39;
static int calc_check(uchar *buf,uint length);
static void make_record(uchar *record, uint n1, uint n2, uint n3,
const char *mark, uint count);
/* Main program */
int main(int argc, char *argv[])
{
register uint i,j;
uint ant,n1,n2,n3;
uint write_count,update,opt_delete,check2,dupp_keys,found_key;
int error;
ulong pos;
unsigned long key_check;
uchar record[128],record2[128],record3[128],key[10];
const char *filename,*filename2;
HP_INFO *file,*file2;
HP_SHARE *tmp_share;
HP_KEYDEF keyinfo[MAX_KEYS];
HA_KEYSEG keyseg[MAX_KEYS*5];
HEAP_PTR position;
HP_CREATE_INFO hp_create_info;
CHARSET_INFO *cs= &my_charset_latin1;
MY_INIT(argv[0]); /* init my_sys library & pthreads */
LINT_INIT(position);
filename= "test2";
filename2= "test2_2";
file=file2=0;
get_options(argc,argv);
bzero(&hp_create_info, sizeof(hp_create_info));
hp_create_info.max_table_size= 1024L*1024L;
write_count=update=opt_delete=0;
key_check=0;
keyinfo[0].seg=keyseg;
keyinfo[0].keysegs=1;
keyinfo[0].flag= 0;
keyinfo[0].algorithm= HA_KEY_ALG_HASH;
keyinfo[0].seg[0].type=HA_KEYTYPE_BINARY;
keyinfo[0].seg[0].start=0;
keyinfo[0].seg[0].length=6;
keyinfo[0].seg[0].null_bit=0;
keyinfo[0].seg[0].charset=cs;
keyinfo[1].seg=keyseg+1;
keyinfo[1].keysegs=2;
keyinfo[1].flag=0;
keyinfo[1].algorithm= HA_KEY_ALG_HASH;
keyinfo[1].seg[0].type=HA_KEYTYPE_BINARY;
keyinfo[1].seg[0].start=7;
keyinfo[1].seg[0].length=6;
keyinfo[1].seg[0].null_bit=0;
keyinfo[1].seg[0].charset=cs;
keyinfo[1].seg[1].type=HA_KEYTYPE_TEXT;
keyinfo[1].seg[1].start=0; /* key in two parts */
keyinfo[1].seg[1].length=6;
keyinfo[1].seg[1].null_bit=0;
keyinfo[1].seg[1].charset=cs;
keyinfo[2].seg=keyseg+3;
keyinfo[2].keysegs=1;
keyinfo[2].flag=HA_NOSAME;
keyinfo[2].algorithm= HA_KEY_ALG_HASH;
keyinfo[2].seg[0].type=HA_KEYTYPE_BINARY;
keyinfo[2].seg[0].start=12;
keyinfo[2].seg[0].length=8;
keyinfo[2].seg[0].null_bit=0;
keyinfo[2].seg[0].charset=cs;
keyinfo[3].seg=keyseg+4;
keyinfo[3].keysegs=1;
keyinfo[3].flag=HA_NOSAME;
keyinfo[3].algorithm= HA_KEY_ALG_HASH;
keyinfo[3].seg[0].type=HA_KEYTYPE_BINARY;
keyinfo[3].seg[0].start=37;
keyinfo[3].seg[0].length=1;
keyinfo[3].seg[0].null_bit=1;
keyinfo[3].seg[0].null_pos=38;
keyinfo[3].seg[0].charset=cs;
bzero((char*) key1,sizeof(key1));
bzero((char*) key3,sizeof(key3));
printf("- Creating heap-file\n");
if (heap_create(filename,keys,keyinfo,reclength,(ulong) flag*100000L,
(ulong) recant/2, &hp_create_info, &tmp_share) ||
!(file= heap_open(filename, 2)))
goto err;
signal(SIGINT,endprog);
printf("- Writing records:s\n");
strmov((char*) record," ..... key");
for (i=0 ; i < recant ; i++)
{
n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
make_record(record,n1,n2,n3,"Pos",write_count);
if (heap_write(file,record))
{
if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
{
printf("Error: %d in write at record: %d\n",my_errno,i);
goto err;
}
if (verbose) printf(" Double key: %d\n",n3);
}
else
{
if (key3[n3] == 1)
{
printf("Error: Didn't get error when writing second key: '%8d'\n",n3);
goto err;
}
write_count++; key1[n1]++; key3[n3]=1;
key_check+=n1;
}
if (testflag == 1 && heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
}
if (testflag == 1)
goto end;
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
printf("- Delete\n");
for (i=0 ; i < write_count/10 ; i++)
{
for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
if (j != 0)
{
sprintf((char*) key,"%6d",j);
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
{
printf("can't find key1: \"%s\"\n",(char*) key);
goto err;
}
#ifdef NOT_USED
if (file->current_ptr == hp_find_block(&file->s->block,0) ||
file->current_ptr == hp_find_block(&file->s->block,1))
continue; /* Don't remove 2 first records */
#endif
if (heap_delete(file,record))
{
printf("error: %d; can't delete record: \"%s\"\n", my_errno,(char*) record);
goto err;
}
opt_delete++;
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
key_check-=atoi((char*) record);
if (testflag == 2 && heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
}
else
puts("Warning: Skipping delete test because no dupplicate keys");
}
if (testflag==2) goto end;
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
printf("- Update\n");
for (i=0 ; i < write_count/10 ; i++)
{
n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
make_record(record2, n1, n2, n3, "XXX", update);
if (rnd(2) == 1)
{
if (heap_scan_init(file))
goto err;
j=rnd(write_count-opt_delete);
while ((error=heap_scan(file,record) == HA_ERR_RECORD_DELETED) ||
(!error && j))
{
if (!error)
j--;
}
if (error)
goto err;
}
else
{
for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
if (!key1[j])
continue;
sprintf((char*) key,"%6d",j);
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
{
printf("can't find key1: \"%s\"\n",(char*) key);
goto err;
}
}
if (heap_update(file,record,record2))
{
if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
{
printf("error: %d; can't update:\nFrom: \"%s\"\nTo: \"%s\"\n",
my_errno,(char*) record, (char*) record2);
goto err;
}
if (verbose)
printf("Double key when tried to update:\nFrom: \"%s\"\nTo: \"%s\"\n",
(char*) record, (char*) record2);
}
else
{
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
key1[n1]++; key3[n3]=1;
update++;
key_check=key_check-atoi((char*) record)+n1;
}
if (testflag == 3 && heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
}
if (testflag == 3) goto end;
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
for (i=999, dupp_keys=found_key=0 ; i>0 ; i--)
{
if (key1[i] > dupp_keys) { dupp_keys=key1[i]; found_key=i; }
sprintf((char*) key,"%6d",found_key);
}
if (dupp_keys > 3)
{
if (!silent)
printf("- Read first key - next - delete - next -> last\n");
DBUG_PRINT("progpos",("first - next - delete - next -> last"));
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
goto err;
if (heap_rnext(file,record3)) goto err;
if (heap_delete(file,record3)) goto err;
key_check-=atoi((char*) record3);
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
opt_delete++;
ant=2;
while ((error=heap_rnext(file,record3)) == 0 ||
error == HA_ERR_RECORD_DELETED)
if (! error)
ant++;
if (ant != dupp_keys)
{
printf("next: I can only find: %d records of %d\n",
ant,dupp_keys);
goto end;
}
dupp_keys--;
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
if (!silent)
printf("- Read last key - delete - prev - prev - opt_delete - prev -> first\n");
if (heap_rlast(file,record3,0)) goto err;
if (heap_delete(file,record3)) goto err;
key_check-=atoi((char*) record3);
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
opt_delete++;
if (heap_rprev(file,record3) || heap_rprev(file,record3))
goto err;
if (heap_delete(file,record3)) goto err;
key_check-=atoi((char*) record3);
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
opt_delete++;
ant=3;
while ((error=heap_rprev(file,record3)) == 0 ||
error == HA_ERR_RECORD_DELETED)
{
if (! error)
ant++;
}
if (ant != dupp_keys)
{
printf("next: I can only find: %d records of %d\n",
ant,dupp_keys);
goto end;
}
dupp_keys-=2;
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
}
else
puts("Warning: Not enough duplicated keys: Skipping delete key check");
if (!silent)
printf("- Read (first) - next - delete - next -> last\n");
DBUG_PRINT("progpos",("first - next - delete - next -> last"));
if (heap_scan_init(file))
goto err;
while ((error=heap_scan(file,record3) == HA_ERR_RECORD_DELETED)) ;
if (error)
goto err;
if (heap_delete(file,record3)) goto err;
key_check-=atoi((char*) record3);
opt_delete++;
key1[atoi((char*) record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) record+keyinfo[2].seg[0].start)]=0;
ant=0;
while ((error=heap_scan(file,record3)) == 0 ||
error == HA_ERR_RECORD_DELETED)
if (! error)
ant++;
if (ant != write_count-opt_delete)
{
printf("next: Found: %d records of %d\n",ant,write_count-opt_delete);
goto end;
}
if (heap_check_heap(file,0))
{
puts("Heap keys crashed");
goto err;
}
puts("- Test if: Read rrnd - same - rkey - same");
DBUG_PRINT("progpos",("Read rrnd - same"));
pos=rnd(write_count-opt_delete-5)+5;
heap_scan_init(file);
i=5;
while ((error=heap_scan(file,record)) == HA_ERR_RECORD_DELETED ||
(error == 0 && pos))
{
if (!error)
pos--;
if (i-- == 0)
{
bmove(record3,record,reclength);
position=heap_position(file);
}
}
if (error)
goto err;
bmove(record2,record,reclength);
if (heap_rsame(file,record,-1) || heap_rsame(file,record2,2))
goto err;
if (bcmp(record2,record,reclength))
{
puts("heap_rsame didn't find right record");
goto end;
}
puts("- Test of read through position");
if (heap_rrnd(file,record,position))
goto err;
if (bcmp(record3,record,reclength))
{
puts("heap_frnd didn't find right record");
goto end;
}
printf("- heap_info\n");
{
HEAPINFO info;
heap_info(file,&info,0);
/* We have to test with opt_delete +1 as this may be the case if the last
inserted row was a duplicate key */
if (info.records != write_count-opt_delete ||
(info.deleted != opt_delete && info.deleted != opt_delete+1))
{
puts("Wrong info from heap_info");
printf("Got: records: %ld(%d) deleted: %ld(%d)\n",
info.records,write_count-opt_delete,info.deleted,opt_delete);
}
}
#ifdef OLD_HEAP_VERSION
{
uint check;
printf("- Read through all records with rnd\n");
if (heap_extra(file,HA_EXTRA_RESET) || heap_extra(file,HA_EXTRA_CACHE))
{
puts("got error from heap_extra");
goto end;
}
ant=check=0;
while ((error=heap_rrnd(file,record,(ulong) -1)) != HA_ERR_END_OF_FILE &&
ant < write_count + 10)
{
if (!error)
{
ant++;
check+=calc_check(record,reclength);
}
}
if (ant != write_count-opt_delete)
{
printf("rrnd: I can only find: %d records of %d\n", ant,
write_count-opt_delete);
goto end;
}
if (heap_extra(file,HA_EXTRA_NO_CACHE))
{
puts("got error from heap_extra(HA_EXTRA_NO_CACHE)");
goto end;
}
}
#endif
printf("- Read through all records with scan\n");
if (heap_reset(file) || heap_extra(file,HA_EXTRA_CACHE))
{
puts("got error from heap_extra");
goto end;
}
ant=check2=0;
heap_scan_init(file);
while ((error=heap_scan(file,record)) != HA_ERR_END_OF_FILE &&
ant < write_count + 10)
{
if (!error)
{
ant++;
check2+=calc_check(record,reclength);
}
}
if (ant != write_count-opt_delete)
{
printf("scan: I can only find: %d records of %d\n", ant,
write_count-opt_delete);
goto end;
}
#ifdef OLD_HEAP_VERSION
if (check != check2)
{
puts("scan: Checksum didn't match reading with rrnd");
goto end;
}
#endif
if (heap_extra(file,HA_EXTRA_NO_CACHE))
{
puts("got error from heap_extra(HA_EXTRA_NO_CACHE)");
goto end;
}
for (i=999, dupp_keys=found_key=0 ; i>0 ; i--)
{
if (key1[i] > dupp_keys) { dupp_keys=key1[i]; found_key=i; }
sprintf((char*) key,"%6d",found_key);
}
printf("- Read through all keys with first-next-last-prev\n");
ant=0;
for (error=heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT);
! error ;
error=heap_rnext(file,record))
ant++;
if (ant != dupp_keys)
{
printf("first-next: I can only find: %d records of %d\n", ant,
dupp_keys);
goto end;
}
ant=0;
for (error=heap_rlast(file,record,0) ;
! error ;
error=heap_rprev(file,record))
{
ant++;
check2+=calc_check(record,reclength);
}
if (ant != dupp_keys)
{
printf("last-prev: I can only find: %d records of %d\n", ant,
dupp_keys);
goto end;
}
if (testflag == 4) goto end;
printf("- Reading through all rows through keys\n");
if (!(file2=heap_open(filename, 2)))
goto err;
if (heap_scan_init(file))
goto err;
while ((error=heap_scan(file,record)) != HA_ERR_END_OF_FILE)
{
if (error == 0)
{
if (heap_rkey(file2,record2,2,record+keyinfo[2].seg[0].start,8,
HA_READ_KEY_EXACT))
{
printf("can't find key3: \"%.8s\"\n",
record+keyinfo[2].seg[0].start);
goto err;
}
}
}
heap_close(file2);
printf("- Creating output heap-file 2\n");
if (heap_create(filename2, 1, keyinfo, reclength, 0L, 0L, &hp_create_info,
&tmp_share) ||
!(file2= heap_open_from_share_and_register(tmp_share, 2)))
goto err;
printf("- Copying and removing records\n");
if (heap_scan_init(file))
goto err;
while ((error=heap_scan(file,record)) != HA_ERR_END_OF_FILE)
{
if (error == 0)
{
if (heap_write(file2,record))
goto err;
key_check-=atoi((char*) record);
write_count++;
if (heap_delete(file,record))
goto err;
opt_delete++;
}
pos++;
}
printf("- Checking heap tables\n");
if (heap_check_heap(file,1) || heap_check_heap(file2,1))
{
puts("Heap keys crashed");
goto err;
}
if (my_errno != HA_ERR_END_OF_FILE)
printf("error: %d from heap_rrnd\n",my_errno);
if (key_check)
printf("error: Some read got wrong: check is %ld\n",(long) key_check);
end:
printf("\nFollowing test have been made:\n");
printf("Write records: %d\nUpdate records: %d\nDelete records: %d\n", write_count,update,opt_delete);
heap_clear(file);
if (heap_close(file) || (file2 && heap_close(file2)))
goto err;
heap_delete_table(filename2);
hp_panic(HA_PANIC_CLOSE);
my_end(MY_GIVE_INFO);
return(0);
err:
printf("Got error: %d when using heap-database\n",my_errno);
VOID(heap_close(file));
return(1);
} /* main */
/* Read options */
static int get_options(int argc,char *argv[])
{
char *pos,*progname;
progname= argv[0];
while (--argc >0 && *(pos = *(++argv)) == '-' ) {
switch(*++pos) {
case 'B': /* Big file */
flag=1;
break;
case 'v': /* verbose */
verbose=1;
break;
case 'm': /* records */
recant=atoi(++pos);
break;
case 's':
silent=1;
break;
case 't':
testflag=atoi(++pos); /* testmod */
break;
case 'V':
case 'I':
case '?':
printf("%s Ver 1.1 for %s at %s\n",progname,SYSTEM_TYPE,MACHINE_TYPE);
puts("TCX Datakonsult AB, by Monty, for your professional use\n");
printf("Usage: %s [-?ABIKLsWv] [-m#] [-t#]\n",progname);
exit(0);
case '#':
DBUG_PUSH (++pos);
break;
}
}
return 0;
} /* get options */
/* Generate a random value in intervall 0 <=x <= n */
static int rnd(int max_value)
{
return (int) ((rand() & 32767)/32767.0*max_value);
} /* rnd */
static sig_handler endprog(int sig_number __attribute__((unused)))
{
#ifndef THREAD
if (my_dont_interrupt)
my_remember_signal(sig_number,endprog);
else
#endif
{
hp_panic(HA_PANIC_CLOSE);
my_end(1);
exit(1);
}
}
static int calc_check(uchar *buf, uint length)
{
int check=0;
while (length--)
check+= (int) (uchar) *(buf++);
return check;
}
static void make_record(uchar *record, uint n1, uint n2, uint n3,
const char *mark, uint count)
{
bfill(record,reclength,' ');
sprintf((char*) record,"%6d:%4d:%8d:%3.3s: %4d",
n1,n2,n3,mark,count);
record[37]='A'; /* Store A in null key */
record[38]=1; /* set as null */
}