mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
09a53f28a7
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
501 lines
11 KiB
C
501 lines
11 KiB
C
/* Copyright (C) 2000-2004 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 locking */
|
|
|
|
#ifndef __NETWARE__
|
|
|
|
#include "myisam.h"
|
|
#include <sys/types.h>
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
# include <sys/wait.h>
|
|
#endif
|
|
#ifndef WEXITSTATUS
|
|
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
|
#endif
|
|
#ifndef WIFEXITED
|
|
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
|
#endif
|
|
|
|
|
|
#if defined(HAVE_LRAND48)
|
|
#define rnd(X) (lrand48() % X)
|
|
#define rnd_init(X) srand48(X)
|
|
#else
|
|
#define rnd(X) (random() % X)
|
|
#define rnd_init(X) srandom(X)
|
|
#endif
|
|
|
|
|
|
const char *filename= "test3";
|
|
uint tests=10,forks=10,key_cacheing=0,use_log=0;
|
|
|
|
static void get_options(int argc, char *argv[]);
|
|
void start_test(int id);
|
|
int test_read(MI_INFO *,int),test_write(MI_INFO *,int,int),
|
|
test_update(MI_INFO *,int,int),test_rrnd(MI_INFO *,int);
|
|
|
|
struct record {
|
|
uchar id[8];
|
|
uchar nr[4];
|
|
uchar text[10];
|
|
} record;
|
|
|
|
|
|
int main(int argc,char **argv)
|
|
{
|
|
int status,wait_ret;
|
|
uint i=0;
|
|
MI_KEYDEF keyinfo[10];
|
|
MI_COLUMNDEF recinfo[10];
|
|
HA_KEYSEG keyseg[10][2];
|
|
MY_INIT(argv[0]);
|
|
get_options(argc,argv);
|
|
|
|
bzero((char*) keyinfo,sizeof(keyinfo));
|
|
bzero((char*) recinfo,sizeof(recinfo));
|
|
bzero((char*) keyseg,sizeof(keyseg));
|
|
keyinfo[0].seg= &keyseg[0][0];
|
|
keyinfo[0].seg[0].start=0;
|
|
keyinfo[0].seg[0].length=8;
|
|
keyinfo[0].seg[0].type=HA_KEYTYPE_TEXT;
|
|
keyinfo[0].seg[0].flag=HA_SPACE_PACK;
|
|
keyinfo[0].key_alg=HA_KEY_ALG_BTREE;
|
|
keyinfo[0].keysegs=1;
|
|
keyinfo[0].flag = (uint8) HA_PACK_KEY;
|
|
keyinfo[0].block_length= 0; /* Default block length */
|
|
keyinfo[1].seg= &keyseg[1][0];
|
|
keyinfo[1].seg[0].start=8;
|
|
keyinfo[1].seg[0].length=4; /* Long is always 4 in myisam */
|
|
keyinfo[1].seg[0].type=HA_KEYTYPE_LONG_INT;
|
|
keyinfo[1].seg[0].flag=0;
|
|
keyinfo[1].key_alg=HA_KEY_ALG_BTREE;
|
|
keyinfo[1].keysegs=1;
|
|
keyinfo[1].flag =HA_NOSAME;
|
|
keyinfo[1].block_length= 0; /* Default block length */
|
|
|
|
recinfo[0].type=0;
|
|
recinfo[0].length=sizeof(record.id);
|
|
recinfo[1].type=0;
|
|
recinfo[1].length=sizeof(record.nr);
|
|
recinfo[2].type=0;
|
|
recinfo[2].length=sizeof(record.text);
|
|
|
|
puts("- Creating myisam-file");
|
|
my_delete(filename,MYF(0)); /* Remove old locks under gdb */
|
|
if (mi_create(filename,2,&keyinfo[0],2,&recinfo[0],0,(MI_UNIQUEDEF*) 0,
|
|
(MI_CREATE_INFO*) 0,0))
|
|
exit(1);
|
|
|
|
rnd_init(0);
|
|
printf("- Starting %d processes\n",forks); fflush(stdout);
|
|
for (i=0 ; i < forks; i++)
|
|
{
|
|
if (!fork())
|
|
{
|
|
start_test(i+1);
|
|
sleep(1);
|
|
return 0;
|
|
}
|
|
VOID(rnd(1));
|
|
}
|
|
|
|
for (i=0 ; i < forks ; i++)
|
|
while ((wait_ret=wait(&status)) && wait_ret == -1);
|
|
return 0;
|
|
}
|
|
|
|
|
|
static void get_options(int argc, char **argv)
|
|
{
|
|
char *pos,*progname;
|
|
|
|
progname= argv[0];
|
|
|
|
while (--argc >0 && *(pos = *(++argv)) == '-' ) {
|
|
switch(*++pos) {
|
|
case 'l':
|
|
use_log=1;
|
|
break;
|
|
case 'f':
|
|
forks=atoi(++pos);
|
|
break;
|
|
case 't':
|
|
tests=atoi(++pos);
|
|
break;
|
|
case 'K': /* Use key cacheing */
|
|
key_cacheing=1;
|
|
break;
|
|
case 'A': /* All flags */
|
|
use_log=key_cacheing=1;
|
|
break;
|
|
case '?':
|
|
case 'I':
|
|
case 'V':
|
|
printf("%s Ver 1.0 for %s at %s\n",progname,SYSTEM_TYPE,MACHINE_TYPE);
|
|
puts("By Monty, for your professional use\n");
|
|
puts("Test av locking with threads\n");
|
|
printf("Usage: %s [-?lKA] [-f#] [-t#]\n",progname);
|
|
exit(0);
|
|
case '#':
|
|
DBUG_PUSH (++pos);
|
|
break;
|
|
default:
|
|
printf("Illegal option: '%c'\n",*pos);
|
|
break;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
void start_test(int id)
|
|
{
|
|
uint i;
|
|
int error,lock_type;
|
|
MI_ISAMINFO isam_info;
|
|
MI_INFO *file,*file1,*file2=0,*lock;
|
|
|
|
if (use_log)
|
|
mi_log(1);
|
|
if (!(file1=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)) ||
|
|
!(file2=mi_open(filename,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)))
|
|
{
|
|
fprintf(stderr,"Can't open isam-file: %s\n",filename);
|
|
exit(1);
|
|
}
|
|
if (key_cacheing && rnd(2) == 0)
|
|
init_key_cache(dflt_key_cache, KEY_CACHE_BLOCK_SIZE, 65536L, 0, 0);
|
|
printf("Process %d, pid: %d\n",id,getpid()); fflush(stdout);
|
|
|
|
for (error=i=0 ; i < tests && !error; i++)
|
|
{
|
|
file= (rnd(2) == 1) ? file1 : file2;
|
|
lock=0 ; lock_type=0;
|
|
if (rnd(10) == 0)
|
|
{
|
|
if (mi_lock_database(lock=(rnd(2) ? file1 : file2),
|
|
lock_type=(rnd(2) == 0 ? F_RDLCK : F_WRLCK)))
|
|
{
|
|
fprintf(stderr,"%2d: start: Can't lock table %d\n",id,my_errno);
|
|
error=1;
|
|
break;
|
|
}
|
|
}
|
|
switch (rnd(4)) {
|
|
case 0: error=test_read(file,id); break;
|
|
case 1: error=test_rrnd(file,id); break;
|
|
case 2: error=test_write(file,id,lock_type); break;
|
|
case 3: error=test_update(file,id,lock_type); break;
|
|
}
|
|
if (lock)
|
|
mi_lock_database(lock,F_UNLCK);
|
|
}
|
|
if (!error)
|
|
{
|
|
mi_status(file1,&isam_info,HA_STATUS_VARIABLE);
|
|
printf("%2d: End of test. Records: %ld Deleted: %ld\n",
|
|
id,(long) isam_info.records, (long) isam_info.deleted);
|
|
fflush(stdout);
|
|
}
|
|
|
|
mi_close(file1);
|
|
mi_close(file2);
|
|
if (use_log)
|
|
mi_log(0);
|
|
if (error)
|
|
{
|
|
printf("%2d: Aborted\n",id); fflush(stdout);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
int test_read(MI_INFO *file,int id)
|
|
{
|
|
uint i,lock,found,next,prev;
|
|
ulong find;
|
|
|
|
lock=0;
|
|
if (rnd(2) == 0)
|
|
{
|
|
lock=1;
|
|
if (mi_lock_database(file,F_RDLCK))
|
|
{
|
|
fprintf(stderr,"%2d: Can't lock table %d\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
found=next=prev=0;
|
|
for (i=0 ; i < 100 ; i++)
|
|
{
|
|
find=rnd(100000);
|
|
if (!mi_rkey(file,record.id,1,(uchar*) &find, HA_WHOLE_KEY,
|
|
HA_READ_KEY_EXACT))
|
|
found++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_KEY_NOT_FOUND)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from read in read\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
else if (!mi_rnext(file,record.id,1))
|
|
next++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_END_OF_FILE)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from rnext in read\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
else if (!mi_rprev(file,record.id,1))
|
|
prev++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_END_OF_FILE)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from rnext in read\n",
|
|
id,my_errno);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (lock)
|
|
{
|
|
if (mi_lock_database(file,F_UNLCK))
|
|
{
|
|
fprintf(stderr,"%2d: Can't unlock table\n",id);
|
|
return 1;
|
|
}
|
|
}
|
|
printf("%2d: read: found: %5d next: %5d prev: %5d\n",
|
|
id,found,next,prev);
|
|
fflush(stdout);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int test_rrnd(MI_INFO *file,int id)
|
|
{
|
|
uint count,lock;
|
|
|
|
lock=0;
|
|
if (rnd(2) == 0)
|
|
{
|
|
lock=1;
|
|
if (mi_lock_database(file,F_RDLCK))
|
|
{
|
|
fprintf(stderr,"%2d: Can't lock table (%d)\n",id,my_errno);
|
|
mi_close(file);
|
|
return 1;
|
|
}
|
|
if (rnd(2) == 0)
|
|
mi_extra(file,HA_EXTRA_CACHE,0);
|
|
}
|
|
|
|
count=0;
|
|
if (mi_rrnd(file,record.id,0L))
|
|
{
|
|
if (my_errno == HA_ERR_END_OF_FILE)
|
|
goto end;
|
|
fprintf(stderr,"%2d: Can't read first record (%d)\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
for (count=1 ; !mi_rrnd(file,record.id,HA_OFFSET_ERROR) ;count++) ;
|
|
if (my_errno != HA_ERR_END_OF_FILE)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from rrnd\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
|
|
end:
|
|
if (lock)
|
|
{
|
|
mi_extra(file,HA_EXTRA_NO_CACHE,0);
|
|
if (mi_lock_database(file,F_UNLCK))
|
|
{
|
|
fprintf(stderr,"%2d: Can't unlock table\n",id);
|
|
exit(0);
|
|
}
|
|
}
|
|
printf("%2d: rrnd: %5d\n",id,count); fflush(stdout);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int test_write(MI_INFO *file,int id,int lock_type)
|
|
{
|
|
uint i,tries,count,lock;
|
|
|
|
lock=0;
|
|
if (rnd(2) == 0 || lock_type == F_RDLCK)
|
|
{
|
|
lock=1;
|
|
if (mi_lock_database(file,F_WRLCK))
|
|
{
|
|
if (lock_type == F_RDLCK && my_errno == EDEADLK)
|
|
{
|
|
printf("%2d: write: deadlock\n",id); fflush(stdout);
|
|
return 0;
|
|
}
|
|
fprintf(stderr,"%2d: Can't lock table (%d)\n",id,my_errno);
|
|
mi_close(file);
|
|
return 1;
|
|
}
|
|
if (rnd(2) == 0)
|
|
mi_extra(file,HA_EXTRA_WRITE_CACHE,0);
|
|
}
|
|
|
|
sprintf((char*) record.id,"%7d",getpid());
|
|
strnmov((char*) record.text,"Testing...", sizeof(record.text));
|
|
|
|
tries=(uint) rnd(100)+10;
|
|
for (i=count=0 ; i < tries ; i++)
|
|
{
|
|
uint32 tmp=rnd(80000)+20000;
|
|
int4store(record.nr,tmp);
|
|
if (!mi_write(file,record.id))
|
|
count++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_FOUND_DUPP_KEY)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d (errno %d) from write\n",id,my_errno,
|
|
errno);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
if (lock)
|
|
{
|
|
mi_extra(file,HA_EXTRA_NO_CACHE,0);
|
|
if (mi_lock_database(file,F_UNLCK))
|
|
{
|
|
fprintf(stderr,"%2d: Can't unlock table\n",id);
|
|
exit(0);
|
|
}
|
|
}
|
|
printf("%2d: write: %5d\n",id,count); fflush(stdout);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int test_update(MI_INFO *file,int id,int lock_type)
|
|
{
|
|
uint i,lock,found,next,prev,update;
|
|
uint32 tmp;
|
|
char find[4];
|
|
struct record new_record;
|
|
|
|
lock=0;
|
|
if (rnd(2) == 0 || lock_type == F_RDLCK)
|
|
{
|
|
lock=1;
|
|
if (mi_lock_database(file,F_WRLCK))
|
|
{
|
|
if (lock_type == F_RDLCK && my_errno == EDEADLK)
|
|
{
|
|
printf("%2d: write: deadlock\n",id); fflush(stdout);
|
|
return 0;
|
|
}
|
|
fprintf(stderr,"%2d: Can't lock table (%d)\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
}
|
|
bzero((char*) &new_record,sizeof(new_record));
|
|
strmov((char*) new_record.text,"Updated");
|
|
|
|
found=next=prev=update=0;
|
|
for (i=0 ; i < 100 ; i++)
|
|
{
|
|
tmp=rnd(100000);
|
|
int4store(find,tmp);
|
|
if (!mi_rkey(file,record.id,1,(uchar*) find, HA_WHOLE_KEY,
|
|
HA_READ_KEY_EXACT))
|
|
found++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_KEY_NOT_FOUND)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from read in update\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
else if (!mi_rnext(file,record.id,1))
|
|
next++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_END_OF_FILE)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from rnext in update\n",
|
|
id,my_errno);
|
|
return 1;
|
|
}
|
|
else if (!mi_rprev(file,record.id,1))
|
|
prev++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_END_OF_FILE)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from rnext in update\n",
|
|
id,my_errno);
|
|
return 1;
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
memcpy_fixed(new_record.id,record.id,sizeof(record.id));
|
|
tmp=rnd(20000)+40000;
|
|
int4store(new_record.nr,tmp);
|
|
if (!mi_update(file,record.id,new_record.id))
|
|
update++;
|
|
else
|
|
{
|
|
if (my_errno != HA_ERR_RECORD_CHANGED &&
|
|
my_errno != HA_ERR_RECORD_DELETED &&
|
|
my_errno != HA_ERR_FOUND_DUPP_KEY)
|
|
{
|
|
fprintf(stderr,"%2d: Got error %d from update\n",id,my_errno);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
if (lock)
|
|
{
|
|
if (mi_lock_database(file,F_UNLCK))
|
|
{
|
|
fprintf(stderr,"Can't unlock table,id, error%d\n",my_errno);
|
|
return 1;
|
|
}
|
|
}
|
|
printf("%2d: update: %5d\n",id,update); fflush(stdout);
|
|
return 0;
|
|
}
|
|
|
|
#else /* __NETWARE__ */
|
|
|
|
#include <stdio.h>
|
|
|
|
main()
|
|
{
|
|
fprintf(stderr,"this test has not been ported to NetWare\n");
|
|
return 0;
|
|
}
|
|
|
|
#endif /* __NETWARE__ */
|