diff options
Diffstat (limited to 'storage/myisam')
29 files changed, 524 insertions, 339 deletions
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 5c9cf0c55c3..58effb8cc00 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -118,7 +118,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, */ #ifdef THREAD if (param->need_print_msg_lock) - pthread_mutex_lock(¶m->print_msg_mutex); + mysql_mutex_lock(¶m->print_msg_mutex); #endif protocol->prepare_for_resend(); protocol->store(name, length, system_charset_info); @@ -130,7 +130,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, msgbuf); #ifdef THREAD if (param->need_print_msg_lock) - pthread_mutex_unlock(¶m->print_msg_mutex); + mysql_mutex_unlock(¶m->print_msg_mutex); #endif return; } @@ -762,13 +762,13 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) mi_is_crashed(file)) { file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | STATE_CRASHED_ON_REPAIR); if (!(table->db_stat & HA_READ_ONLY)) error=update_state_info(¶m,file,UPDATE_TIME | UPDATE_OPEN_COUNT | UPDATE_STAT); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | HA_STATUS_CONST); } @@ -812,9 +812,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) error = chk_key(¶m, file); if (!error) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); error=update_state_info(¶m,file,UPDATE_STAT); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } else if (!mi_is_crashed(file) && !thd->killed) mi_mark_crashed(file); @@ -1926,6 +1926,10 @@ static int myisam_init(void *p) { handlerton *myisam_hton; +#ifdef HAVE_PSI_INTERFACE + init_myisam_psi_keys(); +#endif + myisam_hton= (handlerton *)p; myisam_hton->state= SHOW_OPTION_YES; myisam_hton->db_type= DB_TYPE_MYISAM; diff --git a/storage/myisam/mi_cache.c b/storage/myisam/mi_cache.c index d6dcc431a8d..139a50a7c0d 100644 --- a/storage/myisam/mi_cache.c +++ b/storage/myisam/mi_cache.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -29,7 +29,7 @@ is set) - unread part is bzero'ed Note: out-of-cache reads are enabled for shared IO_CACHE's too, - as these reads will be cached by OS cache (and my_pread is always atomic) + as these reads will be cached by OS cache (and mysql_file_pread is always atomic) */ @@ -49,7 +49,7 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length, if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos)) read_length=(uint) (info->pos_in_file-pos); info->seek_not_done=1; - if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP))) + if (mysql_file_pread(info->file, buff, read_length, pos, MYF(MY_NABP))) DBUG_RETURN(1); if (!(length-=read_length)) DBUG_RETURN(0); @@ -88,7 +88,8 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length, else { info->seek_not_done=1; - if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length) + if ((read_length= mysql_file_pread(info->file, buff, length, pos, + MYF(0))) == length) DBUG_RETURN(0); } if (!(flag & READING_HEADER) || (int) read_length == -1 || diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 8ff803b58a0..8e55a7bc50e 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -53,8 +53,8 @@ #include "rt_index.h" #ifndef USE_RAID -#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G) -#define my_raid_delete(A,B,C) my_delete(A,B) +#define my_raid_create(K, A, B, C, D, E, F, G) mysql_file_create(K, A, B, C, G) +#define my_raid_delete(K, A, B, C) mysql_file_delete(K, A, B) #endif /* Functions defined in this file */ @@ -175,8 +175,8 @@ int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag) printf(" %9s",llstr(next_link,buff)); if (next_link >= info->state->data_file_length) goto wrong; - if (my_pread(info->dfile, (uchar*) buff,delete_link_length, - next_link,MYF(MY_NABP))) + if (mysql_file_pread(info->dfile, (uchar*) buff, delete_link_length, + next_link, MYF(MY_NABP))) { if (test_flag & T_VERBOSE) puts(""); mi_check_print_error(param,"Can't read delete-link at filepos: %s", @@ -338,7 +338,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) flush_key_blocks(info->s->key_cache, info->s->kfile, FLUSH_FORCE_WRITE); - size= my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); + size= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); if ((skr=(my_off_t) info->state->key_file_length) != size) { /* Don't give error if file generated by myisampack */ @@ -362,7 +362,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) llstr(info->state->key_file_length,buff), llstr(info->s->base.max_key_file_length-1,buff)); - size=my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); + size= mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)); skr=(my_off_t) info->state->data_file_length; if (info->s->options & HA_OPTION_COMPRESS_RECORD) skr+= MEMMAP_EXTRA_MARGIN; @@ -598,8 +598,8 @@ static int chk_index_down(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, { /* purecov: begin tested */ /* Give it a chance to fit in the real file size. */ - my_off_t max_length= my_seek(info->s->kfile, 0L, MY_SEEK_END, - MYF(MY_THREADSAFE)); + my_off_t max_length= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, + MYF(MY_THREADSAFE)); mi_check_print_error(param, "Invalid key block position: %s " "key block size: %u file_length: %s", llstr(page, llbuff), keyinfo->block_length, @@ -1577,14 +1577,15 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -1608,7 +1609,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, sort_param.pos=sort_param.max_pos=share->pack.header_length; sort_param.filepos=new_header_length; param->read_cache.end_of_file=sort_info.filelength= - my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)); sort_info.dupp=0; sort_param.fix_datafile= (my_bool) (! rep_quick); sort_param.master=1; @@ -1670,7 +1671,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, { (void) fputs(" \r",stdout); (void) fflush(stdout); } - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) { mi_check_print_warning(param, "Can't change size of indexfile, error: %d", @@ -1700,7 +1701,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; info->state->data_file_length=sort_param.filepos; share->state.version=(ulong) time((time_t*) 0); /* Force reopen */ @@ -1733,7 +1734,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -1750,9 +1751,10 @@ err: llstr(sort_param.start_recpos,llbuff)); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,info->s->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, info->s->base.raid_chunks, + MYF(MY_WME)); info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */ } mi_mark_crashed_on_repair(info); @@ -1949,9 +1951,11 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) /* Get real path for index file */ fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32); - if ((new_file=my_create(fn_format(param->temp_filename,param->temp_filename, - "", INDEX_TMP_EXT,2+4), - 0,param->tmpfile_createflag,MYF(0))) <= 0) + if ((new_file= mysql_file_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + param->temp_filename, + "", INDEX_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, MYF(0))) <= 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -1991,9 +1995,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) /* Put same locks as old file */ share->r_locks= share->w_locks= share->tot_locks= 0; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); - (void) my_close(share->kfile,MYF(MY_WME)); + (void) mysql_file_close(share->kfile, MYF(MY_WME)); share->kfile = -1; - (void) my_close(new_file,MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(MY_WME)); if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0, MYF(0)) || mi_open_keyfile(share)) @@ -2017,9 +2021,10 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name) DBUG_RETURN(0); err: - (void) my_close(new_file,MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(MY_WME)); err2: - (void) my_delete(param->temp_filename,MYF(MY_WME)); + (void) mysql_file_delete(mi_key_file_datatmp, + param->temp_filename, MYF(MY_WME)); DBUG_RETURN(-1); } /* mi_sort_index */ @@ -2099,8 +2104,8 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, /* Fill block with zero and write it to the new index file */ length=mi_getint(buff); bzero((uchar*) buff+length,keyinfo->block_length-length); - if (my_pwrite(new_file,(uchar*) buff,(uint) keyinfo->block_length, - new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL))) + if (mysql_file_pwrite(new_file, (uchar*) buff, (uint) keyinfo->block_length, + new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL))) { mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno); goto err; @@ -2176,16 +2181,16 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, buff=tmp_buff; buff_length=IO_SIZE; } - my_seek(from,start,MY_SEEK_SET,MYF(0)); + mysql_file_seek(from, start, MY_SEEK_SET, MYF(0)); while (length > buff_length) { - if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) || - my_write(to,(uchar*) buff,buff_length,param->myf_rw)) + if (mysql_file_read(from, (uchar*) buff, buff_length, MYF(MY_NABP)) || + mysql_file_write(to, (uchar*) buff, buff_length, param->myf_rw)) goto err; length-= buff_length; } - if (my_read(from,(uchar*) buff,(uint) length,MYF(MY_NABP)) || - my_write(to,(uchar*) buff,(uint) length,param->myf_rw)) + if (mysql_file_read(from, (uchar*) buff, (uint) length, MYF(MY_NABP)) || + mysql_file_write(to, (uchar*) buff, (uint) length, param->myf_rw)) goto err; if (buff != tmp_buff) my_free(buff,MYF(0)); @@ -2275,14 +2280,15 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -2320,7 +2326,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_info.dupp=0; sort_info.buff=0; param->read_cache.end_of_file=sort_info.filelength= - my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0)); sort_param.wordlist=NULL; init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); @@ -2470,7 +2476,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, sort_param.filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; share->data_file_type=sort_info.new_data_file_type; share->pack.header_length=(ulong) new_header_length; @@ -2510,7 +2516,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, skr=share->base.reloc*share->base.min_pack_length; #endif if (skr != sort_info.filelength && !info->s->base.raid_type) - if (my_chsize(info->dfile,skr,0,MYF(0))) + if (mysql_file_chsize(info->dfile, skr, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of datafile, error: %d", my_errno); @@ -2518,7 +2524,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_CALC_CHECKSUM) info->state->checksum=param->glob_crc; - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of indexfile, error: %d", my_errno); @@ -2545,7 +2551,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -2561,9 +2567,10 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -2704,9 +2711,11 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, DBUG_PRINT("info", ("is quick repair: %d", rep_quick)); bzero((char*)&sort_info,sizeof(sort_info)); /* Initialize pthread structures before goto err. */ - pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&sort_info.cond, 0); - pthread_mutex_init(¶m->print_msg_mutex, MY_MUTEX_INIT_FAST); + mysql_mutex_init(mi_key_mutex_MI_SORT_INFO_mutex, + &sort_info.mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(mi_key_cond_MI_SORT_INFO_cond, &sort_info.cond, 0); + mysql_mutex_init(mi_key_mutex_MI_CHECK_print_msg, + ¶m->print_msg_mutex, MY_MUTEX_INIT_FAST); param->need_print_msg_lock= 1; if (!(sort_info.key_block= @@ -2732,15 +2741,16 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, if (!rep_quick) { /* Get real path for data file */ - if ((new_file=my_raid_create(fn_format(param->temp_filename, - share->data_file_name, "", - DATA_TMP_EXT, - 2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0))) < 0) + if ((new_file= my_raid_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_TMP_EXT, + 2+4), + 0, param->tmpfile_createflag, + share->base.raid_type, + share->base.raid_chunks, + share->base.raid_chunksize, + MYF(0))) < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", param->temp_filename); @@ -2777,7 +2787,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, sort_info.dupp=0; sort_info.buff=0; param->read_cache.end_of_file=sort_info.filelength= - my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); + mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0)); if (share->data_file_type == DYNAMIC_RECORD) rec_length=max(share->base.min_pack_length+1,share->base.min_block_length); @@ -2903,7 +2913,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, goto err; sort_info.got_error=0; - pthread_mutex_lock(&sort_info.mutex); + mysql_mutex_lock(&sort_info.mutex); /* Initialize the I/O cache share for use with the read caches and, in @@ -2951,9 +2961,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, #else param->sort_buffer_length*sort_param[i].key_length/total_key_length; #endif - if (pthread_create(&sort_param[i].thr, &thr_attr, - thr_find_all_keys, - (void *) (sort_param+i))) + if (mysql_thread_create(mi_key_thread_find_all_keys, + &sort_param[i].thr, &thr_attr, + thr_find_all_keys, + (void *) (sort_param+i))) { mi_check_print_error(param,"Cannot start a repair thread"); /* Cleanup: Detach from the share. Avoid others to be blocked. */ @@ -2969,8 +2980,8 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, /* waiting for all threads to finish */ while (sort_info.threads_running) - pthread_cond_wait(&sort_info.cond, &sort_info.mutex); - pthread_mutex_unlock(&sort_info.mutex); + mysql_cond_wait(&sort_info.cond, &sort_info.mutex); + mysql_mutex_unlock(&sort_info.mutex); if ((got_error= thr_write_keys(sort_param))) { @@ -3006,7 +3017,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, Exchange the data file descriptor of the table, so that we use the new file from now on. */ - my_close(info->dfile,MYF(0)); + mysql_file_close(info->dfile, MYF(0)); info->dfile=new_file; share->data_file_type=sort_info.new_data_file_type; @@ -3035,7 +3046,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, skr=share->base.reloc*share->base.min_pack_length; #endif if (skr != sort_info.filelength && !info->s->base.raid_type) - if (my_chsize(info->dfile,skr,0,MYF(0))) + if (mysql_file_chsize(info->dfile, skr, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of datafile, error: %d", my_errno); @@ -3043,7 +3054,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_CALC_CHECKSUM) info->state->checksum=param->glob_crc; - if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) + if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0))) mi_check_print_warning(param, "Can't change size of indexfile, error: %d", my_errno); @@ -3082,7 +3093,7 @@ err: /* Replace the actual file with the temporary file */ if (new_file >= 0) { - my_close(new_file,MYF(0)); + mysql_file_close(new_file, MYF(0)); info->dfile=new_file= -1; if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, share->base.raid_chunks, @@ -3098,9 +3109,10 @@ err: mi_check_print_error(param,"%d when fixing table",my_errno); if (new_file >= 0) { - (void) my_close(new_file,MYF(0)); - (void) my_raid_delete(param->temp_filename,share->base.raid_chunks, - MYF(MY_WME)); + (void) mysql_file_close(new_file, MYF(0)); + (void) my_raid_delete(mi_key_file_datatmp, + param->temp_filename, share->base.raid_chunks, + MYF(MY_WME)); if (info->dfile == new_file) /* Retry with key cache */ if (unlikely(mi_open_datafile(info, share, name, -1))) param->retry_repair= 0; /* Safety */ @@ -3111,9 +3123,9 @@ err: share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS; share->state.changed|=STATE_NOT_SORTED_PAGES; - pthread_cond_destroy (&sort_info.cond); - pthread_mutex_destroy(&sort_info.mutex); - pthread_mutex_destroy(¶m->print_msg_mutex); + mysql_cond_destroy(&sort_info.cond); + mysql_mutex_destroy(&sort_info.mutex); + mysql_mutex_destroy(¶m->print_msg_mutex); param->need_print_msg_lock= 0; my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR)); @@ -4067,8 +4079,9 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param, if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff)) DBUG_RETURN(1); } - else if (my_pwrite(info->s->kfile,(uchar*) anc_buff, - (uint) keyinfo->block_length,filepos, param->myf_rw)) + else if (mysql_file_pwrite(info->s->kfile, (uchar*) anc_buff, + (uint) keyinfo->block_length, filepos, + param->myf_rw)) DBUG_RETURN(1); DBUG_DUMP("buff",(uchar*) anc_buff,mi_getint(anc_buff)); @@ -4172,8 +4185,8 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param) DFLT_INIT_HITS, key_block->buff)) DBUG_RETURN(1); } - else if (my_pwrite(info->s->kfile,(uchar*) key_block->buff, - (uint) keyinfo->block_length,filepos, myf_rw)) + else if (mysql_file_pwrite(info->s->kfile, (uchar*) key_block->buff, + (uint) keyinfo->block_length, filepos, myf_rw)) DBUG_RETURN(1); DBUG_DUMP("buff",(uchar*) key_block->buff,length); nod_flag=1; @@ -4213,9 +4226,11 @@ int test_if_almost_full(MI_INFO *info) { if (info->s->options & HA_OPTION_COMPRESS_RECORD) return 0; - return my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)) / 10 * 9 > + return mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, + MYF(MY_THREADSAFE)) / 10 * 9 > (my_off_t) info->s->base.max_key_file_length || - my_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) / 10 * 9 > + mysql_file_seek(info->dfile, 0L, MY_SEEK_END, + MYF(0)) / 10 * 9 > (my_off_t) info->s->base.max_data_file_length; } @@ -4313,7 +4328,8 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) if (share.options & HA_OPTION_COMPRESS_RECORD) share.base.records=max_records=info.state->records; else if (share.base.min_pack_length) - max_records=(ha_rows) (my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)) / + max_records=(ha_rows) (mysql_file_seek(info.dfile, 0L, MY_SEEK_END, + MYF(0)) / (ulong) share.base.min_pack_length); else max_records=0; @@ -4321,7 +4337,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) (param->testflag & T_UNPACK); share.options&= ~HA_OPTION_TEMP_COMPRESS_RECORD; - file_length=(ulonglong) my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)); + file_length=(ulonglong) mysql_file_seek(info.dfile, 0L, MY_SEEK_END, MYF(0)); tmp_length= file_length+file_length/10; set_if_bigger(file_length,param->max_data_file_length); set_if_bigger(file_length,tmp_length); diff --git a/storage/myisam/mi_close.c b/storage/myisam/mi_close.c index f94c8f3558d..8ec0bf14e0a 100644 --- a/storage/myisam/mi_close.c +++ b/storage/myisam/mi_close.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004 MySQL AB +/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -31,7 +31,7 @@ int mi_close(register MI_INFO *info) (long) info, (uint) share->reopen, (uint) share->tot_locks)); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); if (info->lock_type == F_EXTRA_LCK) info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ @@ -40,7 +40,7 @@ int mi_close(register MI_INFO *info) if (mi_lock_database(info,F_UNLCK)) error=my_errno; } - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (share->options & HA_OPTION_READ_ONLY_DATA) { @@ -55,7 +55,7 @@ int mi_close(register MI_INFO *info) } flag= !--share->reopen; myisam_open_list=list_delete(myisam_open_list,&info->open_list); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); if (flag) @@ -79,7 +79,7 @@ int mi_close(register MI_INFO *info) mi_state_info_write(share->kfile, &share->state, 1); /* Decrement open count must be last I/O on this file. */ _mi_decrement_open_count(info); - if (my_close(share->kfile,MYF(0))) + if (mysql_file_close(share->kfile, MYF(0))) error = my_errno; } #ifdef HAVE_MMAP @@ -93,25 +93,25 @@ int mi_close(register MI_INFO *info) } #ifdef THREAD thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->intern_lock); + mysql_mutex_destroy(&share->intern_lock); { int i,keys; keys = share->state.header.keys; - (void) rwlock_destroy(&share->mmap_lock); + mysql_rwlock_destroy(&share->mmap_lock); for(i=0; i<keys; i++) { - (void) rwlock_destroy(&share->key_root_lock[i]); + mysql_rwlock_destroy(&share->key_root_lock[i]); } } #endif my_free((uchar*) info->s,MYF(0)); } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (info->ftparser_param) { my_free((uchar*)info->ftparser_param, MYF(0)); info->ftparser_param= 0; } - if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) + if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0))) error = my_errno; myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error); diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 7733fd5db17..66d5d4fa3cd 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -572,7 +572,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, if (! (flags & HA_DONT_TOUCH_DATA)) share.state.create_time= (long) time((time_t*) 0); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); /* NOTE: For test_if_reopen() we need a real path name. Hence we need @@ -638,8 +638,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, goto err; } - if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode, - MYF(MY_WME | create_flag))) < 0) + if ((file= mysql_file_create_with_symlink(mi_key_file_kfile, + linkname_ptr, filename, 0, + create_mode, + MYF(MY_WME | create_flag))) < 0) goto err; errpos=1; @@ -694,8 +696,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; } if ((dfile= - my_create_with_symlink(linkname_ptr, filename, 0, create_mode, - MYF(MY_WME | create_flag))) < 0) + mysql_file_create_with_symlink(mi_key_file_dfile, + linkname_ptr, filename, 0, + create_mode, + MYF(MY_WME | create_flag))) < 0) goto err; } errpos=3; @@ -706,9 +710,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, mi_base_info_write(file, &share.base)) goto err; #ifndef DBUG_OFF - if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE) + if ((uint) mysql_file_tell(file, MYF(0)) != base_pos + MI_BASE_INFO_SIZE) { - uint pos=(uint) my_tell(file,MYF(0)); + uint pos=(uint) mysql_file_tell(file, MYF(0)); DBUG_PRINT("warning",("base_length: %d != used_length: %d", base_pos+ MI_BASE_INFO_SIZE, pos)); } @@ -803,9 +807,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, goto err; #ifndef DBUG_OFF - if ((uint) my_tell(file,MYF(0)) != info_length) + if ((uint) mysql_file_tell(file, MYF(0)) != info_length) { - uint pos= (uint) my_tell(file,MYF(0)); + uint pos= (uint) mysql_file_tell(file, MYF(0)); DBUG_PRINT("warning",("info_length: %d != used_length: %d", info_length, pos)); } @@ -813,46 +817,49 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, /* Enlarge files */ DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart)); - if (my_chsize(file,(ulong) share.base.keystart,0,MYF(0))) + if (mysql_file_chsize(file, (ulong) share.base.keystart, 0, MYF(0))) goto err; if (! (flags & HA_DONT_TOUCH_DATA)) { #ifdef USE_RELOC - if (my_chsize(dfile,share.base.min_pack_length*ci->reloc_rows,0,MYF(0))) + if (mysql_file_chsize(dfile, share.base.min_pack_length*ci->reloc_rows, + 0, MYF(0))) goto err; #endif errpos=2; - if (my_close(dfile,MYF(0))) + if (mysql_file_close(dfile, MYF(0))) goto err; } errpos=0; - pthread_mutex_unlock(&THR_LOCK_myisam); - if (my_close(file,MYF(0))) + mysql_mutex_unlock(&THR_LOCK_myisam); + if (mysql_file_close(file, MYF(0))) goto err; my_free((char*) rec_per_key_part,MYF(0)); DBUG_RETURN(0); err: - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); save_errno=my_errno; switch (errpos) { case 3: - (void) my_close(dfile,MYF(0)); + (void) mysql_file_close(dfile, MYF(0)); /* fall through */ case 2: /* QQ: Tõnu should add a call to my_raid_delete() here */ if (! (flags & HA_DONT_TOUCH_DATA)) - my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + mysql_file_delete_with_symlink(mi_key_file_dfile, + fn_format(filename, name, "", MI_NAME_DEXT, + MY_UNPACK_FILENAME | MY_APPEND_EXT), + MYF(0)); /* fall through */ case 1: - (void) my_close(file,MYF(0)); + (void) mysql_file_close(file, MYF(0)); if (! (flags & HA_DONT_TOUCH_DATA)) - my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT), - MYF(0)); + mysql_file_delete_with_symlink(mi_key_file_kfile, + fn_format(filename, name, "", MI_NAME_IEXT, + MY_UNPACK_FILENAME | MY_APPEND_EXT), + MYF(0)); } my_free((char*) rec_per_key_part, MYF(0)); DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */ diff --git a/storage/myisam/mi_delete_all.c b/storage/myisam/mi_delete_all.c index cbf5abf7ef5..b8706069ced 100644 --- a/storage/myisam/mi_delete_all.c +++ b/storage/myisam/mi_delete_all.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2003, 2005 MySQL AB +/* Copyright (C) 2000-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -57,8 +57,8 @@ int mi_delete_all_rows(MI_INFO *info) if (share->file_map) _mi_unmap_file(info); #endif - if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || - my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) + if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) || + mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME))) goto err; (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); #ifdef HAVE_MMAP diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index a3c0dede581..28aee848665 100644 --- a/storage/myisam/mi_delete_table.c +++ b/storage/myisam/mi_delete_table.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB +/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -58,12 +58,13 @@ int mi_delete_table(const char *name) #endif /* USE_RAID */ fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_delete_with_symlink(from, MYF(MY_WME))) + if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME))) DBUG_RETURN(my_errno); fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); #ifdef USE_RAID if (raid_type) DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0); #endif - DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0); + DBUG_RETURN(mysql_file_delete_with_symlink(mi_key_file_dfile, + from, MYF(MY_WME)) ? my_errno : 0); } diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index 1de0fef876d..4c681eeff5f 100644 --- a/storage/myisam/mi_dynrec.c +++ b/storage/myisam/mi_dynrec.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -143,7 +143,7 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer, { DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile)); if (info->s->concurrent_insert) - rw_rdlock(&info->s->mmap_lock); + mysql_rwlock_rdlock(&info->s->mmap_lock); /* The following test may fail in the following cases: @@ -156,24 +156,24 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer, { memcpy(Buffer, info->s->file_map + offset, Count); if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); return 0; } else { if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); - return my_pread(info->dfile, Buffer, Count, offset, MyFlags); + mysql_rwlock_unlock(&info->s->mmap_lock); + return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags); } } - /* wrapper for my_pread in case if mmap isn't used */ + /* wrapper for mysql_file_pread in case if mmap isn't used */ size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags) { - return my_pread(info->dfile, Buffer, Count, offset, MyFlags); + return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags); } @@ -198,7 +198,7 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer, { DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile)); if (info->s->concurrent_insert) - rw_rdlock(&info->s->mmap_lock); + mysql_rwlock_rdlock(&info->s->mmap_lock); /* The following test may fail in the following cases: @@ -211,26 +211,26 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer, { memcpy(info->s->file_map + offset, Buffer, Count); if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); return 0; } else { info->s->nonmmaped_inserts++; if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); - return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); + mysql_rwlock_unlock(&info->s->mmap_lock); + return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags); } } - /* wrapper for my_pwrite in case if mmap isn't used */ + /* wrapper for mysql_file_pwrite in case if mmap isn't used */ size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags) { - return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); + return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags); } @@ -1642,7 +1642,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos, while (length > IO_SIZE*2) { - if (my_pread(file,temp_buff,next_length,filepos, MYF(MY_NABP)) || + if (mysql_file_pread(file, temp_buff, next_length, filepos, MYF(MY_NABP)) || memcmp(buff, temp_buff, next_length)) goto err; filepos+=next_length; @@ -1650,7 +1650,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos, length-= next_length; next_length=IO_SIZE*2; } - if (my_pread(file,temp_buff,length,filepos,MYF(MY_NABP))) + if (mysql_file_pread(file, temp_buff, length, filepos, MYF(MY_NABP))) goto err; DBUG_RETURN(memcmp(buff,temp_buff,length)); err: @@ -1831,8 +1831,9 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf, block_info.filepos + block_info.data_len && flush_io_cache(&info->rec_cache)) goto err; - /* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */ - if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP))) + /* mysql_file_seek(info->dfile, filepos, MY_SEEK_SET, MYF(0)); */ + if (mysql_file_read(info->dfile, (uchar*) to, block_info.data_len, + MYF(MY_NABP))) { if (my_errno == -1) my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */ @@ -1880,12 +1881,12 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos) if (file >= 0) { /* - We do not use my_pread() here because we want to have the file + We do not use mysql_file_pread() here because we want to have the file pointer set to the end of the header after this function. - my_pread() may leave the file pointer untouched. + mysql_file_pread() may leave the file pointer untouched. */ - my_seek(file,filepos,MY_SEEK_SET,MYF(0)); - if (my_read(file, header, sizeof(info->header),MYF(0)) != + mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, header, sizeof(info->header), MYF(0)) != sizeof(info->header)) goto err; } diff --git a/storage/myisam/mi_extra.c b/storage/myisam/mi_extra.c index f0ddc15b325..d8f4fc99c8e 100644 --- a/storage/myisam/mi_extra.c +++ b/storage/myisam/mi_extra.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2005 MySQL AB +/* Copyright (C) 2000-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -74,17 +74,17 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) #if defined(HAVE_MMAP) && defined(HAVE_MADVISE) if ((share->options & HA_OPTION_COMPRESS_RECORD)) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (_mi_memmap_file(info)) { /* We don't nead MADV_SEQUENTIAL if small file */ madvise((char*) share->file_map, share->state.state.data_file_length, share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ? MADV_RANDOM : MADV_SEQUENTIAL); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); break; } - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } #endif if (info->opt_flag & WRITE_CACHE_USED) @@ -252,16 +252,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) } break; case HA_EXTRA_FORCE_REOPEN: - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); share->last_version= 0L; /* Impossible version */ - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); break; case HA_EXTRA_PREPARE_FOR_DROP: - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); share->last_version= 0L; /* Impossible version */ #ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND /* Close the isam and data files as Win32 can't drop an open table */ - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (flush_key_blocks(share->key_cache, share->kfile, (function == HA_EXTRA_FORCE_REOPEN ? FLUSH_RELEASE : FLUSH_IGNORE_CHANGED))) @@ -285,7 +285,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) } if (share->kfile >= 0) _mi_decrement_open_count(info); - if (share->kfile >= 0 && my_close(share->kfile,MYF(0))) + if (share->kfile >= 0 && mysql_file_close(share->kfile, MYF(0))) error=my_errno; { LIST *list_element ; @@ -296,16 +296,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) MI_INFO *tmpinfo=(MI_INFO*) list_element->data; if (tmpinfo->s == info->s) { - if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0))) + if (tmpinfo->dfile >= 0 && mysql_file_close(tmpinfo->dfile, MYF(0))) error = my_errno; tmpinfo->dfile= -1; } } } share->kfile= -1; /* Files aren't open anymore */ - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #endif - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); break; case HA_EXTRA_FLUSH: if (!share->temporary) @@ -316,9 +316,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) if (share->not_flushed) { share->not_flushed=0; - if (my_sync(share->kfile, MYF(0))) + if (mysql_file_sync(share->kfile, MYF(0))) error= my_errno; - if (my_sync(info->dfile, MYF(0))) + if (mysql_file_sync(info->dfile, MYF(0))) error= my_errno; if (error) { @@ -349,7 +349,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) break; case HA_EXTRA_MMAP: #ifdef HAVE_MMAP - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); /* Memory map the data file if it is not already mapped. It is safe to memory map a file while other threads are using file I/O on it. @@ -370,13 +370,13 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) share->file_write= mi_mmap_pwrite; } } - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #endif break; case HA_EXTRA_MARK_AS_LOG_TABLE: - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); share->is_log_table= TRUE; - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); break; case HA_EXTRA_KEY_CACHE: case HA_EXTRA_NO_KEY_CACHE: diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c index a454a4ade9b..36d7073a4dc 100644 --- a/storage/myisam/mi_info.c +++ b/storage/myisam/mi_info.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2003-2004 MySQL AB +/* Copyright (C) 2000-2001, 2003-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -42,10 +42,10 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) DBUG_RETURN(0); /* Compatible with ISAM */ if (!(flag & HA_STATUS_NO_LOCK)) { - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); (void) _mi_readinfo(info,F_RDLCK,0); fast_mi_writeinfo(info); - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); } if (flag & HA_STATUS_VARIABLE) { @@ -85,7 +85,7 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag) x->data_file_name = share->data_file_name; x->index_file_name = share->index_file_name; } - if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0))) + if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0))) x->update_time=state.st_mtime; else x->update_time=0; diff --git a/storage/myisam/mi_keycache.c b/storage/myisam/mi_keycache.c index 5cf3fede1ae..cbd9c7d76ab 100644 --- a/storage/myisam/mi_keycache.c +++ b/storage/myisam/mi_keycache.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -96,7 +96,7 @@ int mi_assign_to_key_cache(MI_INFO *info, ensure that setting the key cache and changing the multi_key_cache is done atomicly */ - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); /* Tell all threads to use the new key cache This should be seen at the lastes for the next call to an myisam function. @@ -108,7 +108,7 @@ int mi_assign_to_key_cache(MI_INFO *info, share->unique_name_length, share->key_cache)) error= my_errno; - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); DBUG_RETURN(error); } @@ -143,7 +143,7 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache, /* Lock list to ensure that no one can close the table while we manipulate it */ - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); for (pos=myisam_open_list ; pos ; pos=pos->next) { MI_INFO *info= (MI_INFO*) pos->data; @@ -158,6 +158,6 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache, open a new table that will be associted with the old key cache */ multi_key_cache_change(old_key_cache, new_key_cache); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); DBUG_VOID_RETURN; } diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c index 687962af42a..dd33fb71910 100644 --- a/storage/myisam/mi_locking.c +++ b/storage/myisam/mi_locking.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -49,7 +49,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } flag=error=0; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); if (share->kfile >= 0) /* May only be false on windows */ { switch (lock_type) { @@ -88,11 +88,11 @@ int mi_lock_database(MI_INFO *info, int lock_type) (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS)) { if (info->s->concurrent_insert) - rw_wrlock(&info->s->mmap_lock); + mysql_rwlock_wrlock(&info->s->mmap_lock); mi_remap_file(info, info->s->state.state.data_file_length); info->s->nonmmaped_inserts= 0; if (info->s->concurrent_insert) - rw_unlock(&info->s->mmap_lock); + mysql_rwlock_unlock(&info->s->mmap_lock); } #endif share->state.process= share->last_process=share->this_process; @@ -103,9 +103,9 @@ int mi_lock_database(MI_INFO *info, int lock_type) share->changed=0; if (myisam_flush) { - if (my_sync(share->kfile, MYF(0))) + if (mysql_file_sync(share->kfile, MYF(0))) error= my_errno; - if (my_sync(info->dfile, MYF(0))) + if (mysql_file_sync(info->dfile, MYF(0))) error= my_errno; } else @@ -251,7 +251,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } } #endif - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); #if defined(FULL_LOG) || defined(_lint) lock_type|=(int) (flag << 8); /* Set bit to set if real lock */ myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type), @@ -458,8 +458,8 @@ int _mi_writeinfo(register MI_INFO *info, uint operation) #ifdef _WIN32 if (myisam_flush) { - my_sync(share->kfile,0); - my_sync(info->dfile,0); + mysql_file_sync(share->kfile, 0); + mysql_file_sync(info->dfile, 0); } #endif } @@ -539,9 +539,9 @@ int _mi_mark_file_changed(MI_INFO *info) { mi_int2store(buff,share->state.open_count); buff[2]=1; /* Mark that it's changed */ - DBUG_RETURN(my_pwrite(share->kfile,buff,sizeof(buff), - sizeof(share->state.header), - MYF(MY_NABP))); + DBUG_RETURN(mysql_file_pwrite(share->kfile, buff, sizeof(buff), + sizeof(share->state.header), + MYF(MY_NABP))); } } DBUG_RETURN(0); @@ -568,9 +568,9 @@ int _mi_decrement_open_count(MI_INFO *info) { share->state.open_count--; mi_int2store(buff,share->state.open_count); - write_error=my_pwrite(share->kfile,buff,sizeof(buff), - sizeof(share->state.header), - MYF(MY_NABP)); + write_error= mysql_file_pwrite(share->kfile, buff, sizeof(buff), + sizeof(share->state.header), + MYF(MY_NABP)); } if (!lock_error) lock_error=mi_lock_database(info,old_lock); diff --git a/storage/myisam/mi_log.c b/storage/myisam/mi_log.c index 14e496e79b7..54498393f15 100644 --- a/storage/myisam/mi_log.c +++ b/storage/myisam/mi_log.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -54,16 +54,19 @@ int mi_log(int activate_log) myisam_pid=(ulong) getpid(); if (myisam_log_file < 0) { - if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename, - "",".log",4), - 0,(O_RDWR | O_BINARY | O_APPEND),MYF(0))) - < 0) + if ((myisam_log_file= mysql_file_create(mi_key_file_log, + fn_format(buff, + myisam_log_filename, + "", ".log", 4), + 0, + (O_RDWR | O_BINARY | O_APPEND), + MYF(0))) < 0) DBUG_RETURN(my_errno); } } else if (myisam_log_file >= 0) { - error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ; + error= mysql_file_close(myisam_log_file, MYF(0)) ? my_errno : 0 ; myisam_log_file= -1; } DBUG_RETURN(error); @@ -86,13 +89,13 @@ void _myisam_log(enum myisam_log_commands command, MI_INFO *info, mi_int4store(buff+3,pid); mi_int2store(buff+9,length); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); - (void) my_write(myisam_log_file,buffert,length,MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); + (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } @@ -109,14 +112,14 @@ void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info, mi_int2store(buff+1,info->dfile); mi_int4store(buff+3,pid); mi_int2store(buff+7,result); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); if (buffert) - (void) my_write(myisam_log_file,buffert,length,MYF(0)); + (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0)); if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } @@ -140,10 +143,10 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, mi_int2store(buff+7,result); mi_sizestore(buff+9,filepos); mi_int4store(buff+17,length); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - (void) my_write(myisam_log_file, buff,sizeof(buff),MYF(0)); - (void) my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)); + (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0)); + (void) mysql_file_write(myisam_log_file, record, info->s->base.reclength, MYF(0)); if (info->s->base.blobs) { MI_BLOB *blob,*end; @@ -154,11 +157,11 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, { memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length, sizeof(char*)); - (void) my_write(myisam_log_file,pos,blob->length,MYF(0)); + (void) mysql_file_write(myisam_log_file, pos, blob->length, MYF(0)); } } if (!error) error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=old_errno; } diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index b97470c0aa6..f7137ac554d 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -103,7 +103,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) DBUG_RETURN (NULL); } - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); if (!(old_info=test_if_reopen(name_buff))) { share= &share_buff; @@ -120,17 +120,21 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno= HA_ERR_CRASHED; goto err; }); - if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0) + if ((kfile= mysql_file_open(mi_key_file_kfile, + name_buff, + (open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0) { if ((errno != EROFS && errno != EACCES) || mode != O_RDONLY || - (kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0) + (kfile= mysql_file_open(mi_key_file_kfile, + name_buff, + (open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0) goto err; } share->mode=open_mode; errpos=1; - if (my_read(kfile, share->state.header.file_version, head_length, - MYF(MY_NABP))) + if (mysql_file_read(kfile, share->state.header.file_version, head_length, + MYF(MY_NABP))) { my_errno= HA_ERR_NOT_A_TABLE; goto err; @@ -181,7 +185,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) end_pos=disk_cache+info_length; errpos=2; - my_seek(kfile,0L,MY_SEEK_SET,MYF(0)); + mysql_file_seek(kfile, 0L, MY_SEEK_SET, MYF(0)); if (!(open_flags & HA_OPEN_TMP_TABLE)) { if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF, @@ -191,7 +195,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) goto err; } errpos=3; - if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP))) + if (mysql_file_read(kfile, disk_cache, info_length, MYF(MY_NABP))) { my_errno=HA_ERR_CRASHED; goto err; @@ -309,9 +313,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) &share->state.key_del, (share->state.header.max_block_size_index*sizeof(my_off_t)), #ifdef THREAD - &share->key_root_lock,sizeof(rw_lock_t)*keys, + &share->key_root_lock, sizeof(mysql_rwlock_t)*keys, #endif - &share->mmap_lock,sizeof(rw_lock_t), + &share->mmap_lock, sizeof(mysql_rwlock_t), NullS)) goto err; errpos=4; @@ -522,10 +526,12 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) share->is_log_table= FALSE; #ifdef THREAD thr_lock_init(&share->lock); - pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); + mysql_mutex_init(mi_key_mutex_MYISAM_SHARE_intern_lock, + &share->intern_lock, MY_MUTEX_INIT_FAST); for (i=0; i<keys; i++) - (void) my_rwlock_init(&share->key_root_lock[i], NULL); - (void) my_rwlock_init(&share->mmap_lock, NULL); + mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_key_root_lock, + &share->key_root_lock[i]); + mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_mmap_lock, &share->mmap_lock); if (!thr_lock_inited) { /* Probably a single threaded program; Don't use concurrent inserts */ @@ -611,7 +617,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) info.ft1_to_ft2=0; info.errkey= -1; info.page_changed=1; - pthread_mutex_lock(&share->intern_lock); + mysql_mutex_lock(&share->intern_lock); info.read_record=share->read_record; share->reopen++; share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL); @@ -635,7 +641,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) myisam_delay_key_write) share->delay_key_write=1; info.state= &share->state.state; /* Change global values by default */ - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); /* Allocate buffer for one record */ @@ -651,7 +657,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) m_info->open_list.data=(void*) m_info; myisam_open_list=list_add(myisam_open_list,&m_info->open_list); - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (myisam_log_file >= 0) { intern_filename(name_buff,share->index_file_name); @@ -670,7 +676,7 @@ err: my_free((uchar*) m_info,MYF(0)); /* fall through */ case 5: - (void) my_close(info.dfile,MYF(0)); + (void) mysql_file_close(info.dfile, MYF(0)); if (old_info) break; /* Don't remove open table */ /* fall through */ @@ -685,13 +691,13 @@ err: my_afree(disk_cache); /* fall through */ case 1: - (void) my_close(kfile,MYF(0)); + (void) mysql_file_close(kfile, MYF(0)); /* fall through */ case 0: default: break; } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); my_errno=save_errno; DBUG_RETURN (NULL); } /* mi_open */ @@ -924,10 +930,10 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite) } if (pWrite & 1) - DBUG_RETURN(my_pwrite(file, buff, (size_t) (ptr-buff), 0L, - MYF(MY_NABP | MY_THREADSAFE)) != 0); - DBUG_RETURN(my_write(file, buff, (size_t) (ptr-buff), - MYF(MY_NABP)) != 0); + DBUG_RETURN(mysql_file_pwrite(file, buff, (size_t) (ptr-buff), 0L, + MYF(MY_NABP | MY_THREADSAFE)) != 0); + DBUG_RETURN(mysql_file_write(file, buff, (size_t) (ptr-buff), + MYF(MY_NABP)) != 0); } @@ -992,10 +998,10 @@ uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead) { if (pRead) { - if (my_pread(file, buff, state->state_length,0L, MYF(MY_NABP))) + if (mysql_file_pread(file, buff, state->state_length, 0L, MYF(MY_NABP))) return 1; } - else if (my_read(file, buff, state->state_length,MYF(MY_NABP))) + else if (mysql_file_read(file, buff, state->state_length, MYF(MY_NABP))) return 1; mi_state_info_read(buff, state); } @@ -1038,7 +1044,7 @@ uint mi_base_info_write(File file, MI_BASE_INFO *base) mi_int2store(ptr,base->raid_chunks); ptr +=2; mi_int4store(ptr,base->raid_chunksize); ptr +=4; bzero(ptr,6); ptr +=6; /* extra */ - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } @@ -1098,7 +1104,7 @@ uint mi_keydef_write(File file, MI_KEYDEF *keydef) mi_int2store(ptr,keydef->keylength); ptr +=2; mi_int2store(ptr,keydef->minlength); ptr +=2; mi_int2store(ptr,keydef->maxlength); ptr +=2; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef) @@ -1142,7 +1148,7 @@ int mi_keyseg_write(File file, const HA_KEYSEG *keyseg) mi_int4store(ptr, pos); ptr+=4; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } @@ -1184,7 +1190,7 @@ uint mi_uniquedef_write(File file, MI_UNIQUEDEF *def) *ptr++= (uchar) def->key; *ptr++ = (uchar) def->null_are_equal; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *def) @@ -1208,7 +1214,7 @@ uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo) mi_int2store(ptr,recinfo->length); ptr +=2; *ptr++ = recinfo->null_bit; mi_int2store(ptr,recinfo->null_pos); ptr+= 2; - return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo) @@ -1261,15 +1267,18 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, } else #endif - info->dfile=my_open(data_name, share->mode | O_SHARE, MYF(MY_WME)); + info->dfile= mysql_file_open(mi_key_file_dfile, + data_name, share->mode | O_SHARE, MYF(MY_WME)); return info->dfile >= 0 ? 0 : 1; } int mi_open_keyfile(MYISAM_SHARE *share) { - if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE, - MYF(MY_WME))) < 0) + if ((share->kfile= mysql_file_open(mi_key_file_kfile, + share->unique_file_name, + share->mode | O_SHARE, + MYF(MY_WME))) < 0) return 1; return 0; } diff --git a/storage/myisam/mi_packrec.c b/storage/myisam/mi_packrec.c index 887a8254979..ee56d86f5ba 100644 --- a/storage/myisam/mi_packrec.c +++ b/storage/myisam/mi_packrec.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -150,7 +150,7 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys) file=info->dfile; my_errno=0; - if (my_read(file,(uchar*) header,sizeof(header),MYF(MY_NABP))) + if (mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP))) { if (!my_errno) my_errno=HA_ERR_END_OF_FILE; @@ -224,9 +224,9 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys) tmp_buff=share->decode_tables+length; disk_cache= (uchar*) (tmp_buff+OFFSET_TABLE_SIZE); - if (my_read(file,disk_cache, - (uint) (share->pack.header_length-sizeof(header)), - MYF(MY_NABP))) + if (mysql_file_read(file, disk_cache, + (uint) (share->pack.header_length-sizeof(header)), + MYF(MY_NABP))) goto err2; huff_tree_bits=max_bit(trees ? trees-1 : 0); @@ -717,8 +717,8 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, uchar *buf) if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info, &info->rec_buff, file, filepos)) goto err; - if (my_read(file,(uchar*) info->rec_buff + block_info.offset , - block_info.rec_len - block_info.offset, MYF(MY_NABP))) + if (mysql_file_read(file, (uchar*) info->rec_buff + block_info.offset, + block_info.rec_len - block_info.offset, MYF(MY_NABP))) goto panic; info->update|= HA_STATE_AKTIV; DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf, @@ -1339,9 +1339,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, uchar *buf, } else { - if (my_read(info->dfile,(uchar*) info->rec_buff + block_info.offset, - block_info.rec_len-block_info.offset, - MYF(MY_NABP))) + if (mysql_file_read(info->dfile, + (uchar*) info->rec_buff + block_info.offset, + block_info.rec_len-block_info.offset, MYF(MY_NABP))) goto err; } info->packed_length=block_info.rec_len; @@ -1370,11 +1370,11 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff, { ref_length=myisam->s->pack.ref_length; /* - We can't use my_pread() here because mi_read_rnd_pack_record assumes + We can't use mysql_file_pread() here because mi_read_rnd_pack_record assumes position is ok */ - my_seek(file,filepos,MY_SEEK_SET,MYF(0)); - if (my_read(file, header,ref_length,MYF(MY_NABP))) + mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, header, ref_length, MYF(MY_NABP))) return BLOCK_FATAL_ERROR; DBUG_DUMP("header",(uchar*) header,ref_length); } @@ -1496,7 +1496,7 @@ my_bool _mi_memmap_file(MI_INFO *info) if (!info->s->file_map) { - if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) < + if (mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) < share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN) { DBUG_PRINT("warning",("File isn't extended for memmap")); diff --git a/storage/myisam/mi_panic.c b/storage/myisam/mi_panic.c index 02dfb239cc0..69865cfc0bb 100644 --- a/storage/myisam/mi_panic.c +++ b/storage/myisam/mi_panic.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2003 MySQL AB +/* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -30,17 +30,17 @@ int mi_panic(enum ha_panic_function flag) MI_INFO *info; DBUG_ENTER("mi_panic"); - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); for (list_element=myisam_open_list ; list_element ; list_element=next_open) { next_open=list_element->next; /* Save if close */ info=(MI_INFO*) list_element->data; switch (flag) { case HA_PANIC_CLOSE: - pthread_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ + mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ if (mi_close(info)) error=my_errno; - pthread_mutex_lock(&THR_LOCK_myisam); + mysql_mutex_lock(&THR_LOCK_myisam); break; case HA_PANIC_WRITE: /* Do this to free databases */ #ifdef CANT_OPEN_FILES_TWICE @@ -66,9 +66,9 @@ int mi_panic(enum ha_panic_function flag) error=my_errno; } #ifdef CANT_OPEN_FILES_TWICE - if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0))) + if (info->s->kfile >= 0 && mysql_file_close(info->s->kfile, MYF(0))) error = my_errno; - if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) + if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0))) error = my_errno; info->s->kfile=info->dfile= -1; /* Files aren't open anymore */ break; @@ -78,15 +78,19 @@ int mi_panic(enum ha_panic_function flag) { /* Open closed files */ char name_buff[FN_REFLEN]; if (info->s->kfile < 0) - if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"", - N_NAME_IEXT,4),info->mode, - MYF(MY_WME))) < 0) + if ((info->s->kfile= mysql_file_open(mi_key_file_kfile, + fn_format(name_buff, + info->filename, "", + N_NAME_IEXT, 4), + info->mode, MYF(MY_WME))) < 0) error = my_errno; if (info->dfile < 0) { - if ((info->dfile= my_open(fn_format(name_buff,info->filename,"", - N_NAME_DEXT,4),info->mode, - MYF(MY_WME))) < 0) + if ((info->dfile= mysql_file_open(mi_key_file_dfile, + fn_format(name_buff, + info->filename, "", + N_NAME_DEXT, 4), + info->mode, MYF(MY_WME))) < 0) error = my_errno; info->rec_cache.file=info->dfile; } @@ -106,7 +110,7 @@ int mi_panic(enum ha_panic_function flag) (void) mi_log(0); /* Close log if neaded */ ft_free_stopwords(); } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (!error) DBUG_RETURN(0); DBUG_RETURN(my_errno=error); diff --git a/storage/myisam/mi_preload.c b/storage/myisam/mi_preload.c index 60ab55106cb..ae45014eab5 100644 --- a/storage/myisam/mi_preload.c +++ b/storage/myisam/mi_preload.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2005 MySQL AB +/* Copyright (C) 2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -81,7 +81,8 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) /* Read the next block of index file into the preload buffer */ if ((my_off_t) length > (key_file_length-pos)) length= (ulong) (key_file_length-pos); - if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP))) + if (mysql_file_pread(share->kfile, (uchar*) buff, length, pos, + MYF(MY_FAE|MY_FNABP))) goto err; if (ignore_leaves) diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index dc6dc9d62b7..927c511eec1 100644 --- a/storage/myisam/mi_range.c +++ b/storage/myisam/mi_range.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004, 2006 MySQL AB +/* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -57,7 +57,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, DBUG_RETURN(HA_POS_ERROR); info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); switch(info->s->keyinfo[inx].key_alg){ #ifdef HAVE_RTREE_KEYS @@ -106,7 +106,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, } if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); fast_mi_writeinfo(info); DBUG_PRINT("info",("records: %ld",(ulong) (res))); diff --git a/storage/myisam/mi_rename.c b/storage/myisam/mi_rename.c index 51669b0caa6..56ccb333d03 100644 --- a/storage/myisam/mi_rename.c +++ b/storage/myisam/mi_rename.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -47,7 +47,7 @@ int mi_rename(const char *old_name, const char *new_name) fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_rename_with_symlink(from, to, MYF(MY_WME))) + if (mysql_file_rename_with_symlink(mi_key_file_kfile, from, to, MYF(MY_WME))) DBUG_RETURN(my_errno); fn_format(from,old_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); @@ -56,5 +56,7 @@ int mi_rename(const char *old_name, const char *new_name) DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno : 0); #endif - DBUG_RETURN(my_rename_with_symlink(from, to,MYF(MY_WME)) ? my_errno : 0); + DBUG_RETURN(mysql_file_rename_with_symlink(mi_key_file_dfile, + from, to, + MYF(MY_WME)) ? my_errno : 0); } diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c index f1d35810d36..d3744c9a053 100644 --- a/storage/myisam/mi_rkey.c +++ b/storage/myisam/mi_rkey.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -71,7 +71,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, goto err; if (share->concurrent_insert) - rw_rdlock(&share->key_root_lock[inx]); + mysql_rwlock_rdlock(&share->key_root_lock[inx]); nextflag=myisam_read_vec[search_flag]; use_key_length=pack_key_length; @@ -156,7 +156,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, } } if (share->concurrent_insert) - rw_unlock(&share->key_root_lock[inx]); + mysql_rwlock_unlock(&share->key_root_lock[inx]); /* Calculate length of the found key; Used by mi_rnext_same */ if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg && diff --git a/storage/myisam/mi_rnext.c b/storage/myisam/mi_rnext.c index 7ce66d41e0f..6def5749043 100644 --- a/storage/myisam/mi_rnext.c +++ b/storage/myisam/mi_rnext.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2004 MySQL AB +/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -39,7 +39,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx) if (fast_mi_readinfo(info)) DBUG_RETURN(my_errno); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); changed=_mi_test_if_changed(info); if (!flag) { @@ -96,7 +96,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx) break; } } - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); } /* Don't clear if database-changed */ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); diff --git a/storage/myisam/mi_rnext_same.c b/storage/myisam/mi_rnext_same.c index 1892fe3e1e0..6779709fc80 100644 --- a/storage/myisam/mi_rnext_same.c +++ b/storage/myisam/mi_rnext_same.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -38,7 +38,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf) DBUG_RETURN(my_errno); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); switch (keyinfo->key_alg) { @@ -81,7 +81,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf) } } if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); /* Don't clear if database-changed */ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME; diff --git a/storage/myisam/mi_rprev.c b/storage/myisam/mi_rprev.c index d1407012590..f7dddefb647 100644 --- a/storage/myisam/mi_rprev.c +++ b/storage/myisam/mi_rprev.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2004 MySQL AB +/* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -39,7 +39,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx) DBUG_RETURN(my_errno); changed=_mi_test_if_changed(info); if (share->concurrent_insert) - rw_rdlock(&share->key_root_lock[inx]); + mysql_rwlock_rdlock(&share->key_root_lock[inx]); if (!flag) error=_mi_search_last(info, share->keyinfo+inx, share->state.key_root[inx]); @@ -65,7 +65,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx) break; } } - rw_unlock(&share->key_root_lock[inx]); + mysql_rwlock_unlock(&share->key_root_lock[inx]); } info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update|= HA_STATE_PREV_FOUND; diff --git a/storage/myisam/mi_rsame.c b/storage/myisam/mi_rsame.c index 08c482acc9b..ea41dc73c92 100644 --- a/storage/myisam/mi_rsame.c +++ b/storage/myisam/mi_rsame.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2001, 2005 MySQL AB +/* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -49,12 +49,12 @@ int mi_rsame(MI_INFO *info, uchar *record, int inx) info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record, info->lastpos); if (info->s->concurrent_insert) - rw_rdlock(&info->s->key_root_lock[inx]); + mysql_rwlock_rdlock(&info->s->key_root_lock[inx]); (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, SEARCH_SAME, info->s->state.key_root[inx]); if (info->s->concurrent_insert) - rw_unlock(&info->s->key_root_lock[inx]); + mysql_rwlock_unlock(&info->s->key_root_lock[inx]); } if (!(*info->read_record)(info,info->lastpos,record)) diff --git a/storage/myisam/mi_static.c b/storage/myisam/mi_static.c index a3ba785a94f..aaa7405bbb5 100644 --- a/storage/myisam/mi_static.c +++ b/storage/myisam/mi_static.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2002, 2004-2005 MySQL AB +/* Copyright (C) 2000-2002, 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -68,3 +68,74 @@ uint NEAR myisam_readnext_vec[]= SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER }; + +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock, + mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg; + +static PSI_mutex_info all_myisam_mutexes[]= +{ + { &mi_key_mutex_MI_SORT_INFO_mutex, "MI_SORT_INFO::mutex", 0}, + { &mi_key_mutex_MYISAM_SHARE_intern_lock, "MYISAM_SHARE::intern_lock", 0}, + { &mi_key_mutex_MI_CHECK_print_msg, "MI_CHECK::print_msg", 0} +}; + +PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock, + mi_key_rwlock_MYISAM_SHARE_mmap_lock; + +static PSI_rwlock_info all_myisam_rwlocks[]= +{ + { &mi_key_rwlock_MYISAM_SHARE_key_root_lock, "MYISAM_SHARE::key_root_lock", 0}, + { &mi_key_rwlock_MYISAM_SHARE_mmap_lock, "MYISAM_SHARE::mmap_lock", 0} +}; + +PSI_cond_key mi_key_cond_MI_SORT_INFO_cond; + +static PSI_cond_info all_myisam_conds[]= +{ + { &mi_key_cond_MI_SORT_INFO_cond, "MI_SORT_INFO::cond", 0} +}; + +PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile, + mi_key_file_log; + +static PSI_file_info all_myisam_files[]= +{ + { & mi_key_file_datatmp, "data_tmp", 0}, + { & mi_key_file_dfile, "dfile", 0}, + { & mi_key_file_kfile, "kfile", 0}, + { & mi_key_file_log, "log", 0} +}; + +PSI_thread_key mi_key_thread_find_all_keys; + +static PSI_thread_info all_myisam_threads[]= +{ + { &mi_key_thread_find_all_keys, "find_all_keys", 0}, +}; + +void init_myisam_psi_keys() +{ + const char* category= "myisam"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_myisam_mutexes); + PSI_server->register_mutex(category, all_myisam_mutexes, count); + + count= array_elements(all_myisam_rwlocks); + PSI_server->register_rwlock(category, all_myisam_rwlocks, count); + + count= array_elements(all_myisam_conds); + PSI_server->register_cond(category, all_myisam_conds, count); + + count= array_elements(all_myisam_files); + PSI_server->register_file(category, all_myisam_files, count); + + count= array_elements(all_myisam_threads); + PSI_server->register_thread(category, all_myisam_threads, count); +} +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index b9bc84aa6ad..4293d9b5269 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -107,7 +107,7 @@ int mi_write(MI_INFO *info, uchar *record) is_tree_inited(&info->bulk_insert[i]))); if (local_lock_tree) { - rw_wrlock(&share->key_root_lock[i]); + mysql_rwlock_wrlock(&share->key_root_lock[i]); share->keyinfo[i].version++; } if (share->keyinfo[i].flag & HA_FULLTEXT ) @@ -115,7 +115,7 @@ int mi_write(MI_INFO *info, uchar *record) if (_mi_ft_add(info,i, buff, record, filepos)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); DBUG_PRINT("error",("Got error: %d on write",my_errno)); goto err; } @@ -126,7 +126,7 @@ int mi_write(MI_INFO *info, uchar *record) _mi_make_key(info,i,buff,record,filepos))) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); DBUG_PRINT("error",("Got error: %d on write",my_errno)); goto err; } @@ -136,7 +136,7 @@ int mi_write(MI_INFO *info, uchar *record) info->update&= ~HA_STATE_RNEXT_SAME; if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); } } if (share->calc_checksum) @@ -197,13 +197,13 @@ err: !(info->bulk_insert && is_tree_inited(&info->bulk_insert[i]))); if (local_lock_tree) - rw_wrlock(&share->key_root_lock[i]); + mysql_rwlock_wrlock(&share->key_root_lock[i]); if (share->keyinfo[i].flag & HA_FULLTEXT) { if (_mi_ft_del(info,i, buff,record,filepos)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); break; } } @@ -213,12 +213,12 @@ err: if (_mi_ck_delete(info,i,buff,key_length)) { if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); break; } } if (local_lock_tree) - rw_unlock(&share->key_root_lock[i]); + mysql_rwlock_unlock(&share->key_root_lock[i]); } } } @@ -943,7 +943,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param) case free_init: if (param->info->s->concurrent_insert) { - rw_wrlock(¶m->info->s->key_root_lock[param->keynr]); + mysql_rwlock_wrlock(¶m->info->s->key_root_lock[param->keynr]); param->info->s->keyinfo[param->keynr].version++; } return 0; @@ -955,7 +955,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param) keylen - param->info->s->rec_reflength); case free_end: if (param->info->s->concurrent_insert) - rw_unlock(¶m->info->s->key_root_lock[param->keynr]); + mysql_rwlock_unlock(¶m->info->s->key_root_lock[param->keynr]); return 0; } return -1; diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index b64c7f6bd7f..7f617fd044e 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -24,6 +24,7 @@ #else #include <my_no_pthread.h> #endif +#include <mysql/psi/mysql_file.h> #if defined(my_write) && !defined(MAP_TO_USE_RAID) #undef my_write /* undef map from my_nosys; We need test-if-disk full */ @@ -213,13 +214,13 @@ typedef struct st_mi_isam_share { /* Shared between opens */ concurrent_insert; #ifdef THREAD THR_LOCK lock; - pthread_mutex_t intern_lock; /* Locking for use with _locking */ - rw_lock_t *key_root_lock; + mysql_mutex_t intern_lock; /* Locking for use with _locking */ + mysql_rwlock_t *key_root_lock; #endif my_off_t mmaped_length; uint nonmmaped_inserts; /* counter of writing in non-mmaped area */ - rw_lock_t mmap_lock; + mysql_rwlock_t mmap_lock; } MYISAM_SHARE; @@ -460,12 +461,12 @@ typedef struct st_mi_sort_param #define mi_unique_store(A,B) mi_int4store((A),(B)) #ifdef THREAD -extern pthread_mutex_t THR_LOCK_myisam; +extern mysql_mutex_t THR_LOCK_myisam; #endif #if !defined(THREAD) || defined(DONT_USE_RW_LOCKS) -#define rw_wrlock(A) {} -#define rw_rdlock(A) {} -#define rw_unlock(A) {} +#define mysql_rwlock_wrlock(A) {} +#define mysql_rwlock_rdlock(A) {} +#define mysql_rwlock_unlock(A) {} #endif /* Some extern variables */ @@ -785,3 +786,22 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); } #endif +#ifdef HAVE_PSI_INTERFACE +C_MODE_START +extern PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock, + mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg; + +extern PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock, + mi_key_rwlock_MYISAM_SHARE_mmap_lock; + +extern PSI_cond_key mi_key_cond_MI_SORT_INFO_cond; + +extern PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile, + mi_key_file_log; + +extern PSI_thread_key mi_key_thread_find_all_keys; + +void init_myisam_psi_keys(); +C_MODE_END +#endif /* HAVE_PSI_INTERFACE */ + diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 139a5f39d85..23a821ba75b 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -44,6 +44,7 @@ #define DATA_TMP_EXT ".TMD" #define OLD_EXT ".OLD" +#define FRM_EXT ".frm" #define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE struct st_file_buffer { @@ -125,6 +126,7 @@ static void get_options(int *argc,char ***argv); static MI_INFO *open_isam_file(char *name,int mode); static my_bool open_isam_files(PACK_MRG_INFO *mrg,char **names,uint count); static int compress(PACK_MRG_INFO *file,char *join_name); +static int create_dest_frm(char *source_table, char *dest_table); static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records); static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, @@ -216,9 +218,13 @@ int main(int argc, char **argv) error=ok=isamchk_neaded=0; if (join_table) - { /* Join files into one */ + { + /* + Join files into one and create FRM file for the compressed table only if + the compression succeeds + */ if (open_isam_files(&merge,argv,(uint) argc) || - compress(&merge,join_table)) + compress(&merge, join_table) || create_dest_frm(argv[0], join_table)) error=1; } else while (argc--) @@ -759,6 +765,44 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) DBUG_RETURN(-1); } + +/** + Create FRM for the destination table for --join operation + Copy the first table FRM as the destination table FRM file. Doing so + will help the mysql server to recognize the newly created table. + See Bug#36573. + + @param source_table Name of the source table + @param dest_table Name of the destination table + @retval 0 Successful copy operation + + @note We always return 0 because we don't want myisampack to report error + even if the copy operation fails. +*/ + +static int create_dest_frm(char *source_table, char *dest_table) +{ + char source_name[FN_REFLEN], dest_name[FN_REFLEN]; + + DBUG_ENTER("create_dest_frm"); + + (void) fn_format(source_name, source_table, + "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS); + (void) fn_format(dest_name, dest_table, + "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS); + /* + Error messages produced by my_copy() are suppressed as this + is not vital for --join operation. User shouldn't see any error messages + like "source file frm not found" and "unable to create destination frm + file. So we don't pass the flag MY_WME -Write Message on Error to + my_copy() + */ + (void) my_copy(source_name, dest_name, MYF(MY_DONT_OVERWRITE_FILE)); + + return 0; +} + + /* Init a huff_count-struct for each field and init it */ static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records) diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index 670b5f4a30f..441d6bfa05b 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc 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 @@ -478,10 +478,10 @@ ok: if (sort_param->read_cache.share) remove_io_thread(&sort_param->read_cache); - pthread_mutex_lock(&sort_param->sort_info->mutex); + mysql_mutex_lock(&sort_param->sort_info->mutex); if (!--sort_param->sort_info->threads_running) - pthread_cond_signal(&sort_param->sort_info->cond); - pthread_mutex_unlock(&sort_param->sort_info->mutex); + mysql_cond_signal(&sort_param->sort_info->cond); + mysql_mutex_unlock(&sort_param->sort_info->mutex); DBUG_PRINT("exit", ("======== ending thread ========")); } my_thread_end(); @@ -824,8 +824,9 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count))) { - if (my_pread(fromfile->file,(uchar*) buffpek->base, - (length= sort_length*count),buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base, + (length= sort_length*count), + buffpek->file_pos, MYF_RW)) return((uint) -1); /* purecov: inspected */ buffpek->key=buffpek->base; buffpek->file_pos+= length; /* New filepos */ @@ -849,12 +850,12 @@ static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek, for (idx=1;idx<=count;idx++) { - if (my_pread(fromfile->file,(uchar*)&length_of_key,sizeof(length_of_key), - buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*)&length_of_key, + sizeof(length_of_key), buffpek->file_pos, MYF_RW)) return((uint) -1); buffpek->file_pos+=sizeof(length_of_key); - if (my_pread(fromfile->file,(uchar*) buffp,length_of_key, - buffpek->file_pos,MYF_RW)) + if (mysql_file_pread(fromfile->file, (uchar*) buffp, + length_of_key, buffpek->file_pos, MYF_RW)) return((uint) -1); buffpek->file_pos+=length_of_key; buffp = buffp + sort_length; |