diff options
Diffstat (limited to 'storage/myisam')
63 files changed, 1387 insertions, 2587 deletions
diff --git a/storage/myisam/.cvsignore b/storage/myisam/.cvsignore deleted file mode 100644 index ef6d92c6e18..00000000000 --- a/storage/myisam/.cvsignore +++ /dev/null @@ -1,14 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -ft_eval -ft_test1 -mi_test1 -mi_test2 -mi_test3 -rt_test -sp_test -myisamchk -myisamlog -myisampack diff --git a/storage/myisam/CMakeLists.txt b/storage/myisam/CMakeLists.txt index c05e0046e64..487fbded2df 100755..100644 --- a/storage/myisam/CMakeLists.txt +++ b/storage/myisam/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2006 MySQL AB +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # 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 @@ -11,14 +11,9 @@ # # 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake") -INCLUDE("${PROJECT_SOURCE_DIR}/win/mysql_manifest.cmake") +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") - -SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c ft_stem.c +SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c ha_myisam.cc ft_stopwords.c ft_update.c mi_cache.c mi_changed.c mi_check.c mi_checksum.c mi_close.c mi_create.c mi_dbug.c mi_delete.c @@ -28,30 +23,45 @@ SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c mi_rfirst.c mi_rlast.c mi_rnext.c mi_rnext_same.c mi_rprev.c mi_rrnd.c mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c mi_unique.c mi_update.c mi_write.c rt_index.c rt_key.c rt_mbr.c - rt_split.c sort.c sp_key.c ft_eval.h myisamdef.h rt_index.h mi_rkey.c) + rt_split.c sort.c sp_key.c mi_extrafunc.h myisamdef.h + rt_index.h mi_rkey.c) -MYSQL_STORAGE_ENGINE(MYISAM) +MYSQL_ADD_PLUGIN(myisam ${MYISAM_SOURCES} + STORAGE_ENGINE + MANDATORY + RECOMPILE_FOR_EMBEDDED) -IF(NOT SOURCE_SUBLIBS) - ADD_EXECUTABLE(myisam_ftdump myisam_ftdump.c) - TARGET_LINK_LIBRARIES(myisam_ftdump myisam mysys debug dbug strings zlib wsock32) +TARGET_LINK_LIBRARIES(myisam mysys) - ADD_EXECUTABLE(myisamchk myisamchk.c) - TARGET_LINK_LIBRARIES(myisamchk myisam mysys debug dbug strings zlib wsock32) +MYSQL_ADD_EXECUTABLE(myisam_ftdump myisam_ftdump.c) +TARGET_LINK_LIBRARIES(myisam_ftdump myisam) - ADD_EXECUTABLE(myisamlog myisamlog.c) - TARGET_LINK_LIBRARIES(myisamlog myisam mysys debug dbug strings zlib wsock32) +MYSQL_ADD_EXECUTABLE(myisamchk myisamchk.c) +TARGET_LINK_LIBRARIES(myisamchk myisam) - ADD_EXECUTABLE(myisampack myisampack.c) - TARGET_LINK_LIBRARIES(myisampack myisam mysys debug dbug strings zlib wsock32) +MYSQL_ADD_EXECUTABLE(myisamlog myisamlog.c) +TARGET_LINK_LIBRARIES(myisamlog myisam) - SET_TARGET_PROPERTIES(myisamchk myisampack PROPERTIES LINK_FLAGS "setargv.obj") +MYSQL_ADD_EXECUTABLE(myisampack myisampack.c) +TARGET_LINK_LIBRARIES(myisampack myisam) + +IF(WITH_UNIT_TESTS AND FALSE) + ADD_EXECUTABLE(mi_test1 mi_test1.c) + TARGET_LINK_LIBRARIES(mi_test1 myisam) - IF(EMBED_MANIFESTS) - MYSQL_EMBED_MANIFEST("myisam_ftdump" "asInvoker") - MYSQL_EMBED_MANIFEST("myisamchk" "asInvoker") - MYSQL_EMBED_MANIFEST("myisamlog" "asInvoker") - MYSQL_EMBED_MANIFEST("myisampack" "asInvoker") - ENDIF(EMBED_MANIFESTS) + ADD_EXECUTABLE(mi_test2 mi_test2.c) + TARGET_LINK_LIBRARIES(mi_test2 myisam) -ENDIF(NOT SOURCE_SUBLIBS) + ADD_EXECUTABLE(mi_test3 mi_test3.c) + TARGET_LINK_LIBRARIES(mi_test3 myisam) + + ADD_EXECUTABLE(sp_test sp_test.c) + TARGET_LINK_LIBRARIES(sp_test myisam) + + ADD_EXECUTABLE(rt_test rt_test.c) + TARGET_LINK_LIBRARIES(rt_test myisam) +ENDIF() + +IF (MSVC) + SET_TARGET_PROPERTIES(myisamchk myisampack PROPERTIES LINK_FLAGS "setargv.obj") +ENDIF() diff --git a/storage/myisam/Makefile.am b/storage/myisam/Makefile.am index f50c312b8e4..5c3370ac6c5 100644 --- a/storage/myisam/Makefile.am +++ b/storage/myisam/Makefile.am @@ -27,7 +27,7 @@ LDADD = DEFS = @DEFS@ -EXTRA_DIST = mi_test_all.sh mi_test_all.res ft_stem.c CMakeLists.txt plug.in +EXTRA_DIST = mi_test_all.sh mi_test_all.res CMakeLists.txt plug.in pkgdata_DATA = mi_test_all mi_test_all.res pkglib_LIBRARIES = libmyisam.a @@ -47,10 +47,9 @@ myisampack_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/strings/libmystrings.a @ZLIB_LIBS@ -noinst_PROGRAMS = mi_test1 mi_test2 mi_test3 rt_test sp_test #ft_test1 ft_eval +noinst_PROGRAMS = mi_test1 mi_test2 mi_test3 rt_test sp_test noinst_HEADERS = myisamdef.h rt_index.h rt_key.h rt_mbr.h sp_defs.h \ - fulltext.h ftdefs.h ft_test1.h ft_eval.h \ - ha_myisam.h + fulltext.h ftdefs.h ha_myisam.h mi_extrafunc.h mi_test1_DEPENDENCIES= $(LIBRARIES) mi_test1_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \ $(top_builddir)/mysys/libmysys.a \ @@ -66,8 +65,6 @@ mi_test3_LDADD= @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/strings/libmystrings.a @ZLIB_LIBS@ -#ft_test1_DEPENDENCIES= $(LIBRARIES) -#ft_eval_DEPENDENCIES= $(LIBRARIES) myisam_ftdump_DEPENDENCIES= $(LIBRARIES) myisam_ftdump_LDADD = @CLIENT_EXTRA_LDFLAGS@ libmyisam.a \ $(top_builddir)/mysys/libmysys.a \ @@ -150,5 +147,23 @@ SUFFIXES = .sh @CHMOD@ +x $@-t @MV@ $@-t $@ -# Don't update the files from bitkeeper -%::SCCS/s.% +if HAVE_DTRACE_DASH_G +libmyisam_a_LIBADD = probes_mysql.o +libmyisam_a_DEPENDENCIES = probes_mysql.o dtrace_files dtrace_providers +CLEANFILES += probes_mysql.o dtrace_files dtrace_providers +DTRACEFILES = ha_myisam.o +DTRACEPROVIDER = probes_mysql.d +CLEANFILES += $(DTRACEPROVIDER) dtrace_sources + +dtrace_files: + echo $(DTRACEFILES) > $@ +dtrace_providers: probes_mysql.d + echo $(DTRACEPROVIDER) > $@ +probes_mysql.d: + -$(RM) -f probes_mysql.d + $(CP) $(top_srcdir)/include/probes_mysql.d.base probes_mysql.d + echo timestamp > dtrace_sources + +probes_mysql.o: $(DTRACEPROVIDER) $(DTRACEFILES) + $(DTRACE) $(DTRACEFLAGS) -G -s $(DTRACEPROVIDER) $(DTRACEFILES) -o $@ +endif diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index 52ad6b11aa1..b54b4c6ce49 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -92,6 +92,8 @@ static double *nwghts=_nwghts+5; /* nwghts[i] = -0.5*1.5**i */ #define FTB_FLAG_NO 4 #define FTB_FLAG_WONLY 8 +#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1) + typedef struct st_ftb_expr FTB_EXPR; struct st_ftb_expr { @@ -608,7 +610,7 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, uchar *query, return ftb; err: free_root(& ftb->mem_root, MYF(0)); - my_free((uchar*)ftb,MYF(0)); + my_free(ftb); return 0; } @@ -1032,7 +1034,7 @@ void ft_boolean_close_search(FT_INFO *ftb) delete_tree(& ftb->no_dupes); } free_root(& ftb->mem_root, MYF(0)); - my_free((uchar*)ftb,MYF(0)); + my_free(ftb); } diff --git a/storage/myisam/ft_eval.c b/storage/myisam/ft_eval.c deleted file mode 100644 index de01510fdd7..00000000000 --- a/storage/myisam/ft_eval.c +++ /dev/null @@ -1,252 +0,0 @@ -/* Copyright (C) 2000-2002 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 */ - -/* Written by Sergei A. Golubchik, who has a shared copyright to this code - added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */ - -#include "ftdefs.h" -#include "ft_eval.h" -#include <stdarg.h> -#include <my_getopt.h> - -static void print_error(int exit_code, const char *fmt,...); -static void get_options(int argc, char *argv[]); -static int create_record(char *pos, FILE *file); -static void usage(); - -static struct my_option my_long_options[] = -{ - {"", 's', "", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'q', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'S', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", '#', "", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'V', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", '?', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'h', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} -}; - -int main(int argc, char *argv[]) -{ - MI_INFO *file; - int i,j; - - MY_INIT(argv[0]); - get_options(argc,argv); - bzero((char*)recinfo,sizeof(recinfo)); - - /* First define 2 columns */ - recinfo[0].type=FIELD_SKIP_ENDSPACE; - recinfo[0].length=docid_length; - recinfo[1].type=FIELD_BLOB; - recinfo[1].length= 4+portable_sizeof_char_ptr; - - /* Define a key over the first column */ - keyinfo[0].seg=keyseg; - keyinfo[0].keysegs=1; - keyinfo[0].block_length= 0; /* Default block length */ - keyinfo[0].seg[0].type= HA_KEYTYPE_TEXT; - keyinfo[0].seg[0].flag= HA_BLOB_PART; - keyinfo[0].seg[0].start=recinfo[0].length; - keyinfo[0].seg[0].length=key_length; - keyinfo[0].seg[0].null_bit=0; - keyinfo[0].seg[0].null_pos=0; - keyinfo[0].seg[0].bit_start=4; - keyinfo[0].seg[0].language=MY_CHARSET_CURRENT; - keyinfo[0].flag = HA_FULLTEXT; - - if (!silent) - printf("- Creating isam-file\n"); - if (mi_create(filename,1,keyinfo,2,recinfo,0,NULL,(MI_CREATE_INFO*) 0,0)) - goto err; - if (!(file=mi_open(filename,2,0))) - goto err; - if (!silent) - printf("Initializing stopwords\n"); - ft_init_stopwords(stopwordlist); - - if (!silent) - printf("- Writing key:s\n"); - - my_errno=0; - i=0; - while (create_record(record,df)) - { - error=mi_write(file,record); - if (error) - printf("I= %2d mi_write: %d errno: %d\n",i,error,my_errno); - i++; - } - fclose(df); - - if (mi_close(file)) goto err; - if (!silent) - printf("- Reopening file\n"); - if (!(file=mi_open(filename,2,0))) goto err; - if (!silent) - printf("- Reading rows with key\n"); - for (i=1;create_record(record,qf);i++) - { - FT_DOCLIST *result; - double w; - int t, err; - - result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1); - if (!result) - { - printf("Query %d failed with errno %3d\n",i,my_errno); - goto err; - } - if (!silent) - printf("Query %d. Found: %d.\n",i,result->ndocs); - for (j=0;(err=ft_nlq_read_next(result, read_record))==0;j++) - { - t=uint2korr(read_record); - w=ft_nlq_get_relevance(result); - printf("%d %.*s %f\n",i,t,read_record+2,w); - } - if (err != HA_ERR_END_OF_FILE) - { - printf("ft_read_next %d failed with errno %3d\n",j,my_errno); - goto err; - } - ft_nlq_close_search(result); - } - - if (mi_close(file)) goto err; - my_end(MY_CHECK_ERROR); - - return (0); - - err: - printf("got error: %3d when using myisam-database\n",my_errno); - return 1; /* skip warning */ - -} - - -static my_bool -get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) -{ - switch (optid) { - case 's': - if (stopwordlist && stopwordlist != ft_precompiled_stopwords) - break; - { - FILE *f; char s[HA_FT_MAXLEN]; int i=0,n=SWL_INIT; - - if (!(stopwordlist=(const char**) malloc(n*sizeof(char *)))) - print_error(1,"malloc(%d)",n*sizeof(char *)); - if (!(f=fopen(argument,"r"))) - print_error(1,"fopen(%s)",argument); - while (!feof(f)) - { - if (!(fgets(s,HA_FT_MAXLEN,f))) - print_error(1,"fgets(s,%d,%s)",HA_FT_MAXLEN,argument); - if (!(stopwordlist[i++]=strdup(s))) - print_error(1,"strdup(%s)",s); - if (i >= n) - { - n+=SWL_PLUS; - if (!(stopwordlist=(const char**) realloc((char*) stopwordlist, - n*sizeof(char *)))) - print_error(1,"realloc(%d)",n*sizeof(char *)); - } - } - fclose(f); - stopwordlist[i]=NULL; - break; - } - case 'q': silent=1; break; - case 'S': if (stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break; - case '#': - DBUG_PUSH (argument); - break; - case 'V': - case '?': - case 'h': - usage(); - exit(1); - } - return 0; -} - - -static void get_options(int argc, char *argv[]) -{ - int ho_error; - - if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) - exit(ho_error); - - if (!(d_file=argv[optind])) print_error(1,"No d_file"); - if (!(df=fopen(d_file,"r"))) - print_error(1,"fopen(%s)",d_file); - if (!(q_file=argv[optind+1])) print_error(1,"No q_file"); - if (!(qf=fopen(q_file,"r"))) - print_error(1,"fopen(%s)",q_file); - return; -} /* get options */ - - -static int create_record(char *pos, FILE *file) -{ - uint tmp; char *ptr; - - bzero((char *)pos,MAX_REC_LENGTH); - - /* column 1 - VARCHAR */ - if (!(fgets(pos+2,MAX_REC_LENGTH-32,file))) - { - if (feof(file)) - return 0; - else - print_error(1,"fgets(docid) - 1"); - } - tmp=(uint) strlen(pos+2)-1; - int2store(pos,tmp); - pos+=recinfo[0].length; - - /* column 2 - BLOB */ - - if (!(fgets(blob_record,MAX_BLOB_LENGTH,file))) - print_error(1,"fgets(docid) - 2"); - tmp=(uint) strlen(blob_record); - int4store(pos,tmp); - ptr=blob_record; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); - return 1; -} - -/* VARARGS */ - -static void print_error(int exit_code, const char *fmt,...) -{ - va_list args; - - va_start(args,fmt); - fprintf(stderr,"%s: error: ",my_progname); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); - fflush(stderr); - va_end(args); - exit(exit_code); -} - - -static void usage() -{ - printf("%s [options]\n", my_progname); - my_print_help(my_long_options); - my_print_variables(my_long_options); -} diff --git a/storage/myisam/ft_eval.h b/storage/myisam/ft_eval.h deleted file mode 100644 index 9acc1a60d09..00000000000 --- a/storage/myisam/ft_eval.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & Sergei A. Golubchik - - 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 */ - -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ - -const char **stopwordlist=ft_precompiled_stopwords; - -#define MAX_REC_LENGTH 128 -#define MAX_BLOB_LENGTH 60000 -char record[MAX_REC_LENGTH], read_record[MAX_REC_LENGTH+MAX_BLOB_LENGTH]; -char blob_record[MAX_BLOB_LENGTH+20*20]; - -char *filename= (char*) "EVAL"; - -int silent=0, error=0; - -uint key_length=MAX_BLOB_LENGTH,docid_length=32; -char *d_file, *q_file; -FILE *df,*qf; - -MI_COLUMNDEF recinfo[3]; -MI_KEYDEF keyinfo[2]; -HA_KEYSEG keyseg[10]; - -#define SWL_INIT 500 -#define SWL_PLUS 50 - -#define MAX_LINE_LENGTH 128 -char line[MAX_LINE_LENGTH]; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 5317da78ee4..937bb6ffe19 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -197,7 +197,8 @@ static int walk_and_push(FT_SUPERDOC *from, static int FT_DOC_cmp(void *unused __attribute__((unused)), FT_DOC *a, FT_DOC *b) { - return sgn(b->weight - a->weight); + double c= b->weight - a->weight; + return ((c < 0) ? -1 : (c > 0) ? 1 : 0); } @@ -357,7 +358,7 @@ float ft_nlq_find_relevance(FT_INFO *handler, void ft_nlq_close_search(FT_INFO *handler) { - my_free((uchar*)handler,MYF(0)); + my_free(handler); } diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index 4cde3834ed7..663d7869f71 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -39,7 +39,7 @@ static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) { word->weight=LWS_IN_USE; docstat->sum+=word->weight; - memcpy_fixed((docstat->list)++,word,sizeof(FT_WORD)); + memcpy((docstat->list)++, word, sizeof(FT_WORD)); return 0; } @@ -83,10 +83,10 @@ my_bool ft_boolean_check_syntax_string(const uchar *str) uint i, j; if (!str || - (strlen((char*) str)+1 != sizeof(ft_boolean_syntax)) || + (strlen((char*) str)+1 != sizeof(DEFAULT_FTB_SYNTAX)) || (str[0] != ' ' && str[1] != ' ')) return 1; - for (i=0; i<sizeof(ft_boolean_syntax); i++) + for (i=0; i<sizeof(DEFAULT_FTB_SYNTAX); i++) { /* limiting to 7-bit ascii only */ if ((unsigned char)(str[i]) > 127 || my_isalnum(default_charset_info, str[i])) @@ -127,7 +127,6 @@ uchar ft_get_word(CHARSET_INFO *cs, uchar **start, uchar *end, break; if (*doc == FTB_RQUOT && param->quot) { - param->quot= (char*) doc; *start=doc+1; param->type= FT_TOKEN_RIGHT_PAREN; goto ret; @@ -139,7 +138,7 @@ uchar ft_get_word(CHARSET_INFO *cs, uchar **start, uchar *end, /* param->prev=' '; */ *start=doc+1; if (*doc == FTB_LQUOT) - param->quot= (char*) *start; + param->quot= (char*) 1; param->type= (*doc == FTB_RBR ? FT_TOKEN_RIGHT_PAREN : FT_TOKEN_LEFT_PAREN); goto ret; } @@ -193,7 +192,6 @@ uchar ft_get_word(CHARSET_INFO *cs, uchar **start, uchar *end, if (param->quot) { *start= doc; - param->quot= (char*) doc; param->type= 3; /* FT_RBR */ goto ret; } diff --git a/storage/myisam/ft_static.c b/storage/myisam/ft_static.c index 1b6c7458fd7..78fbc5781e9 100644 --- a/storage/myisam/ft_static.c +++ b/storage/myisam/ft_static.c @@ -17,12 +17,12 @@ #include "ftdefs.h" -ulong ft_min_word_len=4; -ulong ft_max_word_len=HA_FT_MAXCHARLEN; -ulong ft_query_expansion_limit=5; -char ft_boolean_syntax[]="+ -><()~*:\"\"&|"; +ulong ft_min_word_len= 4; +ulong ft_max_word_len= HA_FT_MAXCHARLEN; +ulong ft_query_expansion_limit= 5; +const char *ft_boolean_syntax= DEFAULT_FTB_SYNTAX; -const HA_KEYSEG ft_keysegs[FT_SEGS]={ +const HA_KEYSEG ft_keysegs[FT_SEGS]= { { 0, /* charset */ HA_FT_WLEN, /* start */ @@ -30,8 +30,8 @@ const HA_KEYSEG ft_keysegs[FT_SEGS]={ 0, /* Bit pos */ HA_VAR_LENGTH_PART | HA_PACK_KEY, /* flag */ HA_FT_MAXBYTELEN, /* length */ - HA_KEYTYPE_VARTEXT2, /* type */ 63, /* language (will be overwritten) */ + HA_KEYTYPE_VARTEXT2, /* type */ 0, /* null_bit */ 2, 0, 0 /* bit_start, bit_end, bit_length */ }, @@ -41,15 +41,15 @@ const HA_KEYSEG ft_keysegs[FT_SEGS]={ be packed in any way, otherwise w_search() won't be able to update key entry 'in vivo' */ - 0, 0, 0, 0, HA_NO_SORT, HA_FT_WLEN, HA_FT_WTYPE, 63, 0, 0, 0, 0 + 0, 0, 0, 0, HA_NO_SORT, HA_FT_WLEN, 63, HA_FT_WTYPE, 0, 0, 0, 0 } }; -const struct _ft_vft _ft_vft_nlq = { +const struct _ft_vft _ft_vft_nlq= { ft_nlq_read_next, ft_nlq_find_relevance, ft_nlq_close_search, ft_nlq_get_relevance, ft_nlq_reinit_search }; -const struct _ft_vft _ft_vft_boolean = { +const struct _ft_vft _ft_vft_boolean= { ft_boolean_read_next, ft_boolean_find_relevance, ft_boolean_close_search, ft_boolean_get_relevance, ft_boolean_reinit_search }; @@ -68,8 +68,8 @@ FT_INFO *ft_init_search(uint flags, void *info, uint keynr, return res; } -const char *ft_stopword_file = 0; -const char *ft_precompiled_stopwords[] = { +const char *ft_stopword_file= 0; +const char *ft_precompiled_stopwords[]= { #ifdef COMPILE_STOPWORDS_IN diff --git a/storage/myisam/ft_stopwords.c b/storage/myisam/ft_stopwords.c index 9838b15af34..e8d81cbbbb1 100644 --- a/storage/myisam/ft_stopwords.c +++ b/storage/myisam/ft_stopwords.c @@ -18,6 +18,10 @@ #include "ftdefs.h" #include "my_handler.h" + +static CHARSET_INFO *ft_stopword_cs= NULL; + + typedef struct st_ft_stopwords { const char * pos; @@ -29,7 +33,7 @@ static TREE *stopwords3=NULL; static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)), FT_STOPWORD *w1, FT_STOPWORD *w2) { - return ha_compare_text(default_charset_info, + return ha_compare_text(ft_stopword_cs, (uchar *)w1->pos,w1->len, (uchar *)w2->pos,w2->len,0,0); } @@ -38,7 +42,7 @@ static void FT_STOPWORD_free(FT_STOPWORD *w, TREE_FREE action, void *arg __attribute__((unused))) { if (action == free_free) - my_free((uchar*) w->pos, MYF(0)); + my_free((void*)w->pos); } static int ft_add_stopword(const char *w) @@ -59,6 +63,14 @@ int ft_init_stopwords() 0, (ft_stopword_file ? (tree_element_free)&FT_STOPWORD_free : 0), NULL); + /* + Stopword engine currently does not support tricky + character sets UCS2, UTF16, UTF32. + Use latin1 to compare stopwords in case of these character sets. + It's also fine to use latin1 with the built-in stopwords. + */ + ft_stopword_cs= default_charset_info->mbminlen == 1 ? + default_charset_info : &my_charset_latin1; } if (ft_stopword_file) @@ -80,14 +92,14 @@ int ft_init_stopwords() goto err0; len=my_read(fd, buffer, len, MYF(MY_WME)); end=start+len; - while (ft_simple_get_word(default_charset_info, &start, end, &w, TRUE)) + while (ft_simple_get_word(ft_stopword_cs, &start, end, &w, TRUE)) { if (ft_add_stopword(my_strndup((char*) w.pos, w.len, MYF(0)))) goto err1; } error=0; err1: - my_free(buffer, MYF(0)); + my_free(buffer); err0: my_close(fd, MYF(MY_WME)); return error; @@ -121,7 +133,7 @@ void ft_free_stopwords() if (stopwords3) { delete_tree(stopwords3); /* purecov: inspected */ - my_free((char*) stopwords3,MYF(0)); + my_free(stopwords3); stopwords3=0; } ft_stopword_file= 0; diff --git a/storage/myisam/ft_test1.c b/storage/myisam/ft_test1.c deleted file mode 100644 index b37935a0d7a..00000000000 --- a/storage/myisam/ft_test1.c +++ /dev/null @@ -1,315 +0,0 @@ -/* Copyright (C) 2000-2002, 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 */ - -/* Written by Sergei A. Golubchik, who has a shared copyright to this code - added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */ - -#include "ftdefs.h" -#include "ft_test1.h" -#include <my_getopt.h> - -static int key_field=FIELD_VARCHAR,extra_field=FIELD_SKIP_ENDSPACE; -static uint key_length=200,extra_length=50; -static int key_type=HA_KEYTYPE_TEXT; -static int verbose=0,silent=0,skip_update=0, - no_keys=0,no_stopwords=0,no_search=0,no_fulltext=0; -static int create_flag=0,error=0; - -#define MAX_REC_LENGTH 300 -static char record[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH]; - -static int run_test(const char *filename); -static void get_options(int argc, char *argv[]); -static void create_record(char *, int); -static void usage(); - -static struct my_option my_long_options[] = -{ - {"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", '?', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'h', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'V', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 's', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'N', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'S', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'K', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'F', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", 'U', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"", '#', "", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} -}; - -int main(int argc, char *argv[]) -{ - MY_INIT(argv[0]); - - get_options(argc,argv); - - exit(run_test("FT1")); -} - -static MI_COLUMNDEF recinfo[3]; -static MI_KEYDEF keyinfo[2]; -static HA_KEYSEG keyseg[10]; - -static int run_test(const char *filename) -{ - MI_INFO *file; - int i,j; - my_off_t pos; - - bzero((char*) recinfo,sizeof(recinfo)); - - /* First define 2 columns */ - recinfo[0].type=extra_field; - recinfo[0].length= (extra_field == FIELD_BLOB ? 4 + portable_sizeof_char_ptr : - extra_length); - if (extra_field == FIELD_VARCHAR) - recinfo[0].length+= HA_VARCHAR_PACKLENGTH(extra_length); - recinfo[1].type=key_field; - recinfo[1].length= (key_field == FIELD_BLOB ? 4+portable_sizeof_char_ptr : - key_length); - if (key_field == FIELD_VARCHAR) - recinfo[1].length+= HA_VARCHAR_PACKLENGTH(key_length); - - /* Define a key over the first column */ - keyinfo[0].seg=keyseg; - keyinfo[0].keysegs=1; - keyinfo[0].block_length= 0; /* Default block length */ - keyinfo[0].seg[0].type= key_type; - keyinfo[0].seg[0].flag= (key_field == FIELD_BLOB) ? HA_BLOB_PART: - (key_field == FIELD_VARCHAR) ? HA_VAR_LENGTH_PART:0; - keyinfo[0].seg[0].start=recinfo[0].length; - keyinfo[0].seg[0].length=key_length; - keyinfo[0].seg[0].null_bit= 0; - keyinfo[0].seg[0].null_pos=0; - keyinfo[0].seg[0].language= default_charset_info->number; - keyinfo[0].flag = (no_fulltext?HA_PACK_KEY:HA_FULLTEXT); - - if (!silent) - printf("- Creating isam-file\n"); - if (mi_create(filename,(no_keys?0:1),keyinfo,2,recinfo,0,NULL, - (MI_CREATE_INFO*) 0, create_flag)) - goto err; - if (!(file=mi_open(filename,2,0))) - goto err; - - if (!silent) - printf("- %s stopwords\n",no_stopwords?"Skipping":"Initializing"); - ft_init_stopwords(no_stopwords?NULL:ft_precompiled_stopwords); - - if (!silent) - printf("- Writing key:s\n"); - - my_errno=0; - for (i=NUPD ; i<NDATAS; i++ ) - { - create_record(record,i); - error=mi_write(file,record); - if (verbose || error) - printf("I= %2d mi_write: %d errno: %d, record: %s\n", - i,error,my_errno,data[i].f0); - } - - if (!skip_update) - { - if (!silent) - printf("- Updating rows\n"); - - /* Read through all rows and update them */ - pos=(ha_rows) 0; - i=0; - while ((error=mi_rrnd(file,read_record,pos)) == 0) - { - create_record(record,NUPD-i-1); - if (mi_update(file,read_record,record)) - { - printf("Can't update row: %.*s, error: %d\n", - keyinfo[0].seg[0].length,record,my_errno); - } - if(++i == NUPD) break; - pos=HA_OFFSET_ERROR; - } - if (i != NUPD) - printf("Found %d of %d rows\n", i,NUPD); - } - - if (mi_close(file)) goto err; - if(no_search) return 0; - if (!silent) - printf("- Reopening file\n"); - if (!(file=mi_open(filename,2,0))) goto err; - if (!silent) - printf("- Reading rows with key\n"); - for (i=0 ; i < NQUERIES ; i++) - { - FT_DOCLIST *result; - result=ft_nlq_init_search(file,0,(char*) query[i],strlen(query[i]),1); - if(!result) - { - printf("Query %d: `%s' failed with errno %3d\n",i,query[i],my_errno); - continue; - } - printf("Query %d: `%s'. Found: %d. Top five documents:\n", - i,query[i],result->ndocs); - for (j=0;j<5;j++) - { - double w; int err; - err= ft_nlq_read_next(result, read_record); - if (err==HA_ERR_END_OF_FILE) - { - printf("No more matches!\n"); - break; - } - else if (err) - { - printf("ft_read_next %d failed with errno %3d\n",j,my_errno); - break; - } - w=ft_nlq_get_relevance(result); - if (key_field == FIELD_VARCHAR) - { - uint l; - char *p; - p=recinfo[0].length+read_record; - l=uint2korr(p); - printf("%10.7f: %.*s\n",w,(int) l,p+2); - } - else - printf("%10.7f: %.*s\n",w,recinfo[1].length, - recinfo[0].length+read_record); - } - ft_nlq_close_search(result); - } - - if (mi_close(file)) goto err; - my_end(MY_CHECK_ERROR); - - return (0); -err: - printf("got error: %3d when using myisam-database\n",my_errno); - return 1; /* skip warning */ -} - -static char blob_key[MAX_REC_LENGTH]; -/* static char blob_record[MAX_REC_LENGTH+20*20]; */ - -void create_record(char *pos, int n) -{ - bzero((char*) pos,MAX_REC_LENGTH); - if (recinfo[0].type == FIELD_BLOB) - { - uint tmp; - char *ptr; - strnmov(blob_key,data[n].f0,keyinfo[0].seg[0].length); - tmp=strlen(blob_key); - int4store(pos,tmp); - ptr=blob_key; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); - pos+=recinfo[0].length; - } - else if (recinfo[0].type == FIELD_VARCHAR) - { - uint tmp; - /* -1 is here because pack_length is stored in seg->length */ - uint pack_length= HA_VARCHAR_PACKLENGTH(keyinfo[0].seg[0].length-1); - strnmov(pos+pack_length,data[n].f0,keyinfo[0].seg[0].length); - tmp=strlen(pos+pack_length); - if (pack_length == 1) - *pos= (char) tmp; - else - int2store(pos,tmp); - pos+=recinfo[0].length; - } - else - { - strnmov(pos,data[n].f0,keyinfo[0].seg[0].length); - pos+=recinfo[0].length; - } - if (recinfo[1].type == FIELD_BLOB) - { - uint tmp; - char *ptr; - strnmov(blob_key,data[n].f2,keyinfo[0].seg[0].length); - tmp=strlen(blob_key); - int4store(pos,tmp); - ptr=blob_key; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); - pos+=recinfo[1].length; - } - else if (recinfo[1].type == FIELD_VARCHAR) - { - uint tmp; - /* -1 is here because pack_length is stored in seg->length */ - uint pack_length= HA_VARCHAR_PACKLENGTH(keyinfo[0].seg[0].length-1); - strnmov(pos+pack_length,data[n].f2,keyinfo[0].seg[0].length); - tmp=strlen(pos+1); - if (pack_length == 1) - *pos= (char) tmp; - else - int2store(pos,tmp); - pos+=recinfo[1].length; - } - else - { - strnmov(pos,data[n].f2,keyinfo[0].seg[0].length); - pos+=recinfo[1].length; - } -} - - -static my_bool -get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) -{ - switch(optid) { - case 'v': verbose=1; break; - case 's': silent=1; break; - case 'F': no_fulltext=1; no_search=1; - case 'U': skip_update=1; break; - case 'K': no_keys=no_search=1; break; - case 'N': no_search=1; break; - case 'S': no_stopwords=1; break; - case '#': - DBUG_PUSH (argument); - break; - case 'V': - case '?': - case 'h': - usage(); - exit(1); - } - return 0; -} - -/* Read options */ - -static void get_options(int argc,char *argv[]) -{ - int ho_error; - - if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) - exit(ho_error); - return; -} /* get options */ - - -static void usage() -{ - printf("%s [options]\n", my_progname); - my_print_help(my_long_options); - my_print_variables(my_long_options); -} diff --git a/storage/myisam/ft_test1.h b/storage/myisam/ft_test1.h deleted file mode 100644 index 4b466818460..00000000000 --- a/storage/myisam/ft_test1.h +++ /dev/null @@ -1,420 +0,0 @@ -/* Copyright (C) 2000-2001 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 */ - -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ - -#define NUPD 20 -#define NDATAS 389 -struct { const char *f0, *f2; } data[NDATAS] = { - {"1", "General Information about MySQL"}, - {"1.1", "What is MySQL?"}, - {"1.2", "About this manual"}, - {"1.3", "History of MySQL"}, - {"1.4", "The main features of MySQL"}, - {"1.5", "General SQL information and tutorials"}, - {"1.6", "Useful MySQL-related links"}, - {"1.7", "What are stored procedures and triggers and so on?"}, - {"2", "MySQL mailing lists and how to ask questions/give error (bug) reports"}, - {"2.1", "Subscribing to/un-subscribing from the MySQL mailing list"}, - {"2.2", "Asking questions or reporting bugs"}, - {"2.3", "I think I have found a bug. What information do you need to help me?"}, - {"2.3.1", "MySQL keeps crashing"}, - {"2.4", "Guidelines for answering questions on the mailing list"}, - {"3", "Licensing or When do I have/want to pay for MySQL?"}, - {"3.1", "How much does MySQL cost?"}, - {"3.2", "How do I get commercial support?"}, - {"3.2.1", "Types of commercial support"}, - {"3.2.1.1", "Basic email support"}, - {"3.2.1.2", "Extended email support"}, -/*------------------------------- NUPD=20 -------------------------------*/ - {"3.2.1.3", "Asking: Login support"}, - {"3.2.1.4", "Extended login support"}, - {"3.3", "How do I pay for licenses/support?"}, - {"3.4", "Who do I contact when I want more information about licensing/support?"}, - {"3.5", "What Copyright does MySQL use?"}, - {"3.6", "When may I distribute MySQL commercially without a fee?"}, - {"3.7", "I want to sell a product that can be configured to use MySQL"}, - {"3.8", "I am running a commercial web server using MySQL"}, - {"3.9", "Do I need a license to sell commercial Perl/tcl/PHP/Web+ etc applications?"}, - {"3.10", "Possible future changes in the licensing"}, - {"4", "Compiling and installing MySQL"}, - {"4.1", "How do I get MySQL?"}, - {"4.2", "Which MySQL version should I use?"}, - {"4.3", "How/when will you release updates?"}, - {"4.4", "What operating systems does MySQL support?"}, - {"4.5", "Compiling MySQL from source code"}, - {"4.5.1", "Quick installation overview"}, - {"4.5.2", "Usual configure switches"}, - {"4.5.3", "Applying a patch"}, - {"4.6", "Problems compiling?"}, - {"4.7", "General compilation notes"}, - {"4.8", "MIT-pthreads notes (FreeBSD)"}, - {"4.9", "Perl installation comments"}, - {"4.10", "Special things to consider for some machine/OS combinations"}, - {"4.10.1", "Solaris notes"}, - {"4.10.2", "SunOS 4 notes"}, - {"4.10.3", "Linux notes for all versions"}, - {"4.10.3.1", "Linux-x86 notes"}, - {"4.10.3.2", "RedHat 5.0"}, - {"4.10.3.3", "RedHat 5.1"}, - {"4.10.3.4", "Linux-Sparc notes"}, - {"4.10.3.5", "Linux-Alpha notes"}, - {"4.10.3.6", "MkLinux notes"}, - {"4.10.4", "Alpha-DEC-Unix notes"}, - {"4.10.5", "Alpha-DEC-OSF1 notes"}, - {"4.10.6", "SGI-IRIX notes"}, - {"4.10.7", "FreeBSD notes"}, - {"4.10.7.1", "FreeBSD-3.0 notes"}, - {"4.10.8", "BSD/OS 2.# notes"}, - {"4.10.8.1", "BSD/OS 3.# notes"}, - {"4.10.9", "SCO notes"}, - {"4.10.10", "SCO Unixware 7.0 notes"}, - {"4.10.11", "IBM-AIX notes"}, - {"4.10.12", "HP-UX notes"}, - {"4.11", "TcX binaries"}, - {"4.12", "Win32 notes"}, - {"4.13", "Installation instructions for MySQL binary releases"}, - {"4.13.1", "How to get MySQL Perl support working"}, - {"4.13.2", "Linux notes"}, - {"4.13.3", "HP-UX notes"}, - {"4.13.4", "Linking client libraries"}, - {"4.14", "Problems running mysql_install_db"}, - {"4.15", "Problems starting MySQL"}, - {"4.16", "Automatic start/stop of MySQL"}, - {"4.17", "Option files"}, - {"5", "How standards-compatible is MySQL?"}, - {"5.1", "What extensions has MySQL to ANSI SQL92?"}, - {"5.2", "What functionality is missing in MySQL?"}, - {"5.2.1", "Sub-selects"}, - {"5.2.2", "SELECT INTO TABLE"}, - {"5.2.3", "Transactions"}, - {"5.2.4", "Triggers"}, - {"5.2.5", "Foreign Keys"}, - {"5.2.5.1", "Some reasons NOT to use FOREIGN KEYS"}, - {"5.2.6", "Views"}, - {"5.2.7", "-- as start of a comment"}, - {"5.3", "What standards does MySQL follow?"}, - {"5.4", "What functions exist only for compatibility?"}, - {"5.5", "Limitations of BLOB and TEXT types"}, - {"5.6", "How to cope without COMMIT-ROLLBACK"}, - {"6", "The MySQL access privilege system"}, - {"6.1", "What the privilege system does"}, - {"6.2", "Connecting to the MySQL server"}, - {"6.2.1", "Keeping your password secure"}, - {"6.3", "Privileges provided by MySQL"}, - {"6.4", "How the privilege system works"}, - {"6.5", "The privilege tables"}, - {"6.6", "Setting up the initial MySQL privileges"}, - {"6.7", "Adding new user privileges to MySQL"}, - {"6.8", "An example permission setup"}, - {"6.9", "Causes of Access denied errors"}, - {"6.10", "How to make MySQL secure against crackers"}, - {"7", "MySQL language reference"}, - {"7.1", "Literals: how to write strings and numbers"}, - {"7.1.1", "Strings"}, - {"7.1.2", "Numbers"}, - {"7.1.3", "NULL values"}, - {"7.1.4", "Database, table, index, column and alias names"}, - {"7.1.4.1", "Case sensitivity in names"}, - {"7.2", "Column types"}, - {"7.2.1", "Column type storage requirements"}, - {"7.2.5", "Numeric types"}, - {"7.2.6", "Date and time types"}, - {"7.2.6.1", "The DATE type"}, - {"7.2.6.2", "The TIME type"}, - {"7.2.6.3", "The DATETIME type"}, - {"7.2.6.4", "The TIMESTAMP type"}, - {"7.2.6.5", "The YEAR type"}, - {"7.2.6.6", "Miscellaneous date and time properties"}, - {"7.2.7", "String types"}, - {"7.2.7.1", "The CHAR and VARCHAR types"}, - {"7.2.7.2", "The BLOB and TEXT types"}, - {"7.2.7.3", "The ENUM type"}, - {"7.2.7.4", "The SET type"}, - {"7.2.8", "Choosing the right type for a column"}, - {"7.2.9", "Column indexes"}, - {"7.2.10", "Multiple-column indexes"}, - {"7.2.11", "Using column types from other database engines"}, - {"7.3", "Functions for use in SELECT and WHERE clauses"}, - {"7.3.1", "Grouping functions"}, - {"7.3.2", "Normal arithmetic operations"}, - {"7.3.3", "Bit functions"}, - {"7.3.4", "Logical operations"}, - {"7.3.5", "Comparison operators"}, - {"7.3.6", "String comparison functions"}, - {"7.3.7", "Control flow functions"}, - {"7.3.8", "Mathematical functions"}, - {"7.3.9", "String functions"}, - {"7.3.10", "Date and time functions"}, - {"7.3.11", "Miscellaneous functions"}, - {"7.3.12", "Functions for use with GROUP BY clauses"}, - {"7.4", "CREATE DATABASE syntax"}, - {"7.5", "DROP DATABASE syntax"}, - {"7.6", "CREATE TABLE syntax"}, - {"7.7", "ALTER TABLE syntax"}, - {"7.8", "OPTIMIZE TABLE syntax"}, - {"7.9", "DROP TABLE syntax"}, - {"7.10", "DELETE syntax"}, - {"7.11", "SELECT syntax"}, - {"7.12", "JOIN syntax"}, - {"7.13", "INSERT syntax"}, - {"7.14", "REPLACE syntax"}, - {"7.15", "LOAD DATA INFILE syntax"}, - {"7.16", "UPDATE syntax"}, - {"7.17", "USE syntax"}, - {"7.18", "SHOW syntax (Get information about tables, columns...)"}, - {"7.19", "EXPLAIN syntax (Get information about a SELECT)"}, - {"7.20", "DESCRIBE syntax (Get information about columns)"}, - {"7.21", "LOCK TABLES/UNLOCK TABLES syntax"}, - {"7.22", "SET OPTION syntax"}, - {"7.23", "GRANT syntax (Compatibility function)"}, - {"7.24", "CREATE INDEX syntax (Compatibility function)"}, - {"7.25", "DROP INDEX syntax (Compatibility function)"}, - {"7.26", "Comment syntax"}, - {"7.27", "CREATE FUNCTION/DROP FUNCTION syntax"}, - {"7.28", "Is MySQL picky about reserved words?"}, - {"8", "Example SQL queries"}, - {"8.1", "Queries from twin project"}, - {"8.1.1", "Find all non-distributed twins"}, - {"8.1.2", "Show a table on twin pair status"}, - {"9", "How safe/stable is MySQL?"}, - {"9.1", "How stable is MySQL?"}, - {"9.2", "Why are there is so many releases of MySQL?"}, - {"9.3", "Checking a table for errors"}, - {"9.4", "How to repair tables"}, - {"9.5", "Is there anything special to do when upgrading/downgrading MySQL?"}, - {"9.5.1", "Upgrading from a 3.21 version to 3.22"}, - {"9.5.2", "Upgrading from a 3.20 version to 3.21"}, - {"9.5.3", "Upgrading to another architecture"}, - {"9.6", "Year 2000 compliance"}, - {"10", "MySQL Server functions"}, - {"10.1", "What languages are supported by MySQL?"}, - {"10.1.1", "Character set used for data & sorting"}, - {"10.2", "The update log"}, - {"10.3", "How big can MySQL tables be?"}, - {"11", "Getting maximum performance from MySQL"}, - {"11.1", "How does one change the size of MySQL buffers?"}, - {"11.2", "How compiling and linking affects the speed of MySQL"}, - {"11.3", "How does MySQL use memory?"}, - {"11.4", "How does MySQL use indexes?"}, - {"11.5", "What optimizations are done on WHERE clauses?"}, - {"11.6", "How does MySQL open & close tables?"}, - {"11.6.0.1", "What are the drawbacks of creating possibly thousands of tables in a database?"}, - {"11.7", "How does MySQL lock tables?"}, - {"11.8", "How should I arrange my table to be as fast/small as possible?"}, - {"11.9", "What affects the speed of INSERT statements?"}, - {"11.10", "What affects the speed DELETE statements?"}, - {"11.11", "How do I get MySQL to run at full speed?"}, - {"11.12", "What are the different row formats? Or, when should VARCHAR/CHAR be used?"}, - {"11.13", "Why so many open tables?"}, - {"12", "MySQL benchmark suite"}, - {"13", "MySQL Utilites"}, - {"13.1", "Overview of the different MySQL programs"}, - {"13.2", "The MySQL table check, optimize and repair program"}, - {"13.2.1", "isamchk memory use"}, - {"13.2.2", "Getting low-level table information"}, - {"13.3", "The MySQL compressed read-only table generator"}, - {"14", "Adding new functions to MySQL"}, - {"15", "MySQL ODBC Support"}, - {"15.1", "Operating systems supported by MyODBC"}, - {"15.2", "How to report problems with MyODBC"}, - {"15.3", "Programs known to work with MyODBC"}, - {"15.4", "How to fill in the various fields in the ODBC administrator program"}, - {"15.5", "How to get the value of an AUTO_INCREMENT column in ODBC"}, - {"16", "Problems and common errors"}, - {"16.1", "Some common errors when using MySQL"}, - {"16.1.1", "MySQL server has gone away error"}, - {"16.1.2", "Can't connect to local MySQL server error"}, - {"16.1.3", "Out of memory error"}, - {"16.1.4", "Packet too large error"}, - {"16.1.5", "The table is full error"}, - {"16.1.6", "Commands out of sync error in client"}, - {"16.1.7", "Removing user error"}, - {"16.2", "How MySQL handles a full disk"}, - {"16.3", "How to run SQL commands from a text file"}, - {"16.4", "Where MySQL stores temporary files"}, - {"16.5", "Access denied error"}, - {"16.6", "How to run MySQL as a normal user"}, - {"16.7", "Problems with file permissions"}, - {"16.8", "File not found"}, - {"16.9", "Problems using DATE columns"}, - {"16.10", "Case sensitivity in searches"}, - {"16.11", "Problems with NULL values"}, - {"17", "Solving some common problems with MySQL"}, - {"17.1", "Database replication"}, - {"17.2", "Database backups"}, - {"18", "MySQL client tools and API's"}, - {"18.1", "MySQL C API"}, - {"18.2", "C API datatypes"}, - {"18.3", "C API function overview"}, - {"18.4", "C API function descriptions"}, - {"18.4.1", "mysql_affected_rows()"}, - {"18.4.2", "mysql_close()"}, - {"18.4.3", "mysql_connect()"}, - {"18.4.4", "mysql_create_db()"}, - {"18.4.5", "mysql_data_seek()"}, - {"18.4.6", "mysql_debug()"}, - {"18.4.7", "mysql_drop_db()"}, - {"18.4.8", "mysql_dump_debug_info()"}, - {"18.4.9", "mysql_eof()"}, - {"18.4.10", "mysql_errno()"}, - {"18.4.11", "mysql_error()"}, - {"18.4.12", "mysql_escape_string()"}, - {"18.4.13", "mysql_fetch_field()"}, - {"18.4.14", "mysql_fetch_fields()"}, - {"18.4.15", "mysql_fetch_field_direct()"}, - {"18.4.16", "mysql_fetch_lengths()"}, - {"18.4.17", "mysql_fetch_row()"}, - {"18.4.18", "mysql_field_seek()"}, - {"18.4.19", "mysql_field_tell()"}, - {"18.4.20", "mysql_free_result()"}, - {"18.4.21", "mysql_get_client_info()"}, - {"18.4.22", "mysql_get_host_info()"}, - {"18.4.23", "mysql_get_proto_info()"}, - {"18.4.24", "mysql_get_server_info()"}, - {"18.4.25", "mysql_info()"}, - {"18.4.26", "mysql_init()"}, - {"18.4.27", "mysql_insert_id()"}, - {"18.4.28", "mysql_kill()"}, - {"18.4.29", "mysql_list_dbs()"}, - {"18.4.30", "mysql_list_fields()"}, - {"18.4.31", "mysql_list_processes()"}, - {"18.4.32", "mysql_list_tables()"}, - {"18.4.33", "mysql_num_fields()"}, - {"18.4.34", "mysql_num_rows()"}, - {"18.4.35", "mysql_query()"}, - {"18.4.36", "mysql_real_connect()"}, - {"18.4.37", "mysql_real_query()"}, - {"18.4.38", "mysql_reload()"}, - {"18.4.39", "mysql_row_tell()"}, - {"18.4.40", "mysql_select_db()"}, - {"18.4.41", "mysql_shutdown()"}, - {"18.4.42", "mysql_stat()"}, - {"18.4.43", "mysql_store_result()"}, - {"18.4.44", "mysql_thread_id()"}, - {"18.4.45", "mysql_use_result()"}, - {"18.4.46", "Why is it that after mysql_query() returns success, mysql_store_result() sometimes returns NULL?"}, - {"18.4.47", "What results can I get from a query?"}, - {"18.4.48", "How can I get the unique ID for the last inserted row?"}, - {"18.4.49", "Problems linking with the C API"}, - {"18.4.50", "How to make a thread-safe client"}, - {"18.5", "MySQL Perl API's"}, - {"18.5.1", "DBI with DBD::mysql"}, - {"18.5.1.1", "The DBI interface"}, - {"18.5.1.2", "More DBI/DBD information"}, - {"18.6", "MySQL Java connectivity (JDBC)"}, - {"18.7", "MySQL PHP API's"}, - {"18.8", "MySQL C++ API's"}, - {"18.9", "MySQL Python API's"}, - {"18.10", "MySQL TCL API's"}, - {"19", "How MySQL compares to other databases"}, - {"19.1", "How MySQL compares to mSQL"}, - {"19.1.1", "How to convert mSQL tools for MySQL"}, - {"19.1.2", "How mSQL and MySQL client/server communications protocols differ"}, - {"19.1.3", "How mSQL 2.0 SQL syntax differs from MySQL"}, - {"19.2", "How MySQL compares to PostgreSQL"}, - {"A", "Some users of MySQL"}, - {"B", "Contributed programs"}, - {"C", "Contributors to MySQL"}, - {"D", "MySQL change history"}, - {"19.3", "Changes in release 3.22.x (Alpha version)"}, - {"19.3.1", "Changes in release 3.22.7"}, - {"19.3.2", "Changes in release 3.22.6"}, - {"19.3.3", "Changes in release 3.22.5"}, - {"19.3.4", "Changes in release 3.22.4"}, - {"19.3.5", "Changes in release 3.22.3"}, - {"19.3.6", "Changes in release 3.22.2"}, - {"19.3.7", "Changes in release 3.22.1"}, - {"19.3.8", "Changes in release 3.22.0"}, - {"19.4", "Changes in release 3.21.x"}, - {"19.4.1", "Changes in release 3.21.33"}, - {"19.4.2", "Changes in release 3.21.32"}, - {"19.4.3", "Changes in release 3.21.31"}, - {"19.4.4", "Changes in release 3.21.30"}, - {"19.4.5", "Changes in release 3.21.29"}, - {"19.4.6", "Changes in release 3.21.28"}, - {"19.4.7", "Changes in release 3.21.27"}, - {"19.4.8", "Changes in release 3.21.26"}, - {"19.4.9", "Changes in release 3.21.25"}, - {"19.4.10", "Changes in release 3.21.24"}, - {"19.4.11", "Changes in release 3.21.23"}, - {"19.4.12", "Changes in release 3.21.22"}, - {"19.4.13", "Changes in release 3.21.21a"}, - {"19.4.14", "Changes in release 3.21.21"}, - {"19.4.15", "Changes in release 3.21.20"}, - {"19.4.16", "Changes in release 3.21.19"}, - {"19.4.17", "Changes in release 3.21.18"}, - {"19.4.18", "Changes in release 3.21.17"}, - {"19.4.19", "Changes in release 3.21.16"}, - {"19.4.20", "Changes in release 3.21.15"}, - {"19.4.21", "Changes in release 3.21.14b"}, - {"19.4.22", "Changes in release 3.21.14a"}, - {"19.4.23", "Changes in release 3.21.13"}, - {"19.4.24", "Changes in release 3.21.12"}, - {"19.4.25", "Changes in release 3.21.11"}, - {"19.4.26", "Changes in release 3.21.10"}, - {"19.4.27", "Changes in release 3.21.9"}, - {"19.4.28", "Changes in release 3.21.8"}, - {"19.4.29", "Changes in release 3.21.7"}, - {"19.4.30", "Changes in release 3.21.6"}, - {"19.4.31", "Changes in release 3.21.5"}, - {"19.4.32", "Changes in release 3.21.4"}, - {"19.4.33", "Changes in release 3.21.3"}, - {"19.4.34", "Changes in release 3.21.2"}, - {"19.4.35", "Changes in release 3.21.0"}, - {"19.5", "Changes in release 3.20.x"}, - {"19.5.1", "Changes in release 3.20.18"}, - {"19.5.2", "Changes in release 3.20.17"}, - {"19.5.3", "Changes in release 3.20.16"}, - {"19.5.4", "Changes in release 3.20.15"}, - {"19.5.5", "Changes in release 3.20.14"}, - {"19.5.6", "Changes in release 3.20.13"}, - {"19.5.7", "Changes in release 3.20.11"}, - {"19.5.8", "Changes in release 3.20.10"}, - {"19.5.9", "Changes in release 3.20.9"}, - {"19.5.10", "Changes in release 3.20.8"}, - {"19.5.11", "Changes in release 3.20.7"}, - {"19.5.12", "Changes in release 3.20.6"}, - {"19.5.13", "Changes in release 3.20.3"}, - {"19.5.14", "Changes in release 3.20.0"}, - {"19.6", "Changes in release 3.19.x"}, - {"19.6.1", "Changes in release 3.19.5"}, - {"19.6.2", "Changes in release 3.19.4"}, - {"19.6.3", "Changes in release 3.19.3"}, - {"E", "Known errors and design deficiencies in MySQL"}, - {"F", "List of things we want to add to MySQL in the future (The TODO)"}, - {"19.7", "Things that must done in the real near future"}, - {"19.8", "Things that have to be done sometime"}, - {"19.9", "Some things we don't have any plans to do"}, - {"G", "Comments on porting to other systems"}, - {"19.10", "Debugging MySQL"}, - {"19.11", "Comments about RTS threads"}, - {"19.12", "What is the difference between different thread packages?"}, - {"H", "Description of MySQL regular expression syntax"}, - {"I", "What is Unireg?"}, - {"J", "The MySQL server license"}, - {"K", "The MySQL license for Microsoft operating systems"}, - {"*", "SQL command, type and function index"}, - {"*", "Concept Index"} -}; - -#define NQUERIES 5 -const char *query[NQUERIES]={ - "mysql information and manual", - "upgrading from previous version", - "column indexes", - "against about after more right the with/without", /* stopwords test */ - "mysql license and copyright" -}; diff --git a/storage/myisam/ft_update.c b/storage/myisam/ft_update.c index d1548e32870..a2ddb49ecf0 100644 --- a/storage/myisam/ft_update.c +++ b/storage/myisam/ft_update.c @@ -83,8 +83,7 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi) if (ftsi->seg->flag & HA_BLOB_PART) { ftsi->len=_mi_calc_blob_length(ftsi->seg->bit_start,ftsi->pos); - memcpy_fixed((char*) &ftsi->pos, ftsi->pos+ftsi->seg->bit_start, - sizeof(char*)); + memcpy(&ftsi->pos, ftsi->pos+ftsi->seg->bit_start, sizeof(char*)); DBUG_RETURN(1); } ftsi->len=ftsi->seg->length; diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 12557b75cc1..2ba62d03c6b 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 @@ -19,8 +19,10 @@ #endif #define MYSQL_SERVER 1 -#include "mysql_priv.h" -#include <mysql/plugin.h> +#include "sql_priv.h" +#include "probes_mysql.h" +#include "key.h" // key_copy +#include "sql_plugin.h" #include <m_ctype.h> #include <my_bit.h> #include <myisampack.h> @@ -28,12 +30,15 @@ #include <stdarg.h> #include "myisamdef.h" #include "rt_index.h" +#include "sql_table.h" // tablename_to_filename +#include "sql_class.h" // THD -ulong myisam_recover_options= HA_RECOVER_NONE; +ulonglong myisam_recover_options; +static ulong opt_myisam_block_size; /* bits in myisam_recover_options */ const char *myisam_recover_names[] = -{ "DEFAULT", "BACKUP", "FORCE", "QUICK", NullS}; +{ "DEFAULT", "BACKUP", "FORCE", "QUICK", "OFF", NullS}; TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"", myisam_recover_names, NULL}; @@ -43,6 +48,54 @@ TYPELIB myisam_stats_method_typelib= { array_elements(myisam_stats_method_names) - 1, "", myisam_stats_method_names, NULL}; +static MYSQL_SYSVAR_ULONG(block_size, opt_myisam_block_size, + PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_RQCMDARG, + "Block size to be used for MyISAM index pages", NULL, NULL, + MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, MI_MAX_KEY_BLOCK_LENGTH, + MI_MIN_KEY_BLOCK_LENGTH); + +static MYSQL_SYSVAR_ULONG(data_pointer_size, myisam_data_pointer_size, + PLUGIN_VAR_RQCMDARG, "Default pointer size to be used for MyISAM tables", + NULL, NULL, 6, 2, 7, 1); + +#define MB (1024*1024) +static MYSQL_SYSVAR_ULONGLONG(max_sort_file_size, myisam_max_temp_length, + PLUGIN_VAR_RQCMDARG, "Don't use the fast sort index method to created " + "index if the temporary file would get bigger than this", NULL, NULL, + LONG_MAX/MB*MB, 0, MAX_FILE_SIZE, MB); + +static MYSQL_SYSVAR_SET(recover_options, myisam_recover_options, + PLUGIN_VAR_OPCMDARG|PLUGIN_VAR_READONLY, + "Syntax: myisam-recover-options[=option[,option...]], where option can be " + "DEFAULT, BACKUP, FORCE, QUICK, or OFF", + NULL, NULL, 0, &myisam_recover_typelib); + +static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG, + "If larger than 1, when repairing a MyISAM table all indexes will be " + "created in parallel, with one thread per index. The value of 1 " + "disables parallel repair", NULL, NULL, + 1, 1, ULONG_MAX, 1); + +static MYSQL_THDVAR_ULONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG, + "The buffer that is allocated when sorting the index when doing " + "a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE", NULL, NULL, + 8192*1024, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), ULONG_MAX, 1); + +static MYSQL_SYSVAR_BOOL(use_mmap, opt_myisam_use_mmap, PLUGIN_VAR_NOCMDARG, + "Use memory mapping for reading and writing MyISAM tables", NULL, NULL, FALSE); + +static MYSQL_SYSVAR_ULONGLONG(mmap_size, myisam_mmap_size, + PLUGIN_VAR_RQCMDARG|PLUGIN_VAR_READONLY, "Restricts the total memory " + "used for memory mapping of MySQL tables", NULL, NULL, + SIZE_T_MAX, MEMMAP_EXTRA_MARGIN, SIZE_T_MAX, 1); + +static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG, + "Specifies how MyISAM index statistics collection code should " + "treat NULLs. Possible values of name are NULLS_UNEQUAL (default " + "behavior for 4.1 and later), NULLS_EQUAL (emulate 4.0 behavior), " + "and NULLS_IGNORED", NULL, NULL, + MI_STATS_METHOD_NULLS_NOT_EQUAL, &myisam_stats_method_typelib); + #ifndef DBUG_OFF /** Causes the thread to wait in a spin lock for a query kill signal. @@ -117,7 +170,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); @@ -129,7 +182,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; } @@ -224,7 +277,7 @@ int table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out, keydef[i].seg[j].bit_start= keydef[i].seg[j].bit_end= keydef[i].seg[j].bit_length= 0; keydef[i].seg[j].bit_pos= 0; - keydef[i].seg[j].language= field->charset()->number; + keydef[i].seg[j].language= field->charset_for_protocol()->number; if (field->null_ptr) { @@ -538,6 +591,45 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...) va_end(args); } + +/** + Report list of threads (and queries) accessing a table, thread_id of a + thread that detected corruption, ource file name and line number where + this corruption was detected, optional extra information (string). + + This function is intended to be used when table corruption is detected. + + @param[in] file MI_INFO object. + @param[in] message Optional error message. + @param[in] sfile Name of source file. + @param[in] sline Line number in source file. + + @return void +*/ + +void _mi_report_crashed(MI_INFO *file, const char *message, + const char *sfile, uint sline) +{ + THD *cur_thd; + LIST *element; + char buf[1024]; + mysql_mutex_lock(&file->s->intern_lock); + if ((cur_thd= (THD*) file->in_use.data)) + sql_print_error("Got an error from thread_id=%lu, %s:%d", cur_thd->thread_id, + sfile, sline); + else + sql_print_error("Got an error from unknown thread, %s:%d", sfile, sline); + if (message) + sql_print_error("%s", message); + for (element= file->s->in_use; element; element= list_rest(element)) + { + THD *thd= (THD*) element->data; + sql_print_error("%s", thd ? thd_security_context(thd, buf, sizeof(buf), 0) + : "Unknown thread accessing table"); + } + mysql_mutex_unlock(&file->s->intern_lock); +} + } @@ -584,90 +676,6 @@ const char *ha_myisam::index_type(uint key_number) "BTREE"); } -#ifdef HAVE_REPLICATION -int ha_myisam::net_read_dump(NET* net) -{ - int data_fd = file->dfile; - int error = 0; - - my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)); - for (;;) - { - ulong packet_len = my_net_read(net); - if (!packet_len) - break ; // end of file - if (packet_len == packet_error) - { - sql_print_error("ha_myisam::net_read_dump - read error "); - error= -1; - goto err; - } - if (my_write(data_fd, (uchar*)net->read_pos, (uint) packet_len, - MYF(MY_WME|MY_FNABP))) - { - error = errno; - goto err; - } - } -err: - return error; -} - - -int ha_myisam::dump(THD* thd, int fd) -{ - MYISAM_SHARE* share = file->s; - NET* net = &thd->net; - uint blocksize = share->blocksize; - my_off_t bytes_to_read = share->state.state.data_file_length; - int data_fd = file->dfile; - uchar *buf = (uchar*) my_malloc(blocksize, MYF(MY_WME)); - if (!buf) - return ENOMEM; - - int error = 0; - my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME)); - for (; bytes_to_read > 0;) - { - size_t bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME)); - if (bytes == MY_FILE_ERROR) - { - error = errno; - goto err; - } - - if (fd >= 0) - { - if (my_write(fd, buf, bytes, MYF(MY_WME | MY_FNABP))) - { - error = errno ? errno : EPIPE; - goto err; - } - } - else - { - if (my_net_write(net, buf, bytes)) - { - error = errno ? errno : EPIPE; - goto err; - } - } - bytes_to_read -= bytes; - } - - if (fd < 0) - { - if (my_net_write(net, (uchar*) "", 0)) - error = errno ? errno : EPIPE; - net_flush(net); - } - -err: - my_free((uchar*) buf, MYF(0)); - return error; -} -#endif /* HAVE_REPLICATION */ - /* Name is here without an extension */ int ha_myisam::open(const char *name, int mode, uint test_if_locked) @@ -720,11 +728,11 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked) } if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE)) - VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0)); + (void) mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0); info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED)) - VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0)); + (void) mi_extra(file, HA_EXTRA_WAIT_LOCK, 0); if (!table->s->db_record_offset) int_table_flags|=HA_REC_NOT_IN_SEQ; if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) @@ -748,7 +756,7 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked) recinfo must be freed. */ if (recinfo) - my_free((uchar*) recinfo, MYF(0)); + my_free(recinfo); return my_errno; } @@ -795,7 +803,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) param.db_name= table->s->db.str; param.table_name= table->alias; param.testflag = check_opt->flags | T_CHECK | T_SILENT; - param.stats_method= (enum_mi_stats_method)thd->variables.myisam_stats_method; + param.stats_method= (enum_mi_stats_method)THDVAR(thd, stats_method); if (!(table->db_stat & HA_READ_ONLY)) param.testflag|= T_STATISTICS; @@ -845,13 +853,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); } @@ -887,7 +895,7 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | T_DONT_CHECK_CHECKSUM); param.using_global_keycache = 1; - param.stats_method= (enum_mi_stats_method)thd->variables.myisam_stats_method; + param.stats_method= (enum_mi_stats_method)THDVAR(thd, stats_method); if (!(share->state.changed & STATE_NOT_ANALYZED)) return HA_ADMIN_ALREADY_DONE; @@ -895,9 +903,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); @@ -905,113 +913,6 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) } -int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) -{ - HA_CHECK_OPT tmp_check_opt; - char *backup_dir= thd->lex->backup_dir; - char src_path[FN_REFLEN], dst_path[FN_REFLEN]; - char table_name[FN_REFLEN]; - int error; - const char* errmsg; - DBUG_ENTER("restore"); - - VOID(tablename_to_filename(table->s->table_name.str, table_name, - sizeof(table_name))); - - if (fn_format_relative_to_data_home(src_path, table_name, backup_dir, - MI_NAME_DEXT)) - DBUG_RETURN(HA_ADMIN_INVALID); - - strxmov(dst_path, table->s->normalized_path.str, MI_NAME_DEXT, NullS); - if (my_copy(src_path, dst_path, MYF(MY_WME))) - { - error= HA_ADMIN_FAILED; - errmsg= "Failed in my_copy (Error %d)"; - goto err; - } - - tmp_check_opt.init(); - tmp_check_opt.flags |= T_VERY_SILENT | T_CALC_CHECKSUM | T_QUICK; - DBUG_RETURN(repair(thd, &tmp_check_opt)); - - err: - { - MI_CHECK param; - myisamchk_init(¶m); - param.thd= thd; - param.op_name= "restore"; - param.db_name= table->s->db.str; - param.table_name= table->s->table_name.str; - param.testflag= 0; - mi_check_print_error(¶m, errmsg, my_errno); - DBUG_RETURN(error); - } -} - - -int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) -{ - char *backup_dir= thd->lex->backup_dir; - char src_path[FN_REFLEN], dst_path[FN_REFLEN]; - char table_name[FN_REFLEN]; - int error; - const char *errmsg; - DBUG_ENTER("ha_myisam::backup"); - - VOID(tablename_to_filename(table->s->table_name.str, table_name, - sizeof(table_name))); - - if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir, - reg_ext)) - { - errmsg= "Failed in fn_format() for .frm file (errno: %d)"; - error= HA_ADMIN_INVALID; - goto err; - } - - strxmov(src_path, table->s->normalized_path.str, reg_ext, NullS); - if (my_copy(src_path, dst_path, - MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE))) - { - error = HA_ADMIN_FAILED; - errmsg = "Failed copying .frm file (errno: %d)"; - goto err; - } - - /* Change extension */ - if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir, - MI_NAME_DEXT)) - { - errmsg = "Failed in fn_format() for .MYD file (errno: %d)"; - error = HA_ADMIN_INVALID; - goto err; - } - - strxmov(src_path, table->s->normalized_path.str, MI_NAME_DEXT, NullS); - if (my_copy(src_path, dst_path, - MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE))) - { - errmsg = "Failed copying .MYD file (errno: %d)"; - error= HA_ADMIN_FAILED; - goto err; - } - DBUG_RETURN(HA_ADMIN_OK); - - err: - { - MI_CHECK param; - myisamchk_init(¶m); - param.thd= thd; - param.op_name= "backup"; - param.db_name= table->s->db.str; - param.table_name= table->s->table_name.str; - param.testflag = 0; - mi_check_print_error(¶m,errmsg, my_errno); - DBUG_RETURN(error); - } -} - - int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { int error; @@ -1026,7 +927,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) param.testflag= ((check_opt->flags & ~(T_EXTEND)) | T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); - param.sort_buffer_length= check_opt->sort_buffer_size; + param.sort_buffer_length= THDVAR(thd, sort_buffer_size); start_records=file->state->records; while ((error=repair(thd,param,0)) && param.retry_repair) { @@ -1072,7 +973,7 @@ int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt) param.op_name= "optimize"; param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); - param.sort_buffer_length= check_opt->sort_buffer_size; + param.sort_buffer_length= THDVAR(thd, sort_buffer_size); if ((error= repair(thd,param,1)) && param.retry_repair) { sql_print_warning("Warning: Optimize table got errno %d on %s.%s, retrying", @@ -1108,7 +1009,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool do_optimize) ha_release_temporary_latches(thd); // Don't lock tables if we have used LOCK TABLE - if (!thd->locked_tables && + if (! thd->locked_tables_mode && mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) { mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); @@ -1130,7 +1031,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool do_optimize) local_testflag|= T_STATISTICS; param.testflag|= T_STATISTICS; // We get this for free statistics_done=1; - if (thd->variables.myisam_repair_threads>1) + if (THDVAR(thd, repair_threads)>1) { char buf[40]; /* TODO: respect myisam_repair_threads variable */ @@ -1218,7 +1119,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool do_optimize) update_state_info(¶m, file, 0); } thd_proc_info(thd, old_proc_info); - if (!thd->locked_tables) + if (! thd->locked_tables_mode) mi_lock_database(file,F_UNLCK); DBUG_RETURN(error ? HA_ADMIN_FAILED : !optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK); @@ -1441,8 +1342,8 @@ int ha_myisam::enable_indexes(uint mode) param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | T_CREATE_MISSING_KEYS); param.myf_rw&= ~MY_WAIT_IF_FULL; - param.sort_buffer_length= thd->variables.myisam_sort_buff_size; - param.stats_method= (enum_mi_stats_method)thd->variables.myisam_stats_method; + param.sort_buffer_length= THDVAR(thd, sort_buffer_size); + param.stats_method= (enum_mi_stats_method)THDVAR(thd, stats_method); param.tmpdir=&mysql_tmpdir_list; if ((error= (repair(thd,param,0) != HA_ADMIN_OK)) && param.retry_repair) { @@ -1654,10 +1555,12 @@ int ha_myisam::index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_key_count); int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } @@ -1665,57 +1568,69 @@ int ha_myisam::index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); ha_statistic_increment(&SSV::ha_read_key_count); int error=mi_rkey(file, buf, index, key, keypart_map, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } int ha_myisam::index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ENTER("ha_myisam::index_read_last"); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_key_count); int error=mi_rkey(file, buf, active_index, key, keypart_map, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); DBUG_RETURN(error); } int ha_myisam::index_next(uchar *buf) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_next_count); int error=mi_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } int ha_myisam::index_prev(uchar *buf) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_prev_count); int error=mi_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } int ha_myisam::index_first(uchar *buf) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_first_count); int error=mi_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } int ha_myisam::index_last(uchar *buf) { + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); DBUG_ASSERT(inited==INDEX); ha_statistic_increment(&SSV::ha_read_last_count); int error=mi_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } @@ -1725,12 +1640,14 @@ int ha_myisam::index_next_same(uchar *buf, { int error; DBUG_ASSERT(inited==INDEX); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); ha_statistic_increment(&SSV::ha_read_next_count); do { error= mi_rnext_same(file,buf); } while (error == HA_ERR_RECORD_DELETED); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_INDEX_READ_ROW_DONE(error); return error; } @@ -1744,9 +1661,12 @@ int ha_myisam::rnd_init(bool scan) int ha_myisam::rnd_next(uchar *buf) { + MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str, + TRUE); ha_statistic_increment(&SSV::ha_read_rnd_next_count); int error=mi_scan(file, buf); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_READ_ROW_DONE(error); return error; } @@ -1757,9 +1677,12 @@ int ha_myisam::restart_rnd_next(uchar *buf, uchar *pos) int ha_myisam::rnd_pos(uchar *buf, uchar *pos) { + MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str, + FALSE); ha_statistic_increment(&SSV::ha_read_rnd_count); int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length)); table->status=error ? STATUS_NOT_FOUND: 0; + MYSQL_READ_ROW_DONE(error); return error; } @@ -1797,7 +1720,7 @@ int ha_myisam::info(uint flag) /* Update share */ if (share->tmp_table == NO_TMP_TABLE) - pthread_mutex_lock(&share->mutex); + mysql_mutex_lock(&share->LOCK_ha_data); share->keys_in_use.set_prefix(share->keys); share->keys_in_use.intersect_extended(misam_info.key_map); share->keys_for_keyread.intersect(share->keys_in_use); @@ -1807,7 +1730,7 @@ int ha_myisam::info(uint flag) (char*) misam_info.rec_per_key, sizeof(table->key_info[0].rec_per_key[0])*share->key_parts); if (share->tmp_table == NO_TMP_TABLE) - pthread_mutex_unlock(&share->mutex); + mysql_mutex_unlock(&share->LOCK_ha_data); /* Set data_file_name and index_file_name to point at the symlink value @@ -1865,6 +1788,18 @@ int ha_myisam::delete_all_rows() return mi_delete_all_rows(file); } + +/* + Intended to support partitioning. + Allows a particular partition to be truncated. +*/ + +int ha_myisam::truncate() +{ + int error= delete_all_rows(); + return error ? error : reset_auto_increment(0); +} + int ha_myisam::reset_auto_increment(ulonglong value) { file->s->state.auto_increment= value; @@ -1879,6 +1814,7 @@ int ha_myisam::delete_table(const char *name) int ha_myisam::external_lock(THD *thd, int lock_type) { + file->in_use.data= thd; return mi_lock_database(file, !table->s->tmp_table ? lock_type : ((lock_type == F_UNLCK) ? F_UNLCK : F_EXTRA_LCK)); @@ -1959,7 +1895,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, records, recinfo, 0, (MI_UNIQUEDEF*) 0, &create_info, create_flags); - my_free((uchar*) recinfo, MYF(0)); + my_free(recinfo); DBUG_RETURN(error); } @@ -2102,6 +2038,18 @@ static int myisam_init(void *p) { handlerton *myisam_hton; +#ifdef HAVE_PSI_INTERFACE + init_myisam_psi_keys(); +#endif + + /* Set global variables based on startup options */ + if (myisam_recover_options) + ha_open_options|=HA_OPEN_ABORT_IF_CRASHED; + else + myisam_recover_options= HA_RECOVER_OFF; + + myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size); + myisam_hton= (handlerton *)p; myisam_hton->state= SHOW_OPTION_YES; myisam_hton->db_type= DB_TYPE_MYISAM; @@ -2111,6 +2059,19 @@ static int myisam_init(void *p) return 0; } +static struct st_mysql_sys_var* myisam_sysvars[]= { + MYSQL_SYSVAR(block_size), + MYSQL_SYSVAR(data_pointer_size), + MYSQL_SYSVAR(max_sort_file_size), + MYSQL_SYSVAR(recover_options), + MYSQL_SYSVAR(repair_threads), + MYSQL_SYSVAR(sort_buffer_size), + MYSQL_SYSVAR(use_mmap), + MYSQL_SYSVAR(mmap_size), + MYSQL_SYSVAR(stats_method), + 0 +}; + struct st_mysql_storage_engine myisam_storage_engine= { MYSQL_HANDLERTON_INTERFACE_VERSION }; @@ -2120,14 +2081,14 @@ mysql_declare_plugin(myisam) &myisam_storage_engine, "MyISAM", "MySQL AB", - "Default engine as of MySQL 3.23 with great performance", + "MyISAM storage engine", PLUGIN_LICENSE_GPL, myisam_init, /* Plugin Init */ NULL, /* Plugin Deinit */ 0x0100, /* 1.0 */ NULL, /* status variables */ - NULL, /* system variables */ - NULL /* config options */ + myisam_sysvars, /* system variables */ + NULL } mysql_declare_plugin_end; diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index 55a5eac92de..46b732512ac 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 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 @@ -11,7 +11,7 @@ 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 */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef USE_PRAGMA_INTERFACE @@ -22,16 +22,22 @@ #include <myisam.h> #include <ft_global.h> +#include "handler.h" /* handler */ +#include "table.h" /* TABLE_SHARE */ + +struct TABLE_SHARE; +typedef struct st_ha_create_information HA_CREATE_INFO; -#define HA_RECOVER_NONE 0 /* No automatic recover */ #define HA_RECOVER_DEFAULT 1 /* Automatic recover active */ #define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */ #define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */ #define HA_RECOVER_QUICK 8 /* Don't check rows in data file */ +#define HA_RECOVER_OFF 16 /* No automatic recover */ extern ulong myisam_sort_buffer_size; extern TYPELIB myisam_recover_typelib; -extern ulong myisam_recover_options; +extern const char *myisam_recover_names[]; +extern ulonglong myisam_recover_options; class ha_myisam: public handler { @@ -101,6 +107,7 @@ class ha_myisam: public handler int reset(void); int external_lock(THD *thd, int lock_type); int delete_all_rows(void); + int truncate(); int reset_auto_increment(ulonglong value); int disable_indexes(uint mode); int enable_indexes(uint mode); @@ -123,17 +130,11 @@ class ha_myisam: public handler int repair(THD* thd, HA_CHECK_OPT* check_opt); bool check_and_repair(THD *thd); bool is_crashed() const; - bool auto_repair() const { return myisam_recover_options != 0; } + bool auto_repair() const { return myisam_recover_options != HA_RECOVER_OFF; } int optimize(THD* thd, HA_CHECK_OPT* check_opt); - int restore(THD* thd, HA_CHECK_OPT* check_opt); - int backup(THD* thd, HA_CHECK_OPT* check_opt); int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt); int preload_keys(THD* thd, HA_CHECK_OPT* check_opt); bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); -#ifdef HAVE_REPLICATION - int dump(THD* thd, int fd); - int net_read_dump(NET* net); -#endif #ifdef HAVE_QUERY_CACHE my_bool register_query_cache_table(THD *thd, char *table_key, uint key_length, diff --git a/storage/myisam/make-ccc b/storage/myisam/make-ccc deleted file mode 100755 index 6d1303729db..00000000000 --- a/storage/myisam/make-ccc +++ /dev/null @@ -1,5 +0,0 @@ -rm -f .deps/*.P -ccc -DMAP_TO_USE_RAID -I./../include -I../include -DDBUG_OFF -fast -O3 -c mi_cache.c mi_changed.c mi_checksum.c mi_close.c mi_create.c mi_dbug.c mi_delete.c mi_delete_all.c mi_delete_table.c mi_dynrec.c mi_extra.c mi_info.c mi_key.c mi_locking.c mi_log.c mi_open.c mi_packrec.c mi_page.c mi_panic.c mi_range.c mi_rename.c mi_rfirst.c mi_rkey.c mi_rlast.c mi_rnext.c mi_rnext_same.c mi_rprev.c mi_rrnd.c mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c mi_unique.c mi_update.c mi_write.c ft_update.c ft_search.o ft_stem.o ft_stopwords.c ft_parser.c -make sort.o mi_check.o -rm libmyisam.a -ar -cr libmyisam.a mi_cache.o sort.o mi_check.o 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_changed.c b/storage/myisam/mi_changed.c index 7422f995dd0..049974e4a65 100644 --- a/storage/myisam/mi_changed.c +++ b/storage/myisam/mi_changed.c @@ -25,7 +25,7 @@ int mi_is_changed(MI_INFO *info) DBUG_ENTER("mi_is_changed"); if (fast_mi_readinfo(info)) DBUG_RETURN(-1); - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); result=(int) info->data_changed; info->data_changed=0; DBUG_PRINT("exit",("result: %d",result)); diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 8e3864d1c44..6bf01cd63c7 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 @@ -52,11 +52,6 @@ #endif #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) -#endif - /* Functions defined in this file */ static int check_k_link(MI_CHECK *param, MI_INFO *info,uint nr); @@ -175,8 +170,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 +333,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 +357,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 +593,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, @@ -1184,8 +1179,8 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) goto err; start_recpos=pos; splits++; - VOID(_mi_pack_get_block_info(info, &info->bit_buff, &block_info, - &info->rec_buff, -1, start_recpos)); + (void) _mi_pack_get_block_info(info, &info->bit_buff, &block_info, + &info->rec_buff, -1, start_recpos); pos=block_info.filepos+block_info.rec_len; if (block_info.rec_len < (uint) info->s->min_pack_length || block_info.rec_len > (uint) info->s->max_pack_length) @@ -1222,7 +1217,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) records++; if (param->testflag & T_WRITE_LOOP && records % WRITE_COUNT == 0) { - printf("%s\r", llstr(records,llbuff)); VOID(fflush(stdout)); + printf("%s\r", llstr(records,llbuff)); (void) fflush(stdout); } /* Check if keys match the record */ @@ -1275,7 +1270,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) } if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } if (records != info->state->records) { @@ -1369,12 +1364,12 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) printf("Lost space: %12s Linkdata: %10s\n", llstr(empty,llbuff),llstr(link_used,llbuff2)); } - my_free(mi_get_rec_buff_ptr(info, record), MYF(0)); + my_free(mi_get_rec_buff_ptr(info, record)); DBUG_RETURN (error); err: mi_check_print_error(param,"got error: %d when reading datafile at record: %s",my_errno, llstr(records,llbuff)); err2: - my_free(mi_get_rec_buff_ptr(info, record), MYF(0)); + my_free(mi_get_rec_buff_ptr(info, record)); param->testflag|=T_RETRY_WITHOUT_QUICK; DBUG_RETURN(1); } /* chk_data_link */ @@ -1551,8 +1546,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, DBUG_ASSERT(param->use_buffers < SIZE_T_MAX); if (!param->using_global_keycache) - VOID(init_key_cache(dflt_key_cache, param->key_cache_block_size, - (size_t) param->use_buffers, 0, 0)); + (void) init_key_cache(dflt_key_cache, param->key_cache_block_size, + param->use_buffers, 0, 0); if (init_io_cache(¶m->read_cache,info->dfile, (uint) param->read_buffer_length, @@ -1577,14 +1572,12 @@ 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= mysql_file_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_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); @@ -1608,7 +1601,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; @@ -1645,8 +1638,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, llstr(info->dupp_key_pos,llbuff2)); if (param->testflag & T_VERBOSE) { - VOID(_mi_make_key(info,(uint) info->errkey,info->lastkey, - sort_param.record,0L)); + (void) _mi_make_key(info,(uint) info->errkey,info->lastkey, + sort_param.record,0L); _mi_print_key(stdout,share->keyinfo[info->errkey].seg,info->lastkey, USE_WHOLE_KEY); } @@ -1668,9 +1661,9 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (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 +1693,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,10 +1726,24 @@ 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, + /* + On Windows, the old data file cannot be deleted if it is either + open, or memory mapped. Closing the file won't remove the memory + map implicilty on Windows. We closed the data file, but we keep + the MyISAM table open. A memory map will be closed on the final + mi_close() only. So we need to unmap explicitly here. After + renaming the new file under the hook, we couldn't use the map of + the old file any more anyway. + */ + if (info->s->file_map) + { + (void) my_munmap((char*) info->s->file_map, + (size_t) info->s->mmaped_length); + info->s->file_map= NULL; + } + if (change_to_newfile(share->data_file_name, MI_NAME_DEXT, DATA_TMP_EXT, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) || mi_open_datafile(info,share,name,-1)) @@ -1750,21 +1757,19 @@ 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) mysql_file_delete(mi_key_file_datatmp, + param->temp_filename, MYF(MY_WME)); info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */ } mi_mark_crashed_on_repair(info); } - my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff), - MYF(MY_ALLOW_ZERO_PTR)); - my_free(mi_get_rec_buff_ptr(info, sort_param.record), - MYF(MY_ALLOW_ZERO_PTR)); - my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff)); + my_free(mi_get_rec_buff_ptr(info, sort_param.record)); + my_free(sort_info.buff); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); got_error|=flush_blocks(param, share->key_cache, share->kfile); if (!got_error && param->testflag & T_UNPACK) { @@ -1949,9 +1954,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,10 +1998,10 @@ 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))); - if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0, + (void) mysql_file_close(new_file, MYF(MY_WME)); + if (change_to_newfile(share->index_file_name, MI_NAME_IEXT, INDEX_TMP_EXT, MYF(0)) || mi_open_keyfile(share)) goto err2; @@ -2017,9 +2024,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 +2107,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; @@ -2123,18 +2131,9 @@ err: */ int change_to_newfile(const char * filename, const char * old_ext, - const char * new_ext, - uint raid_chunks __attribute__((unused)), - myf MyFlags) + const char * new_ext, myf MyFlags) { char old_filename[FN_REFLEN],new_filename[FN_REFLEN]; -#ifdef USE_RAID - if (raid_chunks) - return my_raid_redel(fn_format(old_filename,filename,"",old_ext,2+4), - fn_format(new_filename,filename,"",new_ext,2+4), - raid_chunks, - MYF(MY_WME | MY_LINK_WARNING | MyFlags)); -#endif /* Get real path to filename */ (void) fn_format(old_filename,filename,"",old_ext,2+4+32); return my_redel(old_filename, @@ -2176,23 +2175,23 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, buff=tmp_buff; buff_length=IO_SIZE; } - VOID(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)); + my_free(buff); DBUG_RETURN(0); err: if (buff != tmp_buff) - my_free(buff,MYF(0)); + my_free(buff); mi_check_print_error(param,"Can't copy %s to tempfile, error %d", type,my_errno); DBUG_RETURN(1); @@ -2275,14 +2274,12 @@ 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= mysql_file_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_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); @@ -2320,7 +2317,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); @@ -2469,7 +2466,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; @@ -2485,7 +2482,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } if (rep_quick && del+sort_info.dupp != info->state->del) @@ -2508,8 +2505,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, skr < share->base.reloc*share->base.min_pack_length) 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 (skr != sort_info.filelength) + 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); @@ -2517,7 +2514,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); @@ -2538,16 +2535,15 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, err: got_error|= flush_blocks(param, share->key_cache, share->kfile); - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); if (!got_error) { /* 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, + if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, DATA_TMP_EXT, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) || mi_open_datafile(info,share,name,-1)) @@ -2560,9 +2556,9 @@ 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) mysql_file_delete(mi_key_file_datatmp, + param->temp_filename, 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 */ @@ -2573,14 +2569,12 @@ err: share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS; share->state.changed|=STATE_NOT_SORTED_PAGES; - my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff), - MYF(MY_ALLOW_ZERO_PTR)); - my_free(mi_get_rec_buff_ptr(info, sort_param.record), - MYF(MY_ALLOW_ZERO_PTR)); - my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR)); - my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR)); - my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff)); + my_free(mi_get_rec_buff_ptr(info, sort_param.record)); + my_free(sort_info.key_block); + my_free(sort_info.ft_buf); + my_free(sort_info.buff); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); if (!got_error && (param->testflag & T_UNPACK)) { @@ -2703,9 +2697,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= @@ -2731,15 +2727,12 @@ 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= mysql_file_create(mi_key_file_datatmp, + fn_format(param->temp_filename, + share->data_file_name, "", + DATA_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); @@ -2776,7 +2769,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); @@ -2902,7 +2895,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 @@ -2950,9 +2943,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. */ @@ -2968,8 +2962,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))) { @@ -3005,7 +2999,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; @@ -3033,8 +3027,8 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, skr < share->base.reloc*share->base.min_pack_length) 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 (skr != sort_info.filelength) + 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); @@ -3042,7 +3036,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); @@ -3067,7 +3061,7 @@ err: the share by remove_io_thread() or it was not yet started (if the error happend before creating the thread). */ - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); /* Destroy the new data cache in case of non-quick repair. All slave threads did either detach from the share by remove_io_thread() @@ -3075,16 +3069,15 @@ err: creating the threads). */ if (!rep_quick) - VOID(end_io_cache(&new_data_cache)); + (void) end_io_cache(&new_data_cache); if (!got_error) { /* 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, + if (change_to_newfile(share->data_file_name, MI_NAME_DEXT, DATA_TMP_EXT, (param->testflag & T_BACKUP_DATA ? MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) || mi_open_datafile(info,share,name,-1)) @@ -3097,9 +3090,9 @@ 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) mysql_file_delete(mi_key_file_datatmp, + param->temp_filename, 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 */ @@ -3110,16 +3103,16 @@ 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)); - my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR)); - my_free((uchar*) sort_param,MYF(MY_ALLOW_ZERO_PTR)); - my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); - VOID(end_io_cache(¶m->read_cache)); + my_free(sort_info.ft_buf); + my_free(sort_info.key_block); + my_free(sort_param); + my_free(sort_info.buff); + (void) end_io_cache(¶m->read_cache); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); if (!got_error && (param->testflag & T_UNPACK)) { @@ -3773,7 +3766,7 @@ int sort_write_record(MI_SORT_PARAM *sort_param) { char llbuff[22]; printf("%s\r", llstr(info->state->records,llbuff)); - VOID(fflush(stdout)); + (void) fflush(stdout); } } DBUG_RETURN(0); @@ -4047,7 +4040,7 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param, key_block->end_pos+=t_length; if (a_length <= keyinfo->block_length) { - VOID(_mi_move_key(keyinfo,key_block->lastkey,key)); + (void) _mi_move_key(keyinfo,key_block->lastkey,key); key_block->last_length=a_length-t_length; DBUG_RETURN(0); } @@ -4066,8 +4059,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)); @@ -4171,8 +4165,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; @@ -4212,9 +4206,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; } @@ -4312,7 +4308,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; @@ -4320,13 +4317,13 @@ 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); set_if_bigger(file_length,(ulonglong) share.base.max_data_file_length); - VOID(mi_close(*org_info)); + (void) mi_close(*org_info); bzero((char*) &create_info,sizeof(create_info)); create_info.max_rows=max(max_records,share.base.records); create_info.reloc_rows=share.base.reloc; @@ -4367,7 +4364,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename) } /* We are modifing */ (*org_info)->s->options&= ~HA_OPTION_READ_ONLY_DATA; - VOID(_mi_readinfo(*org_info,F_WRLCK,0)); + (void) _mi_readinfo(*org_info,F_WRLCK,0); (*org_info)->state->records=info.state->records; if (share.state.create_time) (*org_info)->s->state.create_time=share.state.create_time; @@ -4520,7 +4517,7 @@ void update_auto_increment_key(MI_CHECK *param, MI_INFO *info, if (my_errno != HA_ERR_END_OF_FILE) { mi_extra(info,HA_EXTRA_NO_KEYREAD,0); - my_free(mi_get_rec_buff_ptr(info, record), MYF(0)); + my_free(mi_get_rec_buff_ptr(info, record)); mi_check_print_error(param,"%d when reading last record",my_errno); DBUG_VOID_RETURN; } @@ -4535,7 +4532,7 @@ void update_auto_increment_key(MI_CHECK *param, MI_INFO *info, set_if_bigger(info->s->state.auto_increment, param->auto_increment_value); } mi_extra(info,HA_EXTRA_NO_KEYREAD,0); - my_free(mi_get_rec_buff_ptr(info, record), MYF(0)); + my_free(mi_get_rec_buff_ptr(info, record)); update_state_info(param, info, UPDATE_AUTO_INC); DBUG_VOID_RETURN; } @@ -4656,8 +4653,7 @@ static my_bool mi_too_big_key_for_sort(MI_KEYDEF *key, ha_rows rows) } return (key->flag & HA_SPATIAL) || (key->flag & (HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY | HA_FULLTEXT) && - ((ulonglong) rows * key_maxlength > - (ulonglong) myisam_max_temp_length)); + ((ulonglong) rows * key_maxlength > myisam_max_temp_length)); } /* diff --git a/storage/myisam/mi_close.c b/storage/myisam/mi_close.c index 2066d092e1f..51408ab191c 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,9 +55,9 @@ 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)); + my_free(mi_get_rec_buff_ptr(info, info->rec_buff)); if (flag) { DBUG_EXECUTE_IF("crash_before_flush_keys", @@ -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 @@ -88,34 +88,34 @@ int mi_close(register MI_INFO *info) #endif if (share->decode_trees) { - my_free((uchar*) share->decode_trees,MYF(0)); - my_free((uchar*) share->decode_tables,MYF(0)); + my_free(share->decode_trees); + my_free(share->decode_tables); } #ifdef THREAD thr_lock_delete(&share->lock); - VOID(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)); + my_free(info->s); } - pthread_mutex_unlock(&THR_LOCK_myisam); + mysql_mutex_unlock(&THR_LOCK_myisam); if (info->ftparser_param) { - my_free((uchar*)info->ftparser_param, MYF(0)); + my_free(info->ftparser_param); 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); - my_free((uchar*) info,MYF(0)); + my_free(info); if (error) { diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 0b4d781379c..46c61eb4709 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 @@ -19,12 +19,8 @@ #include "sp_defs.h" #include <my_bit.h> -#if defined(MSDOS) || defined(__WIN__) #ifdef __WIN__ #include <fcntl.h> -#else -#include <process.h> /* Prototype for getpid */ -#endif #endif #include <m_ctype.h> @@ -38,7 +34,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, MI_CREATE_INFO *ci,uint flags) { register uint i,j; - File UNINIT_VAR(dfile),file; + File UNINIT_VAR(dfile), UNINIT_VAR(file); int errpos,save_errno, create_mode= O_RDWR | O_TRUNC; myf create_flag; uint fields,length,max_key_length,packed,pointer,real_length_diff, @@ -73,8 +69,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION); } - LINT_INIT(dfile); - LINT_INIT(file); + errpos=0; options=0; bzero((uchar*) &share,sizeof(share)); @@ -554,11 +549,6 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, share.base.pack_bits=packed; share.base.fields=fields; share.base.pack_fields=packed; -#ifdef USE_RAID - share.base.raid_type=ci->raid_type; - share.base.raid_chunks=ci->raid_chunks; - share.base.raid_chunksize=ci->raid_chunksize; -#endif /* max_data_file_length and max_key_file_length are recalculated on open */ if (options & HA_OPTION_TMP_TABLE) @@ -572,7 +562,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,27 +628,15 @@ 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; if (!(flags & HA_DONT_TOUCH_DATA)) { -#ifdef USE_RAID - if (share.base.raid_type) - { - (void) fn_format(filename, name, "", MI_NAME_DEXT, - MY_UNPACK_FILENAME | MY_APPEND_EXT); - if ((dfile=my_raid_create(filename, 0, create_mode, - share.base.raid_type, - share.base.raid_chunks, - share.base.raid_chunksize, - MYF(MY_WME | MY_RAID))) < 0) - goto err; - } - else -#endif { if (ci->data_file_name) { @@ -694,8 +672,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 +686,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 +783,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,48 +793,50 @@ 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)); + my_free(rec_per_key_part); 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)); + my_free(rec_per_key_part); DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */ } diff --git a/storage/myisam/mi_dbug.c b/storage/myisam/mi_dbug.c index 07c314c43e6..e450e81cecb 100644 --- a/storage/myisam/mi_dbug.c +++ b/storage/myisam/mi_dbug.c @@ -30,12 +30,12 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, const uchar *end; const uchar *key_end=key+length; - VOID(fputs("Key: \"",stream)); + (void) fputs("Key: \"",stream); flag=0; for (; keyseg->type && key < key_end ;keyseg++) { if (flag++) - VOID(putc('-',stream)); + (void) putc('-',stream); end= key+ keyseg->length; if (keyseg->flag & HA_NULL_PART) { @@ -51,7 +51,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, case HA_KEYTYPE_BINARY: if (!(keyseg->flag & HA_SPACE_PACK) && keyseg->length == 1) { /* packed binary digit */ - VOID(fprintf(stream,"%d",(uint) *key++)); + (void) fprintf(stream,"%d",(uint) *key++); break; } /* fall through */ @@ -59,58 +59,58 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, case HA_KEYTYPE_NUM: if (keyseg->flag & HA_SPACE_PACK) { - VOID(fprintf(stream,"%.*s",(int) *key,key+1)); + (void) fprintf(stream,"%.*s",(int) *key,key+1); key+= (int) *key+1; } else { - VOID(fprintf(stream,"%.*s",(int) keyseg->length,key)); + (void) fprintf(stream,"%.*s",(int) keyseg->length,key); key=end; } break; case HA_KEYTYPE_INT8: - VOID(fprintf(stream,"%d",(int) *((signed char*) key))); + (void) fprintf(stream,"%d",(int) *((signed char*) key)); key=end; break; case HA_KEYTYPE_SHORT_INT: s_1= mi_sint2korr(key); - VOID(fprintf(stream,"%d",(int) s_1)); + (void) fprintf(stream,"%d",(int) s_1); key=end; break; case HA_KEYTYPE_USHORT_INT: { ushort u_1; u_1= mi_uint2korr(key); - VOID(fprintf(stream,"%u",(uint) u_1)); + (void) fprintf(stream,"%u",(uint) u_1); key=end; break; } case HA_KEYTYPE_LONG_INT: l_1=mi_sint4korr(key); - VOID(fprintf(stream,"%ld",l_1)); + (void) fprintf(stream,"%ld",l_1); key=end; break; case HA_KEYTYPE_ULONG_INT: l_1=mi_sint4korr(key); - VOID(fprintf(stream,"%lu",(ulong) l_1)); + (void) fprintf(stream,"%lu",(ulong) l_1); key=end; break; case HA_KEYTYPE_INT24: - VOID(fprintf(stream,"%ld",(long) mi_sint3korr(key))); + (void) fprintf(stream,"%ld",(long) mi_sint3korr(key)); key=end; break; case HA_KEYTYPE_UINT24: - VOID(fprintf(stream,"%lu",(ulong) mi_uint3korr(key))); + (void) fprintf(stream,"%lu",(ulong) mi_uint3korr(key)); key=end; break; case HA_KEYTYPE_FLOAT: mi_float4get(f_1,key); - VOID(fprintf(stream,"%g",(double) f_1)); + (void) fprintf(stream,"%g",(double) f_1); key=end; break; case HA_KEYTYPE_DOUBLE: mi_float8get(d_1,key); - VOID(fprintf(stream,"%g",d_1)); + (void) fprintf(stream,"%g",d_1); key=end; break; #ifdef HAVE_LONG_LONG @@ -118,7 +118,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, { char buff[21]; longlong2str(mi_sint8korr(key),buff,-10); - VOID(fprintf(stream,"%s",buff)); + (void) fprintf(stream,"%s",buff); key=end; break; } @@ -126,7 +126,7 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, { char buff[21]; longlong2str(mi_sint8korr(key),buff,10); - VOID(fprintf(stream,"%s",buff)); + (void) fprintf(stream,"%s",buff); key=end; break; } @@ -152,19 +152,31 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg, The following command sometimes gives a warning from valgrind. Not yet sure if the bug is in valgrind, glibc or mysqld */ - VOID(fprintf(stream,"%.*s",(int) tmp_length,key)); + (void) fprintf(stream,"%.*s",(int) tmp_length,key); key+=tmp_length; break; } default: break; /* This never happens */ } } - VOID(fputs("\"\n",stream)); + (void) fputs("\"\n",stream); return; } /* print_key */ -#ifdef EXTRA_DEBUG +#ifdef EXTRA_DEBUG +/** + Check if the named table is in the open list. + + @param[in] name table path as in MYISAM_SHARE::unique_file_name + @param[in] where verbal description of caller + + @retval TRUE table is in open list + @retval FALSE table is not in open list + + @note This function takes THR_LOCK_myisam. Do not call it when + this mutex is locked by this thread already. +*/ my_bool check_table_is_closed(const char *name, const char *where) { @@ -173,6 +185,7 @@ my_bool check_table_is_closed(const char *name, const char *where) DBUG_ENTER("check_table_is_closed"); (void) fn_format(filename,name,"",MI_NAME_IEXT,4+16+32); + mysql_mutex_lock(&THR_LOCK_myisam); for (pos=myisam_open_list ; pos ; pos=pos->next) { MI_INFO *info=(MI_INFO*) pos->data; @@ -181,12 +194,14 @@ my_bool check_table_is_closed(const char *name, const char *where) { if (share->last_version) { + mysql_mutex_unlock(&THR_LOCK_myisam); fprintf(stderr,"Warning: Table: %s is open on %s\n", name,where); DBUG_PRINT("warning",("Table: %s is open on %s", name,where)); DBUG_RETURN(1); } } } + mysql_mutex_unlock(&THR_LOCK_myisam); DBUG_RETURN(0); } #endif /* EXTRA_DEBUG */ diff --git a/storage/myisam/mi_delete.c b/storage/myisam/mi_delete.c index 904ce4b2247..9314148cd8c 100644 --- a/storage/myisam/mi_delete.c +++ b/storage/myisam/mi_delete.c @@ -101,7 +101,7 @@ int mi_delete(MI_INFO *info,const uchar *record) mi_sizestore(lastpos,info->lastpos); myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,sizeof(lastpos),0); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (info->invalidator != 0) { @@ -120,7 +120,7 @@ err: mi_print_error(info->s, HA_ERR_CRASHED); mi_mark_crashed(info); /* mark table crashed */ } - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); info->update|=HA_STATE_WRITTEN; /* Buffer changed */ allow_break(); /* Allow SIGHUP & SIGINT */ my_errno=save_errno; diff --git a/storage/myisam/mi_delete_all.c b/storage/myisam/mi_delete_all.c index 7c3ed178c4c..7a2e24189e6 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,10 +57,10 @@ int mi_delete_all_rows(MI_INFO *info) if (share->file_map) mi_munmap_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)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); #ifdef HAVE_MMAP /* Map again */ if (share->file_map) @@ -72,7 +72,7 @@ int mi_delete_all_rows(MI_INFO *info) err: { int save_errno=my_errno; - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); info->update|=HA_STATE_WRITTEN; /* Buffer changed */ allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno=save_errno); diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index c4797187bec..a05a2ad6237 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 @@ -19,86 +19,44 @@ #include "fulltext.h" +int mi_delete_table(const char *name) +{ + char from[FN_REFLEN]; + DBUG_ENTER("mi_delete_table"); -/** - Remove MyISAM data/index file safely - - @details - If name is a symlink and file it is pointing to is not in - data directory, file is also removed. - - @param name file to remove - - @returns - 0 on success or my_errno on failure -*/ +#ifdef EXTRA_DEBUG + check_table_is_closed(name,"delete"); +#endif -static int _mi_safe_delete_file(const char *name) -{ - DBUG_ENTER("_mi_safe_delete_file"); - if (my_is_symlink(name) && (*myisam_test_invalid_symlink)(name)) + fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); + if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) { /* Symlink is pointing to file in data directory. Remove symlink, keep file. */ - if (my_delete(name, MYF(MY_WME))) + if (mysql_file_delete(mi_key_file_kfile, from, MYF(MY_WME))) DBUG_RETURN(my_errno); } else { - if (my_delete_with_symlink(name, MYF(MY_WME))) + if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME))) DBUG_RETURN(my_errno); } - DBUG_RETURN(0); -} - - -int mi_delete_table(const char *name) -{ - char from[FN_REFLEN]; -#ifdef USE_RAID - uint raid_type=0,raid_chunks=0; -#endif - DBUG_ENTER("mi_delete_table"); - -#ifdef EXTRA_DEBUG - check_table_is_closed(name,"delete"); -#endif -#ifdef USE_RAID + fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); + if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) { - MI_INFO *info; /* - When built with RAID support, we need to determine if this table - makes use of the raid feature. If yes, we need to remove all raid - chunks. This is done with my_raid_delete(). Unfortunately it is - necessary to open the table just to check this. We use - 'open_for_repair' to be able to open even a crashed table. If even - this open fails, we assume no raid configuration for this table - and try to remove the normal data file only. This may however - leave the raid chunks behind. + Symlink is pointing to file in data directory. + Remove symlink, keep file. */ - if (!(info= mi_open(name, O_RDONLY, HA_OPEN_FOR_REPAIR))) - raid_type= 0; - else - { - raid_type= info->s->base.raid_type; - raid_chunks= info->s->base.raid_chunks; - mi_close(info); - } + if (mysql_file_delete(mi_key_file_dfile, from, MYF(MY_WME))) + DBUG_RETURN(my_errno); } -#ifdef EXTRA_DEBUG - check_table_is_closed(name,"delete"); -#endif -#endif /* USE_RAID */ - - fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (_mi_safe_delete_file(from)) - 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(_mi_safe_delete_file(from)); + else + { + if (mysql_file_delete_with_symlink(mi_key_file_dfile, from, MYF(MY_WME))) + DBUG_RETURN(my_errno); + } + DBUG_RETURN(0); } diff --git a/storage/myisam/mi_dynrec.c b/storage/myisam/mi_dynrec.c index 4153f55aa3c..f429edd2759 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 @@ -44,7 +44,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos, #undef my_alloca #undef my_afree #define my_alloca(A) my_malloc((A),MYF(0)) -#define my_afree(A) my_free((A),MYF(0)) +#define my_afree(A) my_free((A)) #endif /* Interface function from MI_INFO */ @@ -170,7 +170,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: @@ -183,24 +183,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); } @@ -225,7 +225,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: @@ -238,26 +238,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); } @@ -283,13 +283,6 @@ int _mi_write_blob_record(MI_INFO *info, const uchar *record) MI_DYN_DELETE_BLOCK_HEADER+1); reclength= (info->s->base.pack_reclength + _my_calc_total_blob_length(info,record)+ extra); -#ifdef NOT_USED /* We now support big rows */ - if (reclength > MI_DYN_MAX_ROW_LENGTH) - { - my_errno=HA_ERR_TO_BIG_ROW; - return -1; - } -#endif if (!(rec_buff=(uchar*) my_alloca(reclength))) { my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */ @@ -317,13 +310,6 @@ int _mi_update_blob_record(MI_INFO *info, my_off_t pos, const uchar *record) MI_DYN_DELETE_BLOCK_HEADER); reclength= (info->s->base.pack_reclength+ _my_calc_total_blob_length(info,record)+ extra); -#ifdef NOT_USED /* We now support big rows */ - if (reclength > MI_DYN_MAX_ROW_LENGTH) - { - my_errno=HA_ERR_TO_BIG_ROW; - return -1; - } -#endif if (!(rec_buff=(uchar*) my_alloca(reclength))) { my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */ @@ -1009,7 +995,7 @@ uint _mi_rec_pack(MI_INFO *info, register uchar *to, char *temp_pos; size_t tmp_length=length-portable_sizeof_char_ptr; memcpy((uchar*) to,from,tmp_length); - memcpy_fixed(&temp_pos,from+tmp_length,sizeof(char*)); + memcpy(&temp_pos,from+tmp_length,sizeof(char*)); memcpy(to+tmp_length,temp_pos,(size_t) blob->length); to+=tmp_length+blob->length; } @@ -1324,9 +1310,9 @@ ulong _mi_rec_unpack(register MI_INFO *info, register uchar *to, uchar *from, from_left - size_length < blob_length || from_left - size_length - blob_length < min_pack_length) goto err; - memcpy((uchar*) to,(uchar*) from,(size_t) size_length); + memcpy(to, from, (size_t) size_length); from+=size_length; - memcpy_fixed((uchar*) to+size_length,(uchar*) &from,sizeof(char*)); + memcpy(to+size_length, &from, sizeof(char*)); from+=blob_length; } else @@ -1550,7 +1536,7 @@ int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *buf) panic: my_errno=HA_ERR_WRONG_IN_RECORD; err: - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); DBUG_RETURN(-1); } @@ -1575,7 +1561,7 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, error=mi_unique_comp(def, record, old_record, def->null_are_equal); if (info->s->base.blobs) { - my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); + my_free(mi_get_rec_buff_ptr(info, info->rec_buff)); info->rec_buff=rec_buff; } my_afree(old_record); @@ -1677,7 +1663,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; @@ -1685,7 +1671,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: @@ -1866,8 +1852,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; - /* VOID(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 */ @@ -1900,7 +1887,7 @@ panic: my_errno=HA_ERR_WRONG_IN_RECORD; /* Something is fatal wrong */ err: save_errno=my_errno; - VOID(_mi_writeinfo(info,0)); + (void) _mi_writeinfo(info,0); DBUG_RETURN(my_errno=save_errno); } @@ -1915,12 +1902,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. */ - VOID(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 d861b2af6cf..baf8cb5e240 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. @@ -365,13 +365,13 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) error= my_errno= errno; } } - 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/ft_stem.c b/storage/myisam/mi_extrafunc.h index dfc132fcfa9..4aa28832c6d 100644 --- a/storage/myisam/ft_stem.c +++ b/storage/myisam/mi_extrafunc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -13,6 +13,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ - -/* mulitingual stem */ +void _mi_report_crashed(MI_INFO *file __attribute__((unused)), + const char *message __attribute__((unused)), + const char *sfile __attribute__((unused)), + uint sline __attribute__((unused))) +{ +} diff --git a/storage/myisam/mi_info.c b/storage/myisam/mi_info.c index 91e7ca659e4..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); - VOID(_mi_readinfo(info,F_RDLCK,0)); + 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_key.c b/storage/myisam/mi_key.c index 3f445ebf44d..75038fce070 100644 --- a/storage/myisam/mi_key.c +++ b/storage/myisam/mi_key.c @@ -139,7 +139,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, else if (keyseg->flag & HA_BLOB_PART) { uint tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos); - memcpy_fixed((uchar*) &pos,pos+keyseg->bit_start,sizeof(char*)); + memcpy(&pos,pos+keyseg->bit_start,sizeof(char*)); set_if_smaller(length,tmp_length); FIX_LENGTH(cs, pos, length, char_length); store_key_length_inc(key,char_length); @@ -253,18 +253,17 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, pos=old; if (keyseg->flag & HA_SPACE_PACK) { - uchar *end=pos+length; if (type == HA_KEYTYPE_NUM) { - while (pos < end && pos[0] == ' ') - pos++; + uchar *end= pos + length; + while (pos < end && pos[0] == ' ') + pos++; + length= (uint) (end - pos); } else if (type != HA_KEYTYPE_BINARY) { - while (end > pos && end[-1] == ' ') - end--; + length= cs->cset->lengthsp(cs, (char*) pos, length); } - length=(uint) (end-pos); FIX_LENGTH(cs, pos, length, char_length); store_key_length_inc(key,char_length); memcpy((uchar*) key,pos,(size_t) char_length); 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 589b9cf89b7..6134b4f46df 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 @@ -44,11 +44,12 @@ int mi_lock_database(MI_INFO *info, int lock_type) ++share->w_locks; ++share->tot_locks; info->lock_type= lock_type; + info->s->in_use= list_add(info->s->in_use, &info->in_use); DBUG_RETURN(0); } 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) { @@ -87,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; @@ -102,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 @@ -133,6 +134,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); info->lock_type= F_UNLCK; + info->s->in_use= list_delete(info->s->in_use, &info->in_use); break; case F_RDLCK: if (info->lock_type == F_WRLCK) @@ -168,15 +170,16 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { error=my_errno; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); my_errno=error; break; } } - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); share->r_locks++; share->tot_locks++; info->lock_type=lock_type; + info->s->in_use= list_add(info->s->in_use, &info->in_use); break; case F_WRLCK: if (info->lock_type == F_RDLCK) @@ -210,26 +213,27 @@ int mi_lock_database(MI_INFO *info, int lock_type) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { error=my_errno; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, - info->lock_wait | MY_SEEK_NOT_DONE)); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, + info->lock_wait | MY_SEEK_NOT_DONE); my_errno=error; break; } } } } - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); info->lock_type=lock_type; info->invalidator=info->s->invalidator; share->w_locks++; share->tot_locks++; + info->s->in_use= list_add(info->s->in_use, &info->in_use); break; default: break; /* Impossible */ } } -#ifdef __WIN__ +#ifdef _WIN32 else { /* @@ -244,7 +248,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) } } #endif - pthread_mutex_unlock(&share->intern_lock); + mysql_mutex_unlock(&share->intern_lock); DBUG_RETURN(error); } /* mi_lock_database */ @@ -400,14 +404,14 @@ int _mi_readinfo(register MI_INFO *info, int lock_type, int check_keybuffer) if (mi_state_info_read_dsk(share->kfile, &share->state, 1)) { int error=my_errno ? my_errno : -1; - VOID(my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, - MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(share->kfile,F_UNLCK,0L,F_TO_EOF, + MYF(MY_SEEK_NOT_DONE)); my_errno=error; DBUG_RETURN(1); } } if (check_keybuffer) - VOID(_mi_test_if_changed(info)); + (void) _mi_test_if_changed(info); info->invalidator=info->s->invalidator; } else if (lock_type == F_WRLCK && info->lock_type == F_RDLCK) @@ -443,11 +447,11 @@ int _mi_writeinfo(register MI_INFO *info, uint operation) share->state.update_count= info->last_loop= ++info->this_loop; if ((error=mi_state_info_write(share->kfile, &share->state, 1))) olderror=my_errno; -#ifdef __WIN__ +#ifdef _WIN32 if (myisam_flush) { - _commit(share->kfile); - _commit(info->dfile); + mysql_file_sync(share->kfile, 0); + mysql_file_sync(info->dfile, 0); } #endif } @@ -475,7 +479,7 @@ int _mi_test_if_changed(register MI_INFO *info) { /* Keyfile has changed */ DBUG_PRINT("info",("index file changed")); if (share->state.process != share->this_process) - VOID(flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE)); + (void) flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE); share->last_process=share->state.process; info->last_unique= share->state.unique; info->last_loop= share->state.update_count; @@ -527,9 +531,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); @@ -556,9 +560,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 8b9ca038fec..5af4a057a95 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 @@ -19,14 +19,8 @@ */ #include "myisamdef.h" -#if defined(MSDOS) || defined(__WIN__) +#ifdef __WIN__ #include <fcntl.h> -#ifndef __WIN__ -#include <process.h> -#endif -#endif -#ifdef VMS -#include <processes.h> #endif #undef GETPID /* For HPUX */ @@ -54,16 +48,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 +83,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 +106,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 +137,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; @@ -152,13 +149,13 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info, blob != end ; blob++) { - memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length, + memcpy(&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 8ecb07d75e8..e3c29909067 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 @@ -20,15 +20,8 @@ #include "rt_index.h" #include <m_ctype.h> -#if defined(MSDOS) || defined(__WIN__) #ifdef __WIN__ #include <fcntl.h> -#else -#include <process.h> /* Prototype for getpid */ -#endif -#endif -#ifdef VMS -#include "static.c" #endif static void setup_key_functions(MI_KEYDEF *keyinfo); @@ -103,7 +96,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 +113,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 +178,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) end_pos=disk_cache+info_length; errpos=2; - VOID(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 +188,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; @@ -263,25 +260,6 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) set_if_smaller(max_data_file_length, INT_MAX32); set_if_smaller(max_key_file_length, INT_MAX32); #endif -#if USE_RAID && SYSTEM_SIZEOF_OFF_T == 4 - set_if_smaller(max_key_file_length, INT_MAX32); - if (!share->base.raid_type) - { - set_if_smaller(max_data_file_length, INT_MAX32); - } - else - { - set_if_smaller(max_data_file_length, - (ulonglong) share->base.raid_chunks << 31); - } -#elif !defined(USE_RAID) - if (share->base.raid_type) - { - DBUG_PRINT("error",("Table uses RAID but we don't have RAID support")); - my_errno=HA_ERR_UNSUPPORTED; - goto err; - } -#endif share->base.max_data_file_length=(my_off_t) max_data_file_length; share->base.max_key_file_length=(my_off_t) max_key_file_length; @@ -309,9 +287,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; @@ -482,7 +460,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) if (! lock_error) { - VOID(my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(kfile,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); lock_error=1; /* Database unlocked */ } @@ -522,10 +500,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); - VOID(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 +591,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 +615,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 +631,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); bzero(info.buff, share->base.max_key_block_length * 2); @@ -670,31 +650,31 @@ err: mi_report_error(save_errno, name); switch (errpos) { case 6: - my_free((uchar*) m_info,MYF(0)); + my_free(m_info); /* 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 */ case 4: - my_free((uchar*) share,MYF(0)); + my_free(share); /* fall through */ case 3: if (! lock_error) - VOID(my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE))); + (void) my_lock(kfile, F_UNLCK, 0L, F_TO_EOF, MYF(MY_SEEK_NOT_DONE)); /* fall through */ case 2: 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 */ @@ -878,7 +858,7 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite) key_blocks=state->header.max_block_size_index; DBUG_ENTER("mi_state_info_write"); - memcpy_fixed(ptr,&state->header,sizeof(state->header)); + memcpy(ptr, &state->header, sizeof(state->header)); ptr+=sizeof(state->header); /* open_count must be first because of _mi_mark_file_changed ! */ @@ -927,17 +907,17 @@ 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); } uchar *mi_state_info_read(uchar *ptr, MI_STATE_INFO *state) { uint i,keys,key_parts,key_blocks; - memcpy_fixed(&state->header,ptr, sizeof(state->header)); + memcpy(&state->header, ptr, sizeof(state->header)); ptr +=sizeof(state->header); keys=(uint) state->header.keys; key_parts=mi_uint2korr(state->header.key_parts); @@ -995,10 +975,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); } @@ -1037,11 +1017,8 @@ uint mi_base_info_write(File file, MI_BASE_INFO *base) mi_int2store(ptr,base->max_key_length); ptr +=2; mi_int2store(ptr,base->extra_alloc_bytes); ptr +=2; *ptr++= base->extra_alloc_procent; - *ptr++= base->raid_type; - 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; + bzero(ptr,13); ptr +=13; /* extra */ + return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; } @@ -1071,17 +1048,8 @@ uchar *my_n_base_info_read(uchar *ptr, MI_BASE_INFO *base) base->max_key_length = mi_uint2korr(ptr); ptr +=2; base->extra_alloc_bytes = mi_uint2korr(ptr); ptr +=2; base->extra_alloc_procent = *ptr++; - base->raid_type= *ptr++; - base->raid_chunks= mi_uint2korr(ptr); ptr +=2; - base->raid_chunksize= mi_uint4korr(ptr); ptr +=4; - /* TO BE REMOVED: Fix for old RAID files */ - if (base->raid_type == 0) - { - base->raid_chunks=0; - base->raid_chunksize=0; - } - ptr+=6; + ptr+=13; return ptr; } @@ -1101,7 +1069,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) @@ -1133,10 +1101,10 @@ int mi_keyseg_write(File file, const HA_KEYSEG *keyseg) ulong pos; *ptr++= keyseg->type; - *ptr++= keyseg->language; + *ptr++= keyseg->language & 0xFF; /* Collation ID, low byte */ *ptr++= keyseg->null_bit; *ptr++= keyseg->bit_start; - *ptr++= keyseg->bit_end; + *ptr++= keyseg->language >> 8; /* Collation ID, high byte */ *ptr++= keyseg->bit_length; mi_int2store(ptr,keyseg->flag); ptr+=2; mi_int2store(ptr,keyseg->length); ptr+=2; @@ -1145,7 +1113,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; } @@ -1155,12 +1123,13 @@ uchar *mi_keyseg_read(uchar *ptr, HA_KEYSEG *keyseg) keyseg->language = *ptr++; keyseg->null_bit = *ptr++; keyseg->bit_start = *ptr++; - keyseg->bit_end = *ptr++; + keyseg->language += ((uint16) (*ptr++)) << 8; keyseg->bit_length = *ptr++; keyseg->flag = mi_uint2korr(ptr); ptr +=2; keyseg->length = mi_uint2korr(ptr); ptr +=2; keyseg->start = mi_uint4korr(ptr); ptr +=4; keyseg->null_pos = mi_uint4korr(ptr); ptr +=4; + keyseg->bit_end= 0; keyseg->charset=0; /* Will be filled in later */ if (keyseg->null_bit) /* We adjust bit_pos if null_bit is last in the byte */ @@ -1186,7 +1155,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) @@ -1210,7 +1179,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) @@ -1223,7 +1192,7 @@ uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo) } /************************************************************************** -Open data file with or without RAID +Open data file. We can't use dup() here as the data file descriptors need to have different active seek-positions. @@ -1251,27 +1220,18 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, data_name= real_data_name; } } -#ifdef USE_RAID - if (share->base.raid_type) - { - info->dfile=my_raid_open(data_name, - share->mode | O_SHARE, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(MY_WME | MY_RAID)); - } - 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 7f048ed62e3..d8d892a5bc9 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); @@ -298,9 +298,9 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys) err3: my_errno=HA_ERR_WRONG_IN_RECORD; err2: - my_free((uchar*) share->decode_tables,MYF(0)); + my_free(share->decode_tables); err1: - my_free((uchar*) share->decode_trees,MYF(0)); + my_free(share->decode_trees); err0: DBUG_RETURN(1); } @@ -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, @@ -1051,8 +1051,7 @@ static void uf_blob(MI_COLUMNDEF *rec, MI_BIT_BUFF *bit_buff, } decode_bytes(rec,bit_buff,bit_buff->blob_pos,bit_buff->blob_pos+length); _my_store_blob_length((uchar*) to,pack_length,length); - memcpy_fixed((char*) to+pack_length,(char*) &bit_buff->blob_pos, - sizeof(char*)); + memcpy((char*) to+pack_length, &bit_buff->blob_pos, sizeof(char*)); bit_buff->blob_pos+=length; } } @@ -1339,9 +1338,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 +1369,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 */ - VOID(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); } @@ -1502,11 +1501,11 @@ my_bool _mi_memmap_file(MI_INFO *info) if (myisam_mmap_size != SIZE_T_MAX) { - pthread_mutex_lock(&THR_LOCK_myisam_mmap); + mysql_mutex_lock(&THR_LOCK_myisam_mmap); eom= data_file_length > myisam_mmap_size - myisam_mmap_used - MEMMAP_EXTRA_MARGIN; if (!eom) myisam_mmap_used+= data_file_length + MEMMAP_EXTRA_MARGIN; - pthread_mutex_unlock(&THR_LOCK_myisam_mmap); + mysql_mutex_unlock(&THR_LOCK_myisam_mmap); } else eom= data_file_length > myisam_mmap_size - MEMMAP_EXTRA_MARGIN; @@ -1516,15 +1515,15 @@ my_bool _mi_memmap_file(MI_INFO *info) DBUG_PRINT("warning", ("File is too large for mmap")); DBUG_RETURN(0); } - 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")); if (myisam_mmap_size != SIZE_T_MAX) { - pthread_mutex_lock(&THR_LOCK_myisam_mmap); + mysql_mutex_lock(&THR_LOCK_myisam_mmap); myisam_mmap_used-= data_file_length + MEMMAP_EXTRA_MARGIN; - pthread_mutex_unlock(&THR_LOCK_myisam_mmap); + mysql_mutex_unlock(&THR_LOCK_myisam_mmap); } DBUG_RETURN(0); } @@ -1534,9 +1533,9 @@ my_bool _mi_memmap_file(MI_INFO *info) { if (myisam_mmap_size != SIZE_T_MAX) { - pthread_mutex_lock(&THR_LOCK_myisam_mmap); + mysql_mutex_lock(&THR_LOCK_myisam_mmap); myisam_mmap_used-= data_file_length + MEMMAP_EXTRA_MARGIN; - pthread_mutex_unlock(&THR_LOCK_myisam_mmap); + mysql_mutex_unlock(&THR_LOCK_myisam_mmap); } DBUG_RETURN(0); } @@ -1550,14 +1549,14 @@ my_bool _mi_memmap_file(MI_INFO *info) void _mi_unmap_file(MI_INFO *info) { - VOID(my_munmap((char*) info->s->file_map, - (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN)); + (void) my_munmap((char*) info->s->file_map, + (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN); if (myisam_mmap_size != SIZE_T_MAX) { - pthread_mutex_lock(&THR_LOCK_myisam_mmap); + mysql_mutex_lock(&THR_LOCK_myisam_mmap); myisam_mmap_used-= info->s->mmaped_length + MEMMAP_EXTRA_MARGIN; - pthread_mutex_unlock(&THR_LOCK_myisam_mmap); + mysql_mutex_unlock(&THR_LOCK_myisam_mmap); } } diff --git a/storage/myisam/mi_panic.c b/storage/myisam/mi_panic.c index 74c93761b61..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; } @@ -103,10 +107,10 @@ int mi_panic(enum ha_panic_function flag) } if (flag == HA_PANIC_CLOSE) { - VOID(mi_log(0)); /* Close log if neaded */ + (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..31537f7054b 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) @@ -112,11 +113,11 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) } while (pos != key_file_length); - my_free((char*) buff, MYF(0)); + my_free(buff); DBUG_RETURN(0); err: - my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR)); + my_free(buff); DBUG_RETURN(my_errno= errno); } diff --git a/storage/myisam/mi_range.c b/storage/myisam/mi_range.c index e4205f36557..28bf5cbe033 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..455d45cecfe 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 @@ -22,39 +22,20 @@ int mi_rename(const char *old_name, const char *new_name) { char from[FN_REFLEN],to[FN_REFLEN]; -#ifdef USE_RAID - uint raid_type=0,raid_chunks=0; -#endif DBUG_ENTER("mi_rename"); #ifdef EXTRA_DEBUG check_table_is_closed(old_name,"rename old_table"); check_table_is_closed(new_name,"rename new table2"); #endif -#ifdef USE_RAID - { - MI_INFO *info; - if (!(info=mi_open(old_name, O_RDONLY, 0))) - DBUG_RETURN(my_errno); - raid_type = info->s->base.raid_type; - raid_chunks = info->s->base.raid_chunks; - mi_close(info); - } -#ifdef EXTRA_DEBUG - check_table_is_closed(old_name,"rename raidcheck"); -#endif -#endif /* USE_RAID */ 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); -#ifdef USE_RAID - if (raid_type) - 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 b9bbda3cacb..e1a78a04e57 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 @@ -40,7 +40,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) { @@ -111,7 +111,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 8093498483f..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]); - VOID(_mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, + 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])); + 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_search.c b/storage/myisam/mi_search.c index 66ea82b7643..61ca3c37863 100644 --- a/storage/myisam/mi_search.c +++ b/storage/myisam/mi_search.c @@ -84,7 +84,7 @@ int _mi_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff, test(!(nextflag & SEARCH_SAVE_BUFF))))) goto err; - DBUG_DUMP("page",(uchar*) buff,mi_getint(buff)); + DBUG_DUMP("page", buff, mi_getint(buff)); flag=(*keyinfo->bin_search)(info,keyinfo,buff,key,key_len,nextflag, &keypos,lastkey, &last_key); diff --git a/storage/myisam/mi_static.c b/storage/myisam/mi_static.c index 27485e101ff..55967fc9001 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 @@ -23,9 +23,9 @@ #endif LIST *myisam_open_list=0; -uchar NEAR myisam_file_magic[]= +uchar myisam_file_magic[]= { (uchar) 254, (uchar) 254,'\007', '\001', }; -uchar NEAR myisam_pack_file_magic[]= +uchar myisam_pack_file_magic[]= { (uchar) 254, (uchar) 254,'\010', '\002', }; char * myisam_log_filename=(char*) "myisam.log"; File myisam_log_file= -1; @@ -37,8 +37,7 @@ ulong myisam_concurrent_insert= 2; #else ulong myisam_concurrent_insert= 0; #endif -my_off_t myisam_max_temp_length= MAX_FILE_SIZE; -ulong myisam_bulk_insert_tree_size=8192*1024; +ulonglong myisam_max_temp_length= MAX_FILE_SIZE; ulong myisam_data_pointer_size=4; ulonglong myisam_mmap_size= SIZE_T_MAX, myisam_mmap_used= 0; @@ -55,7 +54,7 @@ int (*myisam_test_invalid_symlink)(const char *filename)= always_valid; Position is , == , >= , <= , > , < */ -uint NEAR myisam_read_vec[]= +uint myisam_read_vec[]= { SEARCH_FIND, SEARCH_FIND | SEARCH_BIGGER, SEARCH_FIND | SEARCH_SMALLER, SEARCH_NO_FIND | SEARCH_BIGGER, SEARCH_NO_FIND | SEARCH_SMALLER, @@ -63,8 +62,79 @@ uint NEAR myisam_read_vec[]= MBR_CONTAIN, MBR_INTERSECT, MBR_WITHIN, MBR_DISJOINT, MBR_EQUAL }; -uint NEAR myisam_readnext_vec[]= +uint 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_statrec.c b/storage/myisam/mi_statrec.c index e3771560c01..f83afa3c886 100644 --- a/storage/myisam/mi_statrec.c +++ b/storage/myisam/mi_statrec.c @@ -273,7 +273,12 @@ int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf, DBUG_RETURN(error); } - /* Read record with cacheing */ + /* + Read record with caching. If my_b_read() returns TRUE, less than the + requested bytes have been read. In this case rec_cache.error is + either -1 for a read error, or contains the number of bytes copied + into the buffer. + */ error=my_b_read(&info->rec_cache,(uchar*) buf,share->base.reclength); if (info->s->base.pack_reclength != info->s->base.reclength && !error) { @@ -282,7 +287,7 @@ int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf, info->s->base.pack_reclength - info->s->base.reclength); } if (locked) - VOID(_mi_writeinfo(info,0)); /* Unlock keyfile */ + (void) _mi_writeinfo(info,0); /* Unlock keyfile */ if (!error) { if (!buf[0]) @@ -293,8 +298,17 @@ int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf, info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED; DBUG_RETURN(0); } - /* my_errno should be set if rec_cache.error == -1 */ + /* error is TRUE. my_errno should be set if rec_cache.error == -1 */ if (info->rec_cache.error != -1 || my_errno == 0) - my_errno=HA_ERR_WRONG_IN_RECORD; + { + /* + If we could not get a full record, we either have a broken record, + or are at end of file. + */ + if (info->rec_cache.error == 0) + my_errno= HA_ERR_END_OF_FILE; + else + my_errno= HA_ERR_WRONG_IN_RECORD; + } DBUG_RETURN(my_errno); /* Something wrong (EOF?) */ } diff --git a/storage/myisam/mi_test1.c b/storage/myisam/mi_test1.c index 363b024737a..f89f2a8d21d 100644 --- a/storage/myisam/mi_test1.c +++ b/storage/myisam/mi_test1.c @@ -161,7 +161,7 @@ static int run_test(const char *filename) row_count=deleted=0; for (i=49 ; i>=1 ; i-=2 ) { - if (insert_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (insert_count-- == 0) { (void) mi_close(file); exit(0) ; } j=i%25 +1; create_record(record,j); error=mi_write(file,record); @@ -225,7 +225,7 @@ static int run_test(const char *filename) found=0; while ((error=mi_rrnd(file,read_record,pos)) == 0) { - if (update_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (update_count-- == 0) { (void) mi_close(file); exit(0) ; } memcpy(record,read_record,rec_length); update_record(record); if (mi_update(file,read_record,record)) @@ -252,7 +252,7 @@ static int run_test(const char *filename) for (i=0 ; i <= 10 ; i++) { /* testing */ - if (remove_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } + if (remove_count-- == 0) { (void) mi_close(file); exit(0) ; } j=i*2; if (!flags[j]) continue; @@ -411,7 +411,7 @@ static void create_record(uchar *record,uint rownr) tmp=strlen((char*) blob_key); int4store(pos,tmp); ptr=blob_key; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); + memcpy(pos+4, &ptr, sizeof(char*)); pos+=recinfo[1].length; } else if (recinfo[1].type == FIELD_VARCHAR) @@ -439,7 +439,7 @@ static void create_record(uchar *record,uint rownr) tmp=strlen((char*) blob_record); int4store(pos,tmp); ptr=blob_record; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); + memcpy(pos+4, &ptr, sizeof(char*)); } else if (recinfo[2].type == FIELD_VARCHAR) { @@ -468,10 +468,10 @@ static void update_record(uchar *record) uchar *column,*ptr; int length; length=uint4korr(pos); /* Long blob */ - memcpy_fixed(&column,pos+4,sizeof(char*)); + memcpy(&column, pos+4, sizeof(char*)); memcpy(blob_key,column,length); /* Move old key */ ptr=blob_key; - memcpy_fixed(pos+4,&ptr,sizeof(char*)); /* Store pointer to new key */ + memcpy(pos+4, &ptr, sizeof(char*)); /* Store pointer to new key */ if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM) default_charset_info->cset->casedn(default_charset_info, (char*) blob_key, length, @@ -501,13 +501,13 @@ static void update_record(uchar *record) uchar *column; int length; length=uint4korr(pos); - memcpy_fixed(&column,pos+4,sizeof(char*)); + memcpy(&column, pos+4, sizeof(char*)); memcpy(blob_record,column,length); bfill(blob_record+length,20,'.'); /* Make it larger */ length+=20; int4store(pos,length); column= blob_record; - memcpy_fixed(pos+4,&column,sizeof(char*)); + memcpy(pos+4, &column, sizeof(char*)); } else if (recinfo[2].type == FIELD_VARCHAR) { @@ -679,3 +679,5 @@ static void usage() my_print_help(my_long_options); my_print_variables(my_long_options); } + +#include "mi_extrafunc.h" diff --git a/storage/myisam/mi_test2.c b/storage/myisam/mi_test2.c index d7c168d01b0..127d93b5433 100644 --- a/storage/myisam/mi_test2.c +++ b/storage/myisam/mi_test2.c @@ -21,9 +21,6 @@ #ifdef DBUG_OFF #undef DBUG_OFF #endif -#ifndef SAFEMALLOC -#define SAFEMALLOC -#endif #include "myisamdef.h" #include <m_ctype.h> #include <my_bit.h> @@ -31,7 +28,7 @@ #define STANDARD_LENGTH 37 #define MYISAM_KEYS 6 #define MAX_PARTS 4 -#if !defined(MSDOS) && !defined(labs) +#if !defined(labs) #define labs(a) abs(a) #endif @@ -856,13 +853,13 @@ reads: %10lu\n", } end_key_cache(dflt_key_cache,1); if (blob_buffer) - my_free(blob_buffer,MYF(0)); + my_free(blob_buffer); my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO); return(0); err: printf("got error: %d when using MyISAM-database\n",my_errno); if (file) - VOID(mi_close(file)); + (void) mi_close(file); return(1); } /* main */ @@ -1033,7 +1030,7 @@ static void put_blob_in_record(uchar *blob_pos, char **blob_buffer) for (i=0 ; i < length ; i++) (*blob_buffer)[i]=(char) (length+i); int4store(blob_pos,length); - memcpy_fixed(blob_pos+4,(char*) blob_buffer,sizeof(char*)); + memcpy(blob_pos+4, blob_buffer, sizeof(char*)); } else { @@ -1055,3 +1052,5 @@ static void copy_key(MI_INFO *info,uint inx,uchar *rec,uchar *key_buff) } return; } + +#include "mi_extrafunc.h" diff --git a/storage/myisam/mi_test3.c b/storage/myisam/mi_test3.c index 5bdc33b8518..c03a34df227 100644 --- a/storage/myisam/mi_test3.c +++ b/storage/myisam/mi_test3.c @@ -15,8 +15,6 @@ /* Test av locking */ -#ifndef __NETWARE__ - #include "myisam.h" #include <sys/types.h> #ifdef HAVE_SYS_WAIT_H @@ -109,7 +107,7 @@ int main(int argc,char **argv) sleep(1); return 0; } - VOID(rnd(1)); + (void) rnd(1); } for (i=0 ; i < forks ; i++) @@ -460,7 +458,7 @@ int test_update(MI_INFO *file,int id,int lock_type) } } } - memcpy_fixed(new_record.id,record.id,sizeof(record.id)); + memcpy(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)) @@ -488,14 +486,4 @@ int test_update(MI_INFO *file,int id,int lock_type) return 0; } -#else /* __NETWARE__ */ - -#include <stdio.h> - -main() -{ - fprintf(stderr,"this test has not been ported to NetWare\n"); - return 0; -} - -#endif /* __NETWARE__ */ +#include "mi_extrafunc.h" diff --git a/storage/myisam/mi_unique.c b/storage/myisam/mi_unique.c index fdba84a2e67..cee159951de 100644 --- a/storage/myisam/mi_unique.c +++ b/storage/myisam/mi_unique.c @@ -111,7 +111,7 @@ ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const uchar *record) else if (keyseg->flag & HA_BLOB_PART) { uint tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos); - memcpy_fixed((uchar*) &pos,pos+keyseg->bit_start,sizeof(char*)); + memcpy(&pos, pos+keyseg->bit_start, sizeof(char*)); if (!length || length > tmp_length) length=tmp_length; /* The whole blob */ } @@ -206,8 +206,8 @@ int mi_unique_comp(MI_UNIQUEDEF *def, const uchar *a, const uchar *b, set_if_smaller(a_length, keyseg->length); set_if_smaller(b_length, keyseg->length); } - memcpy_fixed((uchar*) &pos_a,pos_a+keyseg->bit_start,sizeof(char*)); - memcpy_fixed((uchar*) &pos_b,pos_b+keyseg->bit_start,sizeof(char*)); + memcpy(&pos_a, pos_a+keyseg->bit_start, sizeof(char*)); + memcpy(&pos_b, pos_b+keyseg->bit_start, sizeof(char*)); } if (type == HA_KEYTYPE_TEXT || type == HA_KEYTYPE_VARTEXT1 || type == HA_KEYTYPE_VARTEXT2) diff --git a/storage/myisam/mi_update.c b/storage/myisam/mi_update.c index a18bb5f1443..b538bcd0bb1 100644 --- a/storage/myisam/mi_update.c +++ b/storage/myisam/mi_update.c @@ -178,7 +178,7 @@ int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec) mi_update() must always pass !0 value as operation, since even if there is no index change there could be data change. */ - VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (info->invalidator != 0) { @@ -229,7 +229,7 @@ err: err_end: myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ if (save_errno == HA_ERR_KEY_NOT_FOUND) { diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index 72a4e006cc6..bd56bb04f65 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 @@ -61,11 +61,6 @@ int mi_write(MI_INFO *info, uchar *record) if (_mi_readinfo(info,F_WRLCK,1)) DBUG_RETURN(my_errno); dont_break(); /* Dont allow SIGHUP or SIGINT */ -#if !defined(NO_LOCKING) && defined(USE_RECORD_LOCK) - if (!info->locked && my_lock(info->dfile,F_WRLCK,0L,F_TO_EOF, - MYF(MY_SEEK_NOT_DONE) | info->lock_wait)) - goto err; -#endif filepos= ((share->state.dellink != HA_OFFSET_ERROR && !info->append_insert_at_end) ? share->state.dellink : @@ -107,7 +102,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 +110,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 +121,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 +131,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) @@ -155,7 +150,7 @@ int mi_write(MI_INFO *info, uchar *record) info->state->records++; info->lastpos=filepos; myisam_log_record(MI_LOG_WRITE,info,record,filepos,0); - VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); if (info->invalidator != 0) { DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename)); @@ -197,13 +192,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 +208,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]); } } } @@ -232,7 +227,7 @@ err: err2: save_errno=my_errno; myisam_log_record(MI_LOG_WRITE,info,record,filepos,my_errno); - VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); + (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); allow_break(); /* Allow SIGHUP & SIGINT */ DBUG_RETURN(my_errno=save_errno); } /* mi_write */ @@ -286,7 +281,7 @@ int _mi_ck_write_btree(register MI_INFO *info, uint keynr, uchar *key, if (!error) error= _mi_ft_convert_to_ft2(info, keynr, key); delete_dynamic(info->ft1_to_ft2); - my_free((uchar*)info->ft1_to_ft2, MYF(0)); + my_free(info->ft1_to_ft2); info->ft1_to_ft2=0; } DBUG_RETURN(error); @@ -943,7 +938,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 +950,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; @@ -1045,7 +1040,7 @@ void mi_end_bulk_insert(MI_INFO *info) delete_tree(& info->bulk_insert[i]); } } - my_free((void *)info->bulk_insert, MYF(0)); + my_free(info->bulk_insert); info->bulk_insert=0; } } diff --git a/storage/myisam/myisam_ftdump.c b/storage/myisam/myisam_ftdump.c index f1637a7e116..1c534fe8d02 100644 --- a/storage/myisam/myisam_ftdump.c +++ b/storage/myisam/myisam_ftdump.c @@ -46,7 +46,7 @@ static struct my_option my_long_options[] = {"stats", 's', "Report global stats.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"verbose", 'v', "Be verbose.", - (uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + &verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -253,18 +253,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), return 0; } -#include <help_start.h> static void usage() { printf("Use: myisam_ftdump <table_name> <index_num>\n"); my_print_help(my_long_options); my_print_variables(my_long_options); - NETWARE_SET_SCREEN_MODE(1); exit(1); } -#include <help_end.h> static void complain(int val) /* Kinda assert :-) */ { @@ -274,3 +271,5 @@ static void complain(int val) /* Kinda assert :-) */ exit(1); } } + +#include "mi_extrafunc.h" diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index 7f9776ca8d0..35b68fe00df 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -27,12 +27,6 @@ #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif -SET_STACK_SIZE(9000) /* Minimum stack size for program */ - -#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) -#endif static uint decode_bits; static char **default_argv; @@ -99,8 +93,8 @@ int main(int argc, char **argv) int new_error=myisamchk(&check_param, *(argv++)); if ((check_param.testflag & T_REP_ANY) != T_REP) check_param.testflag&= ~T_REP; - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); if ((check_param.error_printed | check_param.warning_printed) && (check_param.testflag & T_FORCE_CREATE) && (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS | @@ -112,15 +106,15 @@ int main(int argc, char **argv) check_param.testflag&= ~T_EXTEND; /* Don't needed */ error|=myisamchk(&check_param, argv[-1]); check_param.testflag= old_testflag; - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); } else error|=new_error; if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO)) { puts("\n---------\n"); - VOID(fflush(stdout)); + (void) fflush(stdout); } } if (check_param.total_files > 1) @@ -148,7 +142,7 @@ enum options_mc { OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE, OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN, OPT_FT_MAX_WORD_LEN, OPT_FT_STOPWORD_FILE, - OPT_MAX_RECORD_LENGTH, OPT_AUTO_CLOSE, OPT_STATS_METHOD + OPT_MAX_RECORD_LENGTH, OPT_STATS_METHOD }; static struct my_option my_long_options[] = @@ -156,10 +150,6 @@ static struct my_option my_long_options[] = {"analyze", 'a', "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifdef __NETWARE__ - {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#endif {"block-search", 'b', "No help available.", 0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -252,9 +242,6 @@ static struct my_option my_long_options[] = {"set-collation", OPT_SET_COLLATION, "Change the collation used by the index", &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"set-variable", 'O', - "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"silent", 's', "Only print errors. One can use two -s to make myisamchk very silent.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -339,13 +326,10 @@ static struct my_option my_long_options[] = }; -#include <help_start.h> - static void print_version(void) { printf("%s Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); - NETWARE_SET_SCREEN_MODE(1); } @@ -365,13 +349,9 @@ static void usage(void) printf("\ -H, --HELP Display this help and exit.\n\ -?, --help Display this help and exit.\n\ - -O, --set-variable var=option.\n\ - Change the value of a variable. Please note that\n\ - this option is deprecated; you can set variables\n\ - directly with '--variable-name=value'.\n\ -t, --tmpdir=path Path for temporary files. Multiple paths can be\n\ specified, separated by "); -#if defined( __WIN__) || defined(__NETWARE__) +#if defined( __WIN__) printf("semicolon (;)"); #else printf("colon (:)"); @@ -467,7 +447,6 @@ static void usage(void) my_print_variables(my_long_options); } -#include <help_end.h> const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal", "nulls_ignored", NullS}; @@ -483,11 +462,6 @@ get_one_option(int optid, char *argument) { switch (optid) { -#ifdef __NETWARE__ - case OPT_AUTO_CLOSE: - setscreenmode(SCR_AUTOCLOSE_ON_EXIT); - break; -#endif case 'a': if (argument == disabled_my_option) check_param.testflag&= ~T_STATISTICS; @@ -739,7 +713,9 @@ static void get_options(register int *argc,register char ***argv) { int ho_error; - load_defaults("my", load_default_groups, argc, argv); + if (load_defaults("my", load_default_groups, argc, argv)) + exit(1); + default_argv= *argv; if (isatty(fileno(stdout))) check_param.testflag|=T_WRITE_LOOP; @@ -761,9 +737,9 @@ static void get_options(register int *argc,register char ***argv) if ((check_param.testflag & T_UNPACK) && (check_param.testflag & (T_QUICK | T_SORT_RECORDS))) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "%s: --unpack can't be used with --quick or --sort-records\n", - my_progname_short)); + my_progname_short); exit(1); } if ((check_param.testflag & T_READONLY) && @@ -771,9 +747,9 @@ static void get_options(register int *argc,register char ***argv) (T_REP_ANY | T_STATISTICS | T_AUTO_INC | T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE))) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "%s: Can't use --readonly when repairing or sorting\n", - my_progname_short)); + my_progname_short); exit(1); } @@ -799,7 +775,6 @@ static int myisamchk(MI_CHECK *param, char * filename) { int error,lock_type,recreate; int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS); - uint raid_chunks; MI_INFO *info; File datafile; char llbuff[22],llbuff2[22]; @@ -861,7 +836,6 @@ static int myisamchk(MI_CHECK *param, char * filename) share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */ share->tot_locks-= share->r_locks; share->r_locks=0; - raid_chunks=share->base.raid_chunks; /* Skip the checking of the file if: @@ -927,9 +901,9 @@ static int myisamchk(MI_CHECK *param, char * filename) param->language= set_collation->number; if (recreate_table(param, &info,filename)) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is not fixed because of errors\n", - filename)); + filename); return(-1); } recreate=1; @@ -1029,10 +1003,8 @@ static int myisamchk(MI_CHECK *param, char * filename) #ifndef TO_BE_REMOVED if (param->out_flag & O_NEW_DATA) { /* Change temp file to org file */ - VOID(my_close(info->dfile,MYF(MY_WME))); /* Close new file */ - error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT, - raid_chunks, - MYF(0)); + (void) my_close(info->dfile,MYF(MY_WME)); /* Close new file */ + error|=change_to_newfile(filename, MI_NAME_DEXT, DATA_TMP_EXT, MYF(0)); if (mi_open_datafile(info,info->s, NULL, -1)) error=1; param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */ @@ -1100,23 +1072,23 @@ static int myisamchk(MI_CHECK *param, char * filename) !(param->testflag & (T_FAST | T_FORCE_CREATE))) { if (param->testflag & (T_EXTEND | T_MEDIUM)) - VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size, - (size_t) param->use_buffers, 0, 0)); - VOID(init_io_cache(¶m->read_cache,datafile, + (void) init_key_cache(dflt_key_cache,opt_key_cache_block_size, + param->use_buffers, 0, 0); + (void) init_io_cache(¶m->read_cache,datafile, (uint) param->read_buffer_length, READ_CACHE, (param->start_check_pos ? param->start_check_pos : share->pack.header_length), 1, - MYF(MY_WME))); + MYF(MY_WME)); lock_memory(param); if ((info->s->options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) || (param->testflag & (T_EXTEND | T_MEDIUM))) error|=chk_data_link(param, info, param->testflag & T_EXTEND); error|=flush_blocks(param, share->key_cache, share->kfile); - VOID(end_io_cache(¶m->read_cache)); + (void) end_io_cache(¶m->read_cache); } if (!error) { @@ -1149,7 +1121,7 @@ static int myisamchk(MI_CHECK *param, char * filename) (state_updated ? UPDATE_STAT : 0) | ((param->testflag & T_SORT_RECORDS) ? UPDATE_SORT : 0))); - VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename)); + (void) lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename); info->update&= ~HA_STATE_CHANGED; } mi_lock_database(info, F_UNLCK); @@ -1163,37 +1135,35 @@ end2: { if (param->out_flag & O_NEW_DATA) error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT, - raid_chunks, ((param->testflag & T_BACKUP_DATA) ? MYF(MY_REDEL_MAKE_BACKUP) : MYF(0))); if (param->out_flag & O_NEW_INDEX) - error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0, - MYF(0)); + error|=change_to_newfile(filename, MI_NAME_IEXT, INDEX_TMP_EXT, MYF(0)); } - VOID(fflush(stdout)); VOID(fflush(stderr)); + (void) fflush(stdout); (void) fflush(stderr); if (param->error_printed) { if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX)) { - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is not fixed because of errors\n", - filename)); + filename); if (param->testflag & T_REP_ANY) - VOID(fprintf(stderr, - "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n")); + (void) fprintf(stderr, + "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"); } else if (!(param->error_printed & 2) && !(param->testflag & T_FORCE_CREATE)) - VOID(fprintf(stderr, + (void) fprintf(stderr, "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n", - filename)); + filename); } else if (param->warning_printed && ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE))) - VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n", - filename)); - VOID(fflush(stderr)); + (void) fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n", + filename); + (void) fflush(stderr); DBUG_RETURN(error); } /* myisamchk */ @@ -1264,16 +1234,9 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) share->base.auto_key, llstr(share->state.auto_increment,llbuff)); } - if (share->base.raid_type) - { - printf("RAID: Type: %u Chunks: %u Chunksize: %lu\n", - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize); - } if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) printf("Checksum: %23s\n",llstr(info->state->checksum,llbuff)); -; + if (share->options & HA_OPTION_DELAY_KEY_WRITE) printf("Keys are only flushed at close\n"); @@ -1320,7 +1283,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("Key Start Len Index Type"); if (param->testflag & T_VERBOSE) printf(" Rec/key Root Blocksize"); - VOID(putchar('\n')); + (void) putchar('\n'); for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ; key < share->base.keys; @@ -1359,7 +1322,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("%11lu %12s %10d", share->state.rec_per_key_part[keyseg_nr++], buff,keyinfo->block_length); - VOID(putchar('\n')); + (void) putchar('\n'); while ((++keyseg)->type != HA_KEYTYPE_END) { pos=buff; @@ -1378,7 +1341,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) (long) keyseg->start+1,keyseg->length,buff); if (param->testflag & T_VERBOSE) printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]); - VOID(putchar('\n')); + (void) putchar('\n'); } keyseg++; } @@ -1416,7 +1379,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) printf("\nField Start Length Nullpos Nullbit Type"); if (share->options & HA_OPTION_COMPRESS_RECORD) printf(" Huff tree Bits"); - VOID(putchar('\n')); + (void) putchar('\n'); start=1; for (field=0 ; field < share->base.fields ; field++) { @@ -1455,7 +1418,7 @@ static void descript(MI_CHECK *param, register MI_INFO *info, char * name) (uint) (share->rec[field].huff_tree-share->decode_trees)+1, share->rec[field].huff_tree->quick_table_bits); } - VOID(putchar('\n')); + (void) putchar('\n'); start+=share->rec[field].length; } } @@ -1544,14 +1507,11 @@ static int mi_sort_records(MI_CHECK *param, goto err; } fn_format(param->temp_filename,name,"", MI_NAME_DEXT,2+4+32); - new_file=my_raid_create(fn_format(param->temp_filename, - param->temp_filename,"", - DATA_TMP_EXT,2+4), - 0,param->tmpfile_createflag, - share->base.raid_type, - share->base.raid_chunks, - share->base.raid_chunksize, - MYF(0)); + new_file= my_create(fn_format(param->temp_filename, + param->temp_filename, "", + DATA_TMP_EXT, 2+4), + 0, param->tmpfile_createflag, + MYF(0)); if (new_file < 0) { mi_check_print_error(param,"Can't create new tempfile: '%s'", @@ -1603,7 +1563,7 @@ static int mi_sort_records(MI_CHECK *param, goto err; } - VOID(my_close(info->dfile,MYF(MY_WME))); + (void) my_close(info->dfile,MYF(MY_WME)); param->out_flag|=O_NEW_DATA; /* Data in new file */ info->dfile=new_file; /* Use new datafile */ info->state->del=0; @@ -1617,27 +1577,25 @@ static int mi_sort_records(MI_CHECK *param, if (param->testflag & T_WRITE_LOOP) { - VOID(fputs(" \r",stdout)); VOID(fflush(stdout)); + (void) fputs(" \r",stdout); (void) fflush(stdout); } got_error=0; err: if (got_error && new_file >= 0) { - VOID(end_io_cache(&info->rec_cache)); + (void) end_io_cache(&info->rec_cache); (void) my_close(new_file,MYF(MY_WME)); - (void) my_raid_delete(param->temp_filename, share->base.raid_chunks, - MYF(MY_WME)); + (void) my_delete(param->temp_filename, MYF(MY_WME)); } if (temp_buff) { my_afree((uchar*) temp_buff); } - my_free(mi_get_rec_buff_ptr(info, sort_param.record), - MYF(MY_ALLOW_ZERO_PTR)); + my_free(mi_get_rec_buff_ptr(info, sort_param.record)); info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); - VOID(end_io_cache(&info->rec_cache)); - my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR)); + (void) end_io_cache(&info->rec_cache); + my_free(sort_info.buff); sort_info.buff=0; share->state.sortkey=sort_key; DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) | @@ -1677,7 +1635,6 @@ static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info, endpos=buff+used_length; for ( ;; ) { - _sanity(__FILE__,__LINE__); if (nod_flag) { next_page=_mi_kpos(nod_flag,keypos); @@ -1693,7 +1650,6 @@ static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info, new_file, update_index)) goto err; } - _sanity(__FILE__,__LINE__); if (keypos >= endpos || (key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,lastkey)) == 0) @@ -1760,8 +1716,8 @@ void mi_check_print_info(MI_CHECK *param __attribute__((unused)), va_list args; va_start(args,fmt); - VOID(vfprintf(stdout, fmt, args)); - VOID(fputc('\n',stdout)); + (void) vfprintf(stdout, fmt, args); + (void) fputc('\n',stdout); va_end(args); } @@ -1783,8 +1739,8 @@ void mi_check_print_warning(MI_CHECK *param, const char *fmt,...) param->warning_printed=1; va_start(args,fmt); fprintf(stderr,"%s: warning: ",my_progname_short); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); + (void) vfprintf(stderr, fmt, args); + (void) fputc('\n',stderr); fflush(stderr); va_end(args); DBUG_VOID_RETURN; @@ -1808,9 +1764,11 @@ void mi_check_print_error(MI_CHECK *param, const char *fmt,...) param->error_printed|=1; va_start(args,fmt); fprintf(stderr,"%s: error: ",my_progname_short); - VOID(vfprintf(stderr, fmt, args)); - VOID(fputc('\n',stderr)); + (void) vfprintf(stderr, fmt, args); + (void) fputc('\n',stderr); fflush(stderr); va_end(args); DBUG_VOID_RETURN; } + +#include "mi_extrafunc.h" diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index 962155e884c..c7f0cb27a40 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,9 +24,11 @@ #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 */ +/* undef map from my_nosys; We need test-if-disk full */ +#if defined(my_write) +#undef my_write #endif typedef struct st_mi_status_info @@ -129,9 +131,6 @@ typedef struct st_mi_base_info /* Extra allocation when using dynamic record format */ uint extra_alloc_bytes; uint extra_alloc_procent; - /* Info about raid */ - uint raid_type,raid_chunks; - ulong raid_chunksize; /* The following are from the header */ uint key_parts,all_key_parts; } MI_BASE_INFO; @@ -165,6 +164,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */ MI_COLUMNDEF *rec; /* Pointer to field information */ MI_PACK pack; /* Data about packed records */ MI_BLOB *blobs; /* Pointer to blobs */ + LIST *in_use; /* List of threads using this table */ char *unique_file_name; /* realpath() of index file */ char *data_file_name, /* Resolved path names from symlinks */ *index_file_name; @@ -213,13 +213,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; @@ -242,6 +242,7 @@ struct st_myisam_info { DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */ MEM_ROOT ft_memroot; /* used by the parser */ MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */ + LIST in_use; /* Thread using this table */ char *filename; /* parameter to open filename */ uchar *buff, /* Temp area for key */ *lastkey,*lastkey2; /* Last used search key */ @@ -344,11 +345,11 @@ typedef struct st_mi_sort_param int (*key_read)(struct st_mi_sort_param *,void *); int (*key_write)(struct st_mi_sort_param *, const void *); void (*lock_in_memory)(MI_CHECK *); - NEAR int (*write_keys)(struct st_mi_sort_param *, register uchar **, - uint , struct st_buffpek *, IO_CACHE *); - NEAR uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); - NEAR int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *, - uint, uint); + int (*write_keys)(struct st_mi_sort_param *, register uchar **, + uint , struct st_buffpek *, IO_CACHE *); + uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); + int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *, + uint, uint); } MI_SORT_PARAM; /* Some defines used by isam-funktions */ @@ -385,8 +386,10 @@ typedef struct st_mi_sort_param #define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\ mi_int2store(x,boh); } #define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0) +#define mi_report_crashed(A, B) _mi_report_crashed((A), (B), __FILE__, __LINE__) #define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \ DBUG_PRINT("error", ("Marked table crashed")); \ + mi_report_crashed((x), 0); \ }while(0) #define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \ STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \ @@ -459,19 +462,19 @@ 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 */ extern LIST *myisam_open_list; -extern uchar NEAR myisam_file_magic[],NEAR myisam_pack_file_magic[]; -extern uint NEAR myisam_read_vec[],NEAR myisam_readnext_vec[]; +extern uchar myisam_file_magic[], myisam_pack_file_magic[]; +extern uint myisam_read_vec[], myisam_readnext_vec[]; extern uint myisam_quick_table_bits; extern File myisam_log_file; extern ulong myisam_pid; @@ -539,10 +542,6 @@ void _mi_store_static_key(MI_KEYDEF *keyinfo, uchar *key_pos, MI_KEY_PARAM *s_temp); void _mi_store_var_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, MI_KEY_PARAM *s_temp); -#ifdef NOT_USED -void _mi_store_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, - MI_KEY_PARAM *s_temp); -#endif void _mi_store_bin_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, MI_KEY_PARAM *s_temp); @@ -764,12 +763,14 @@ void mi_setup_functions(register MYISAM_SHARE *share); my_bool mi_dynmap_file(MI_INFO *info, my_off_t size); int mi_munmap_file(MI_INFO *info); void mi_remap_file(MI_INFO *info, my_off_t size); +void _mi_report_crashed(MI_INFO *file, const char *message, + const char *sfile, uint sline); /* Functions needed by mi_check */ volatile int *killed_ptr(MI_CHECK *param); -void mi_check_print_error _VARARGS((MI_CHECK *param, const char *fmt,...)); -void mi_check_print_warning _VARARGS((MI_CHECK *param, const char *fmt,...)); -void mi_check_print_info _VARARGS((MI_CHECK *param, const char *fmt,...)); +void mi_check_print_error(MI_CHECK *param, const char *fmt,...); +void mi_check_print_warning(MI_CHECK *param, const char *fmt,...); +void mi_check_print_info(MI_CHECK *param, const char *fmt,...); int flush_pending_blocks(MI_SORT_PARAM *param); int sort_ft_buf_flush(MI_SORT_PARAM *sort_param); int thr_write_keys(MI_SORT_PARAM *sort_param); @@ -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/myisamlog.c b/storage/myisam/myisamlog.c index 7e0d0a442a5..84743b8da51 100644 --- a/storage/myisam/myisamlog.c +++ b/storage/myisam/myisamlog.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) if (re_open_count) printf("Had to do %d re-open because of too few possibly open files\n", re_open_count); - VOID(mi_panic(HA_PANIC_CLOSE)); + (void) mi_panic(HA_PANIC_CLOSE); my_free_open_file_info(); my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); exit(error); @@ -248,7 +248,6 @@ static void get_options(register int *argc, register char ***argv) /* Fall through */ case 'I': case '?': -#include <help_start.h> printf("%s Ver 1.4 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE); puts("By Monty, for your professional use\n"); @@ -270,7 +269,6 @@ static void get_options(register int *argc, register char ***argv) puts("If a recover is done all writes and all possibly updates and deletes is done\nand errors are only counted."); puts("If one gives table names as arguments only these tables will be updated\n"); help=1; -#include <help_end.h> break; default: printf("illegal option: \"-%c\"\n",*pos); @@ -292,8 +290,8 @@ static void get_options(register int *argc, register char ***argv) } return; err: - VOID(fprintf(stderr,"option \"%c\" used without or with wrong argument\n", - option)); + (void) fprintf(stderr,"option \"%c\" used without or with wrong argument\n", + option); exit(1); } @@ -332,8 +330,8 @@ static int examine_log(char * file_name, char **table_names) bzero((uchar*) com_count,sizeof(com_count)); init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1, (tree_element_free) file_info_free, NULL); - VOID(init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, - 0, 0)); + (void) init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, + 0, 0); files_open=0; access_time=0; while (access_time++ != number_of_commands && @@ -412,8 +410,8 @@ static int examine_log(char * file_name, char **table_names) } open_param.name=file_info.name; open_param.max_id=0; - VOID(tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, - left_root_right)); + (void) tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, + left_root_right); file_info.id=open_param.max_id+1; /* * In the line below +10 is added to accomodate '<' and '>' chars @@ -458,7 +456,7 @@ static int examine_log(char * file_name, char **table_names) files_open++; file_info.closed=0; } - VOID(tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg)); + (void) tree_insert(&tree, (uchar*) &file_info, 0, tree.custom_arg); if (file_info.used) { if (verbose && !record_pos_file) @@ -477,7 +475,7 @@ static int examine_log(char * file_name, char **table_names) { if (!curr_file_info->closed) files_open--; - VOID(tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg)); + (void) tree_delete(&tree, (uchar*) curr_file_info, 0, tree.custom_arg); } break; case MI_LOG_EXTRA: @@ -493,10 +491,10 @@ static int examine_log(char * file_name, char **table_names) if (mi_extra(curr_file_info->isam, extra_command, 0) != (int) result) { fflush(stdout); - VOID(fprintf(stderr, + (void) fprintf(stderr, "Warning: error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], - llstr(isamlog_filepos,llbuff))); + llstr(isamlog_filepos,llbuff)); fflush(stderr); } } @@ -616,12 +614,12 @@ static int examine_log(char * file_name, char **table_names) } } } - my_free(buff,MYF(0)); + my_free(buff); break; case MI_LOG_LOCK: if (my_b_read(&cache,(uchar*) head,sizeof(lock_command))) goto err; - memcpy_fixed(&lock_command,head,sizeof(lock_command)); + memcpy(&lock_command, head, sizeof(lock_command)); if (verbose && !record_pos_file && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s(%d) -> %d\n",FILENAME(curr_file_info), @@ -641,39 +639,39 @@ static int examine_log(char * file_name, char **table_names) break; default: fflush(stdout); - VOID(fprintf(stderr, + (void) fprintf(stderr, "Error: found unknown command %d in logfile, aborted\n", - command)); + command); fflush(stderr); goto end; } } end_key_cache(dflt_key_cache,1); delete_tree(&tree); - VOID(end_io_cache(&cache)); - VOID(my_close(file,MYF(0))); + (void) end_io_cache(&cache); + (void) my_close(file,MYF(0)); if (write_file && my_fclose(write_file,MYF(MY_WME))) DBUG_RETURN(1); DBUG_RETURN(0); err: fflush(stdout); - VOID(fprintf(stderr,"Got error %d when reading from logfile\n",my_errno)); + (void) fprintf(stderr,"Got error %d when reading from logfile\n",my_errno); fflush(stderr); goto end; com_err: fflush(stdout); - VOID(fprintf(stderr,"Got error %d, expected %d on command %s at %s\n", + (void) fprintf(stderr,"Got error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], - llstr(isamlog_filepos,llbuff))); + llstr(isamlog_filepos,llbuff)); fflush(stderr); end: end_key_cache(dflt_key_cache, 1); delete_tree(&tree); - VOID(end_io_cache(&cache)); - VOID(my_close(file,MYF(0))); + (void) end_io_cache(&cache); + (void) my_close(file,MYF(0)); if (write_file) - VOID(my_fclose(write_file,MYF(MY_WME))); + (void) my_fclose(write_file,MYF(MY_WME)); DBUG_RETURN(1); } @@ -683,12 +681,12 @@ static int read_string(IO_CACHE *file, register uchar* *to, register uint length DBUG_ENTER("read_string"); if (*to) - my_free((uchar*) *to,MYF(0)); + my_free(*to); if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) || my_b_read(file,(uchar*) *to,length)) { if (*to) - my_free(*to,MYF(0)); + my_free(*to); *to= 0; DBUG_RETURN(1); } @@ -730,7 +728,7 @@ static void fix_blob_pointers(MI_INFO *info, uchar *record) blob != end ; blob++) { - memcpy_fixed(record+blob->offset+blob->pack_length,&pos,sizeof(char*)); + memcpy(record+blob->offset+blob->pack_length, &pos, sizeof(char*)); pos+=_mi_calc_blob_length(blob->pack_length,record+blob->offset); } } @@ -757,12 +755,12 @@ static void file_info_free(struct file_info *fileinfo) if (update) { if (!fileinfo->closed) - VOID(mi_close(fileinfo->isam)); + (void) mi_close(fileinfo->isam); if (fileinfo->record) - my_free(fileinfo->record,MYF(0)); + my_free(fileinfo->record); } - my_free(fileinfo->name,MYF(0)); - my_free(fileinfo->show_name,MYF(0)); + my_free(fileinfo->name); + my_free(fileinfo->show_name); DBUG_VOID_RETURN; } @@ -775,8 +773,8 @@ static int close_some_file(TREE *tree) access_param.min_accessed=LONG_MAX; access_param.found=0; - VOID(tree_walk(tree,(tree_walk_action) test_when_accessed, - (void*) &access_param,left_root_right)); + (void) tree_walk(tree,(tree_walk_action) test_when_accessed, + (void*) &access_param,left_root_right); if (!access_param.found) return 1; /* No open file that is possibly to close */ if (mi_close(access_param.found->isam)) @@ -815,7 +813,7 @@ static int find_record_with_key(struct file_info *file_info, uchar *record) if (mi_is_key_active(info->s->state.key_map, key) && info->s->keyinfo[key].flag & HA_NOSAME) { - VOID(_mi_make_key(info,key,tmp_key,record,0L)); + (void) _mi_make_key(info,key,tmp_key,record,0L); return mi_rkey(info,file_info->record,(int) key,tmp_key,0, HA_READ_KEY_EXACT); } @@ -845,3 +843,5 @@ static my_bool cmp_filename(struct file_info *file_info, char * name) return 1; return strcmp(file_info->name,name) ? 1 : 0; } + +#include "mi_extrafunc.h" diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 5fcfbae8f8f..84a7f2a1ba9 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -23,9 +23,6 @@ #include <queues.h> #include <my_tree.h> #include "mysys_err.h" -#ifdef MSDOS -#include <io.h> -#endif #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ /* Skip warnings in getopt.h */ #endif @@ -44,6 +41,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 +123,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, @@ -208,15 +207,21 @@ int main(int argc, char **argv) char **default_argv; MY_INIT(argv[0]); - load_defaults("my",load_default_groups,&argc,&argv); + if (load_defaults("my",load_default_groups,&argc,&argv)) + exit(1); + default_argv= argv; get_options(&argc,&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--) @@ -238,8 +243,8 @@ int main(int argc, char **argv) } if (ok && isamchk_neaded && !silent) puts("Remember to run myisamchk -rq on compressed tables"); - VOID(fflush(stdout)); - VOID(fflush(stderr)); + (void) fflush(stdout); + (void) fflush(stderr); free_defaults(default_argv); my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); exit(error ? 2 : 0); @@ -248,14 +253,10 @@ int main(int argc, char **argv) #endif } -enum options_mp {OPT_CHARSETS_DIR_MP=256, OPT_AUTO_CLOSE}; +enum options_mp {OPT_CHARSETS_DIR_MP=256}; static struct my_option my_long_options[] = { -#ifdef __NETWARE__ - {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#endif {"backup", 'b', "Make a backup of the table as table_name.OLD.", &backup, &backup, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"character-sets-dir", OPT_CHARSETS_DIR_MP, @@ -287,13 +288,11 @@ static struct my_option my_long_options[] = { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; -#include <help_start.h> static void print_version(void) { - VOID(printf("%s Ver 1.23 for %s on %s\n", - my_progname, SYSTEM_TYPE, MACHINE_TYPE)); - NETWARE_SET_SCREEN_MODE(1); + printf("%s Ver 1.23 for %s on %s\n", + my_progname, SYSTEM_TYPE, MACHINE_TYPE); } @@ -309,13 +308,12 @@ static void usage(void) puts("afterwards to update the keys."); puts("You should give the .MYI file as the filename argument."); - VOID(printf("\nUsage: %s [OPTIONS] filename...\n", my_progname)); + printf("\nUsage: %s [OPTIONS] filename...\n", my_progname); my_print_help(my_long_options); print_defaults("my", load_default_groups); my_print_variables(my_long_options); } -#include <help_end.h> static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), @@ -324,11 +322,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), uint length; switch(optid) { -#ifdef __NETWARE__ - case OPT_AUTO_CLOSE: - setscreenmode(SCR_AUTOCLOSE_ON_EXIT); - break; -#endif case 'f': force_pack= 1; tmpfile_createflag= O_RDWR | O_TRUNC; @@ -407,7 +400,7 @@ static MI_INFO *open_isam_file(char *name,int mode) (opt_wait ? HA_OPEN_WAIT_IF_LOCKED : HA_OPEN_ABORT_IF_LOCKED)))) { - VOID(fprintf(stderr, "%s gave error %d on open\n", name, my_errno)); + (void) fprintf(stderr, "%s gave error %d on open\n", name, my_errno); DBUG_RETURN(0); } share=isam_file->s; @@ -415,8 +408,8 @@ static MI_INFO *open_isam_file(char *name,int mode) { if (!force_pack) { - VOID(fprintf(stderr, "%s is already compressed\n", name)); - VOID(mi_close(isam_file)); + (void) fprintf(stderr, "%s is already compressed\n", name); + (void) mi_close(isam_file); DBUG_RETURN(0); } if (verbose) @@ -427,11 +420,11 @@ static MI_INFO *open_isam_file(char *name,int mode) (share->state.state.records <= 1 || share->state.state.data_file_length < 1024)) { - VOID(fprintf(stderr, "%s is too small to compress\n", name)); - VOID(mi_close(isam_file)); + (void) fprintf(stderr, "%s is too small to compress\n", name); + (void) mi_close(isam_file); DBUG_RETURN(0); } - VOID(mi_lock_database(isam_file,F_WRLCK)); + (void) mi_lock_database(isam_file,F_WRLCK); DBUG_RETURN(isam_file); } @@ -473,12 +466,12 @@ static my_bool open_isam_files(PACK_MRG_INFO *mrg, char **names, uint count) return 0; diff_file: - VOID(fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n", - my_progname, names[j], names[j+1])); + (void) fprintf(stderr, "%s: Tables '%s' and '%s' are not identical\n", + my_progname, names[j], names[j+1]); error: while (i--) mi_close(mrg->file[i]); - my_free((uchar*) mrg->file,MYF(0)); + my_free(mrg->file); return 1; } @@ -506,16 +499,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) /* Create temporary or join file */ if (backup) - VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2)); + (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2); else - VOID(fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16)); + (void) fn_format(org_name,isam_file->filename,"",MI_NAME_DEXT,2+4+16); if (!test_only && result_table) { /* Make a new indexfile based on first file in list */ uint length; uchar *buff; strmov(org_name,result_table); /* Fix error messages */ - VOID(fn_format(new_name,result_table,"",MI_NAME_IEXT,2)); + (void) fn_format(new_name,result_table,"",MI_NAME_IEXT,2); if ((join_isam_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME))) < 0) goto err; @@ -526,16 +519,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) my_write(join_isam_file,buff,length, MYF(MY_WME | MY_NABP | MY_WAIT_IF_FULL))) { - my_free(buff,MYF(0)); + my_free(buff); goto err; } - my_free(buff,MYF(0)); - VOID(fn_format(new_name,result_table,"",MI_NAME_DEXT,2)); + my_free(buff); + (void) fn_format(new_name,result_table,"",MI_NAME_DEXT,2); } else if (!tmp_dir[0]) - VOID(make_new_name(new_name,org_name)); + (void) make_new_name(new_name,org_name); else - VOID(fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4)); + (void) fn_format(new_name,org_name,tmp_dir,DATA_TMP_EXT,1+2+4); if (!test_only && (new_file=my_create(new_name,0,tmpfile_createflag,MYF(MY_WME))) < 0) goto err; @@ -551,22 +544,21 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) (ulong) mrg->records)); if (write_loop || verbose) { - VOID(printf("Compressing %s: (%lu records)\n", - result_table ? new_name : org_name, (ulong) mrg->records)); + printf("Compressing %s: (%lu records)\n", + result_table ? new_name : org_name, (ulong) mrg->records); } trees=fields=share->base.fields; huff_counts=init_huff_count(isam_file,mrg->records); - QUICK_SAFEMALLOC; /* Read the whole data file(s) for statistics. */ DBUG_PRINT("info", ("- Calculating statistics")); if (write_loop || verbose) - VOID(printf("- Calculating statistics\n")); + printf("- Calculating statistics\n"); if (get_statistic(mrg,huff_counts)) goto err; - NORMAL_SAFEMALLOC; + old_length=0; for (i=0; i < mrg->count ; i++) old_length+= (mrg->file[i]->s->state.state.data_file_length - @@ -613,7 +605,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) */ file_buffer.pos_in_file=HEAD_LENGTH; if (! test_only) - VOID(my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0))); + my_seek(new_file,file_buffer.pos_in_file,MY_SEEK_SET,MYF(0)); /* Write field infos: field type, pack type, length bits, tree number. @@ -639,7 +631,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) */ DBUG_PRINT("info", ("- Compressing file")); if (write_loop || verbose) - VOID(printf("- Compressing file\n")); + printf("- Compressing file\n"); error=compress_isam_file(mrg,huff_counts); new_length=file_buffer.pos_in_file; if (!error && !test_only) @@ -666,9 +658,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) mrg->min_pack_length, mrg->max_pack_length, (ulong) (mrg->records ? (new_length/mrg->records) : 0))); if (verbose && mrg->records) - VOID(printf("Min record length: %6d Max length: %6d " + printf("Min record length: %6d Max length: %6d " "Mean total length: %6ld\n", mrg->min_pack_length, - mrg->max_pack_length, (ulong) (new_length/mrg->records))); + mrg->max_pack_length, (ulong) (new_length/mrg->records)); /* Close source and target file. */ if (!test_only) @@ -704,9 +696,9 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error=my_rename(new_name,org_name,MYF(MY_WME)); if (!error) { - VOID(my_copystat(temp_name,org_name,MYF(MY_COPYTIME))); + (void) my_copystat(temp_name,org_name,MYF(MY_COPYTIME)); if (tmp_dir[0]) - VOID(my_delete(new_name,MYF(MY_WME))); + (void) my_delete(new_name,MYF(MY_WME)); } } } @@ -717,7 +709,7 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error=my_copy(new_name,org_name, MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_COPYTIME)); if (!error) - VOID(my_delete(new_name,MYF(MY_WME))); + (void) my_delete(new_name,MYF(MY_WME)); } else error=my_redel(org_name,new_name,MYF(MY_WME | MY_COPYTIME)); @@ -731,16 +723,16 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) error|=my_close(join_isam_file,MYF(MY_WME)); if (error) { - VOID(fprintf(stderr, "Aborting: %s is not compressed\n", org_name)); - VOID(my_delete(new_name,MYF(MY_WME))); + (void) fprintf(stderr, "Aborting: %s is not compressed\n", org_name); + (void) my_delete(new_name,MYF(MY_WME)); DBUG_RETURN(-1); } if (write_loop || verbose) { if (old_length) - VOID(printf("%.4g%% \n", + printf("%.4g%% \n", (((longlong) (old_length - new_length)) * 100.0 / - (longlong) old_length))); + (longlong) old_length)); else puts("Empty file saved in compressed format"); } @@ -749,14 +741,52 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) err: free_counts_and_tree_and_queue(huff_trees,trees,huff_counts,fields); if (new_file >= 0) - VOID(my_close(new_file,MYF(0))); + (void) my_close(new_file,MYF(0)); if (join_isam_file >= 0) - VOID(my_close(join_isam_file,MYF(0))); + (void) my_close(join_isam_file,MYF(0)); mrg_close(mrg); - VOID(fprintf(stderr, "Aborted: %s is not compressed\n", org_name)); + (void) fprintf(stderr, "Aborted: %s is not compressed\n", org_name); 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) @@ -811,11 +841,11 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, for (i=0 ; i < trees ; i++) { if (huff_trees[i].element_buffer) - my_free((uchar*) huff_trees[i].element_buffer,MYF(0)); + my_free(huff_trees[i].element_buffer); if (huff_trees[i].code) - my_free((uchar*) huff_trees[i].code,MYF(0)); + my_free(huff_trees[i].code); } - my_free((uchar*) huff_trees,MYF(0)); + my_free(huff_trees); } if (huff_counts) { @@ -823,11 +853,11 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, { if (huff_counts[i].tree_buff) { - my_free((uchar*) huff_counts[i].tree_buff,MYF(0)); + my_free(huff_counts[i].tree_buff); delete_tree(&huff_counts[i].int_tree); } } - my_free((uchar*) huff_counts,MYF(0)); + my_free(huff_counts); } delete_queue(&queue); /* This is safe to free */ return; @@ -931,7 +961,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) count->int_tree.elements_in_tree > 1)) { delete_tree(&count->int_tree); - my_free(count->tree_buff,MYF(0)); + my_free(count->tree_buff); count->tree_buff=0; } else @@ -1010,7 +1040,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) { uint field_length=count->field_length -portable_sizeof_char_ptr; ulong blob_length= _mi_calc_blob_length(field_length, start_pos); - memcpy_fixed((char*) &pos, start_pos+field_length,sizeof(char*)); + memcpy(&pos, start_pos+field_length, sizeof(char*)); end_pos=pos+blob_length; tot_blob_length+=blob_length; set_if_bigger(count->max_length,blob_length); @@ -1069,13 +1099,13 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) record_count++; if (write_loop && record_count % WRITE_COUNT == 0) { - VOID(printf("%lu\r", (ulong) record_count)); - VOID(fflush(stdout)); + printf("%lu\r", (ulong) record_count); + (void) fflush(stdout); } } else if (error != HA_ERR_RECORD_DELETED) { - VOID(fprintf(stderr, "Got error %d while reading rows", error)); + (void) fprintf(stderr, "Got error %d while reading rows", error); break; } @@ -1083,8 +1113,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) } if (write_loop) { - VOID(printf(" \r")); - VOID(fflush(stdout)); + printf(" \r"); + (void) fflush(stdout); } /* @@ -1096,8 +1126,8 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("Found the following number of incidents " "of the byte codes:")); if (verbose >= 2) - VOID(printf("Found the following number of incidents " - "of the byte codes:\n")); + printf("Found the following number of incidents " + "of the byte codes:\n"); for (count= huff_counts ; count < end_count; count++) { uint idx; @@ -1106,16 +1136,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("column: %3u", (uint) (count - huff_counts + 1))); if (verbose >= 2) - VOID(printf("column: %3u\n", (uint) (count - huff_counts + 1))); + printf("column: %3u\n", (uint) (count - huff_counts + 1)); if (count->tree_buff) { DBUG_PRINT("info", ("number of distinct values: %u", (uint) ((count->tree_pos - count->tree_buff) / count->field_length))); if (verbose >= 2) - VOID(printf("number of distinct values: %u\n", + printf("number of distinct values: %u\n", (uint) ((count->tree_pos - count->tree_buff) / - count->field_length))); + count->field_length)); } total_count= 0; for (idx= 0; idx < 256; idx++) @@ -1126,16 +1156,16 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) DBUG_PRINT("info", ("counts[0x%02x]: %12s", idx, llstr((longlong) count->counts[idx], llbuf))); if (verbose >= 2) - VOID(printf("counts[0x%02x]: %12s\n", idx, - llstr((longlong) count->counts[idx], llbuf))); + printf("counts[0x%02x]: %12s\n", idx, + llstr((longlong) count->counts[idx], llbuf)); } } DBUG_PRINT("info", ("total: %12s", llstr((longlong) total_count, llbuf))); if ((verbose >= 2) && total_count) { - VOID(printf("total: %12s\n", - llstr((longlong) total_count, llbuf))); + printf("total: %12s\n", + llstr((longlong) total_count, llbuf)); } } @@ -1328,12 +1358,12 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, } else { - my_free((uchar*) huff_counts->tree_buff,MYF(0)); + my_free(huff_counts->tree_buff); delete_tree(&huff_counts->int_tree); huff_counts->tree_buff=0; } if (tree.element_buffer) - my_free((uchar*) tree.element_buffer,MYF(0)); + my_free(tree.element_buffer); } if (huff_counts->pack_type & PACK_TYPE_SPACE_FIELDS) space_fields++; @@ -1352,7 +1382,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, field_count[FIELD_INTERVALL], field_count[FIELD_ZERO])); if (verbose) - VOID(printf("\nnormal: %3d empty-space: %3d " + printf("\nnormal: %3d empty-space: %3d " "empty-zero: %3d empty-fill: %3d\n" "pre-space: %3d end-space: %3d " "intervall-fields: %3d zero: %3d\n", @@ -1361,7 +1391,7 @@ static void check_counts(HUFF_COUNTS *huff_counts, uint trees, field_count[FIELD_SKIP_PRESPACE], field_count[FIELD_SKIP_ENDSPACE], field_count[FIELD_INTERVALL], - field_count[FIELD_ZERO])); + field_count[FIELD_ZERO]); DBUG_VOID_RETURN; } @@ -1450,8 +1480,8 @@ static HUFF_TREE* make_huff_trees(HUFF_COUNTS *huff_counts, uint trees) if (make_huff_tree(huff_tree+tree,huff_counts+tree)) { while (tree--) - my_free((uchar*) huff_tree[tree].element_buffer,MYF(0)); - my_free((uchar*) huff_tree,MYF(0)); + my_free(huff_tree[tree].element_buffer); + my_free(huff_tree); DBUG_RETURN(0); } } @@ -1859,9 +1889,9 @@ static uint join_same_trees(HUFF_COUNTS *huff_counts, uint trees) i->tree->tree_pack_length+j->tree->tree_pack_length+ ALLOWED_JOIN_DIFF) { - memcpy_fixed((uchar*) i->counts,(uchar*) count.counts, + memcpy(i->counts, count.counts, sizeof(count.counts[0])*256); - my_free((uchar*) j->tree->element_buffer,MYF(0)); + my_free(j->tree->element_buffer); j->tree->element_buffer=0; j->tree=i->tree; bmove((uchar*) i->counts,(uchar*) count.counts, @@ -1876,7 +1906,7 @@ static uint join_same_trees(HUFF_COUNTS *huff_counts, uint trees) DBUG_PRINT("info", ("Original trees: %d After join: %d", trees, tree_number)); if (verbose) - VOID(printf("Original trees: %d After join: %d\n", trees, tree_number)); + printf("Original trees: %d After join: %d\n", trees, tree_number); return tree_number; /* Return trees left */ } @@ -2010,7 +2040,7 @@ static int write_header(PACK_MRG_INFO *mrg,uint head_length,uint trees, uchar *buff= (uchar*) file_buffer.pos; bzero(buff,HEAD_LENGTH); - memcpy_fixed(buff,myisam_pack_file_magic,4); + memcpy(buff,myisam_pack_file_magic,4); int4store(buff+4,head_length); int4store(buff+8, mrg->min_pack_length); int4store(buff+12,mrg->max_pack_length); @@ -2022,7 +2052,7 @@ static int write_header(PACK_MRG_INFO *mrg,uint head_length,uint trees, buff[27]= (uchar) mi_get_pointer_length((ulonglong) filelength,2); if (test_only) return 0; - VOID(my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0))); + my_seek(file_buffer.file,0L,MY_SEEK_SET,MYF(0)); return my_write(file_buffer.file,(const uchar *) file_buffer.pos,HEAD_LENGTH, MYF(MY_WME | MY_NABP | MY_WAIT_IF_FULL)) != 0; } @@ -2055,24 +2085,24 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees) DBUG_PRINT("info", (" ")); if (verbose >= 2) { - VOID(printf("\n")); - VOID(printf("column types:\n")); - VOID(printf("FIELD_NORMAL 0\n")); - VOID(printf("FIELD_SKIP_ENDSPACE 1\n")); - VOID(printf("FIELD_SKIP_PRESPACE 2\n")); - VOID(printf("FIELD_SKIP_ZERO 3\n")); - VOID(printf("FIELD_BLOB 4\n")); - VOID(printf("FIELD_CONSTANT 5\n")); - VOID(printf("FIELD_INTERVALL 6\n")); - VOID(printf("FIELD_ZERO 7\n")); - VOID(printf("FIELD_VARCHAR 8\n")); - VOID(printf("FIELD_CHECK 9\n")); - VOID(printf("\n")); - VOID(printf("pack type as a set of flags:\n")); - VOID(printf("PACK_TYPE_SELECTED 1\n")); - VOID(printf("PACK_TYPE_SPACE_FIELDS 2\n")); - VOID(printf("PACK_TYPE_ZERO_FILL 4\n")); - VOID(printf("\n")); + printf("\n"); + printf("column types:\n"); + printf("FIELD_NORMAL 0\n"); + printf("FIELD_SKIP_ENDSPACE 1\n"); + printf("FIELD_SKIP_PRESPACE 2\n"); + printf("FIELD_SKIP_ZERO 3\n"); + printf("FIELD_BLOB 4\n"); + printf("FIELD_CONSTANT 5\n"); + printf("FIELD_INTERVALL 6\n"); + printf("FIELD_ZERO 7\n"); + printf("FIELD_VARCHAR 8\n"); + printf("FIELD_CHECK 9\n"); + printf("\n"); + printf("pack type as a set of flags:\n"); + printf("PACK_TYPE_SELECTED 1\n"); + printf("PACK_TYPE_SPACE_FIELDS 2\n"); + printf("PACK_TYPE_ZERO_FILL 4\n"); + printf("\n"); } for (i=0 ; i++ < fields ; counts++) { @@ -2089,10 +2119,10 @@ static void write_field_info(HUFF_COUNTS *counts, uint fields, uint trees) counts->max_zero_fill, counts->length_bits, counts->tree->tree_number, counts->field_length)); if (verbose >= 2) - VOID(printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u " + printf("column: %3u type: %2u pack: %2u zero: %4u lbits: %2u " "tree: %2u length: %4u\n", i , counts->field_type, counts->pack_type, counts->max_zero_fill, counts->length_bits, - counts->tree->tree_number, counts->field_length)); + counts->tree->tree_number, counts->field_length); } flush_bits(); return; @@ -2127,7 +2157,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_PRINT("info", (" ")); if (verbose >= 2) - VOID(printf("\n")); + printf("\n"); tree_no= 0; intervall_length=0; for (elements=0; trees-- ; huff_tree++) @@ -2138,7 +2168,7 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) tree_no++; DBUG_PRINT("info", (" ")); if (verbose >= 3) - VOID(printf("\n")); + printf("\n"); /* Count the total number of elements (byte codes or column values). */ elements+=huff_tree->elements; huff_tree->max_offset=2; @@ -2157,8 +2187,8 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) */ if (huff_tree->max_offset >= IS_OFFSET) { /* This should be impossible */ - VOID(fprintf(stderr, "Tree offset got too big: %d, aborted\n", - huff_tree->max_offset)); + (void) fprintf(stderr, "Tree offset got too big: %d, aborted\n", + huff_tree->max_offset); my_afree((uchar*) packed_tree); return 0; } @@ -2197,19 +2227,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) "bufflen" : "min_chr", huff_tree->counts->tree_buff ? int_length : huff_tree->min_chr, huff_tree->height)); if (verbose >= 2) - VOID(printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u " + printf("tree: %2u elements: %4u char_bits: %2u offset_bits: %2u " "%s: %5u codelen: %2u\n", tree_no, huff_tree->elements, huff_tree->char_bits, huff_tree->offset_bits, huff_tree->counts->tree_buff ? "bufflen" : "min_chr", huff_tree->counts->tree_buff ? int_length : - huff_tree->min_chr, huff_tree->height)); + huff_tree->min_chr, huff_tree->height); /* Check that the code tree length matches the element count. */ length=(uint) (offset-packed_tree); if (length != huff_tree->elements*2-2) { - VOID(fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n", - length, huff_tree->elements * 2 - 2)); + (void) fprintf(stderr, "error: Huff-tree-length: %d != calc_length: %d\n", + length, huff_tree->elements * 2 - 2); errors++; break; } @@ -2226,10 +2256,10 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) " -> " : "", (packed_tree[i] & IS_OFFSET) ? packed_tree[i] - IS_OFFSET + i : packed_tree[i])); if (verbose >= 3) - VOID(printf("tree[0x%04x]: %s0x%04x\n", + printf("tree[0x%04x]: %s0x%04x\n", i, (packed_tree[i] & IS_OFFSET) ? " -> " : "", (packed_tree[i] & IS_OFFSET) ? - packed_tree[i] - IS_OFFSET + i : packed_tree[i])); + packed_tree[i] - IS_OFFSET + i : packed_tree[i]); } flush_bits(); @@ -2251,9 +2281,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) bindigits(huff_tree->code[i], huff_tree->code_len[i]))); if (verbose >= 3) - VOID(printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i, + printf("code[0x%04x]: 0x%s bits: %2u bin: %s\n", i, hexdigits(huff_tree->code[i]), huff_tree->code_len[i], - bindigits(huff_tree->code[i], huff_tree->code_len[i]))); + bindigits(huff_tree->code[i], huff_tree->code_len[i])); /* Check that the encode table decodes correctly. */ code= 0; @@ -2266,9 +2296,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) { if (! len) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: code 0x%s with %u bits not found\n", - hexdigits(huff_tree->code[i]), huff_tree->code_len[i])); + (void) fflush(stdout); + (void) fprintf(stderr, "error: code 0x%s with %u bits not found\n", + hexdigits(huff_tree->code[i]), huff_tree->code_len[i]); errors++; break; } @@ -2277,18 +2307,18 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) bits++; if (bits > 8 * sizeof(code)) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: Huffman code too long: %u/%u\n", - bits, (uint) (8 * sizeof(code)))); + (void) fflush(stdout); + (void) fprintf(stderr, "error: Huffman code too long: %u/%u\n", + bits, (uint) (8 * sizeof(code))); errors++; break; } idx+= (uint) code & 1; if (idx >= length) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: illegal tree offset: %u/%u\n", - idx, length)); + (void) fflush(stdout); + (void) fprintf(stderr, "error: illegal tree offset: %u/%u\n", + idx, length); errors++; break; } @@ -2303,9 +2333,9 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_EXECUTE_IF("forcechkerr4", packed_tree[idx]++;); if (packed_tree[idx] != i) { - VOID(fflush(stdout)); - VOID(fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n", - packed_tree[idx], i)); + (void) fflush(stdout); + (void) fprintf(stderr, "error: decoded value 0x%04x should be: 0x%04x\n", + packed_tree[idx], i); errors++; break; } @@ -2322,19 +2352,19 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) DBUG_PRINT("info", ("column_values[0x%04x]: 0x%02x", i, (uchar) huff_tree->counts->tree_buff[i])); if (verbose >= 3) - VOID(printf("column_values[0x%04x]: 0x%02x\n", - i, (uchar) huff_tree->counts->tree_buff[i])); + printf("column_values[0x%04x]: 0x%02x\n", + i, (uchar) huff_tree->counts->tree_buff[i]); } } flush_bits(); } DBUG_PRINT("info", (" ")); if (verbose >= 2) - VOID(printf("\n")); + printf("\n"); my_afree((uchar*) packed_tree); if (errors) { - VOID(fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n")); + (void) fprintf(stderr, "Error: Generated decode trees are corrupt. Stop.\n"); return 0; } return elements; @@ -2667,8 +2697,7 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts) DBUG_PRINT("fields", ("FIELD_BLOB %lu bytes, bits: %2u", blob_length, count->length_bits)); write_bits(blob_length,count->length_bits); - memcpy_fixed(&blob,end_pos-portable_sizeof_char_ptr, - sizeof(char*)); + memcpy(&blob, end_pos-portable_sizeof_char_ptr, sizeof(char*)); blob_end=blob+blob_length; /* Encode the blob bytes. */ for ( ; blob < blob_end ; blob++) @@ -2756,8 +2785,8 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts) record_count++; if (write_loop && record_count % WRITE_COUNT == 0) { - VOID(printf("%lu\r", (ulong) record_count)); - VOID(fflush(stdout)); + printf("%lu\r", (ulong) record_count); + (void) fflush(stdout); } } else if (error != HA_ERR_RECORD_DELETED) @@ -2767,11 +2796,11 @@ static int compress_isam_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts) error=0; else { - VOID(fprintf(stderr, "%s: Got error %d reading records\n", - my_progname, error)); + (void) fprintf(stderr, "%s: Got error %d reading records\n", + my_progname, error); } if (verbose >= 2) - VOID(printf("wrote %s records.\n", llstr((longlong) record_count, llbuf))); + printf("wrote %s records.\n", llstr((longlong) record_count, llbuf)); my_afree((uchar*) record); mrg->ref_length=max_pack_length; @@ -2867,7 +2896,7 @@ static int flush_buffer(ulong neaded_length) static void end_file_buffer(void) { - my_free((uchar*) file_buffer.buffer,MYF(0)); + my_free(file_buffer.buffer); } /* output `bits` low bits of `value' */ @@ -2901,7 +2930,7 @@ static void write_bits(register ulonglong value, register uint bits) if (bits != 8 * sizeof(value)) value&= (((ulonglong) 1) << bits) - 1; if (file_buffer.pos >= file_buffer.end) - VOID(flush_buffer(~ (ulong) 0)); + (void) flush_buffer(~ (ulong) 0); file_buffer.bits=(int) (BITS_SAVED - bits); file_buffer.bitbucket= value << (BITS_SAVED - bits); } @@ -2924,7 +2953,7 @@ static void flush_bits(void) *file_buffer.pos++= (uchar) (bit_buffer >> bits); } if (file_buffer.pos >= file_buffer.end) - VOID(flush_buffer(~ (ulong) 0)); + (void) flush_buffer(~ (ulong) 0); file_buffer.bits= BITS_SAVED; file_buffer.bitbucket= 0; } @@ -2974,7 +3003,7 @@ static int save_state(MI_INFO *isam_file,PACK_MRG_INFO *mrg,my_off_t new_length, share->changed=1; /* Force write of header */ share->state.open_count=0; share->global_changed=0; - VOID(my_chsize(share->kfile, share->base.keystart, 0, MYF(0))); + (void) my_chsize(share->kfile, share->base.keystart, 0, MYF(0)); if (share->base.keys) isamchk_neaded=1; DBUG_RETURN(mi_state_info_write(share->kfile,&share->state,1+2)); @@ -3071,7 +3100,7 @@ static int mrg_close(PACK_MRG_INFO *mrg) for (i=0 ; i < mrg->count ; i++) error|=mi_close(mrg->file[i]); if (mrg->free_file) - my_free((uchar*) mrg->file,MYF(0)); + my_free(mrg->file); return error; } @@ -3134,7 +3163,7 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count) */ if (huff_counts->tree_buff) { - my_free((uchar*) huff_counts->tree_buff, MYF(0)); + my_free(huff_counts->tree_buff); delete_tree(&huff_counts->int_tree); huff_counts->tree_buff= NULL; DBUG_PRINT("fakebigcodes", ("freed distinct column values")); @@ -3201,4 +3230,4 @@ static int fakecmp(my_off_t **count1, my_off_t **count2) } #endif - +#include "mi_extrafunc.h" diff --git a/storage/myisam/rt_index.c b/storage/myisam/rt_index.c index 3f712c2dd06..37a06606b3c 100644 --- a/storage/myisam/rt_index.c +++ b/storage/myisam/rt_index.c @@ -968,7 +968,7 @@ int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) goto err1; } if (ReinsertList.pages) - my_free((uchar*) ReinsertList.pages, MYF(0)); + my_free(ReinsertList.pages); /* check for redundant root (not leaf, 1 child) and eliminate */ if ((old_root = info->s->state.key_root[keynr]) == HA_OFFSET_ERROR) diff --git a/storage/myisam/rt_test.c b/storage/myisam/rt_test.c index 7d15afd12ef..7233300c539 100644 --- a/storage/myisam/rt_test.c +++ b/storage/myisam/rt_test.c @@ -366,25 +366,6 @@ static int read_with_pos (MI_INFO * file,int silent) } -#ifdef NOT_USED -static void bprint_record(char * record, - my_off_t offs __attribute__((unused)), - const char * tail) -{ - int i; - char * pos; - i=(unsigned char)record[0]; - printf("%02X ",i); - - for( pos=record+1, i=0; i<32; i++,pos++){ - int b=(unsigned char)*pos; - printf("%02X",b); - } - printf("%s",tail); -} -#endif - - static void print_record(uchar * record, my_off_t offs __attribute__((unused)), const char * tail) @@ -424,30 +405,6 @@ static void create_record1(uchar *record,uint rownr) } } -#ifdef NOT_USED - -static void create_record0(uchar *record,uint rownr) -{ - int i; - char * pos; - double c=rownr+10; - double c0=0; - - bzero((char*) record,MAX_REC_LENGTH); - record[0]=0x01; /* DEL marker */ - - for ( pos=record+1, i=0; i<ndims; i++) - { - memcpy(pos,&c0,sizeof(c0)); - float8store(pos,c0); - pos+=sizeof(c0); - memcpy(pos,&c,sizeof(c)); - float8store(pos,c); - pos+=sizeof(c); - } -} - -#endif static void create_record(uchar *record,uint rownr) { @@ -468,3 +425,5 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused))) exit(0); } #endif /*HAVE_RTREE_KEYS*/ + +#include "mi_extrafunc.h" diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index 5dff1ea3558..9532b9f0474 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 @@ -19,7 +19,7 @@ */ #include "fulltext.h" -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <fcntl.h> #else #include <stddef.h> @@ -41,46 +41,46 @@ Pointers of functions for store and read keys from temp file */ -extern void print_error _VARARGS((const char *fmt,...)); +extern void print_error(const char *fmt,...); /* Functions defined in this file */ -static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info,uint keys, - uchar **sort_keys, - DYNAMIC_ARRAY *buffpek,int *maxbuffer, - IO_CACHE *tempfile, - IO_CACHE *tempfile_for_exceptions); -static int NEAR_F write_keys(MI_SORT_PARAM *info,uchar **sort_keys, - uint count, BUFFPEK *buffpek,IO_CACHE *tempfile); -static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, - IO_CACHE *tempfile); -static int NEAR_F write_index(MI_SORT_PARAM *info,uchar * *sort_keys, - uint count); -static int NEAR_F merge_many_buff(MI_SORT_PARAM *info,uint keys, - uchar * *sort_keys, - BUFFPEK *buffpek,int *maxbuffer, - IO_CACHE *t_file); -static uint NEAR_F read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek, - uint sort_length); -static int NEAR_F merge_buffers(MI_SORT_PARAM *info,uint keys, - IO_CACHE *from_file, IO_CACHE *to_file, - uchar * *sort_keys, BUFFPEK *lastbuff, - BUFFPEK *Fb, BUFFPEK *Tb); -static int NEAR_F merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int, - IO_CACHE *); +static ha_rows find_all_keys(MI_SORT_PARAM *info,uint keys, + uchar **sort_keys, + DYNAMIC_ARRAY *buffpek,int *maxbuffer, + IO_CACHE *tempfile, + IO_CACHE *tempfile_for_exceptions); +static int write_keys(MI_SORT_PARAM *info,uchar **sort_keys, + uint count, BUFFPEK *buffpek,IO_CACHE *tempfile); +static int write_key(MI_SORT_PARAM *info, uchar *key, + IO_CACHE *tempfile); +static int write_index(MI_SORT_PARAM *info,uchar * *sort_keys, + uint count); +static int merge_many_buff(MI_SORT_PARAM *info,uint keys, + uchar * *sort_keys, + BUFFPEK *buffpek,int *maxbuffer, + IO_CACHE *t_file); +static uint read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek, + uint sort_length); +static int merge_buffers(MI_SORT_PARAM *info,uint keys, + IO_CACHE *from_file, IO_CACHE *to_file, + uchar * *sort_keys, BUFFPEK *lastbuff, + BUFFPEK *Fb, BUFFPEK *Tb); +static int merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int, + IO_CACHE *); static int flush_ft_buf(MI_SORT_PARAM *info); -static int NEAR_F write_keys_varlen(MI_SORT_PARAM *info,uchar **sort_keys, - uint count, BUFFPEK *buffpek, - IO_CACHE *tempfile); -static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek, - uint sort_length); -static int NEAR_F write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file, - uchar *key, uint sort_length, uint count); -static int NEAR_F write_merge_key_varlen(MI_SORT_PARAM *info, - IO_CACHE *to_file, - uchar* key, uint sort_length, - uint count); +static int write_keys_varlen(MI_SORT_PARAM *info,uchar **sort_keys, + uint count, BUFFPEK *buffpek, + IO_CACHE *tempfile); +static uint read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek, + uint sort_length); +static int write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file, + uchar *key, uint sort_length, uint count); +static int write_merge_key_varlen(MI_SORT_PARAM *info, + IO_CACHE *to_file, + uchar* key, uint sort_length, + uint count); static inline int my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs); @@ -162,7 +162,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, if (my_init_dynamic_array(&buffpek, sizeof(BUFFPEK), maxbuffer, maxbuffer/2)) { - my_free((uchar*) sort_keys,MYF(0)); + my_free(sort_keys); sort_keys= 0; } else @@ -242,8 +242,7 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, error =0; err: - if (sort_keys) - my_free((uchar*) sort_keys,MYF(0)); + my_free(sort_keys); delete_dynamic(&buffpek); close_cached_file(&tempfile); close_cached_file(&tempfile_for_exceptions); @@ -254,10 +253,10 @@ err: /* Search after all keys and place them in a temp. file */ -static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys, - uchar **sort_keys, DYNAMIC_ARRAY *buffpek, - int *maxbuffer, IO_CACHE *tempfile, - IO_CACHE *tempfile_for_exceptions) +static ha_rows find_all_keys(MI_SORT_PARAM *info, uint keys, + uchar **sort_keys, DYNAMIC_ARRAY *buffpek, + int *maxbuffer, IO_CACHE *tempfile, + IO_CACHE *tempfile_for_exceptions) { int error; uint idx; @@ -382,7 +381,7 @@ pthread_handler_t thr_find_all_keys(void *arg) if (my_init_dynamic_array(&sort_param->buffpek, sizeof(BUFFPEK), maxbuffer, maxbuffer/2)) { - my_free((uchar*) sort_keys,MYF(0)); + my_free(sort_keys); sort_keys= (uchar **) NULL; /* for err: label */ } else @@ -451,8 +450,7 @@ pthread_handler_t thr_find_all_keys(void *arg) err: DBUG_PRINT("error", ("got some error")); sort_param->sort_info->got_error= 1; /* no need to protect with a mutex */ - if (sort_keys) - my_free((uchar*) sort_keys,MYF(0)); + my_free(sort_keys); sort_param->sort_keys= 0; delete_dynamic(& sort_param->buffpek); close_cached_file(&sort_param->tempfile); @@ -476,10 +474,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(); @@ -509,8 +507,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) if (!sinfo->sort_keys) { got_error=1; - my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff), - MYF(MY_ALLOW_ZERO_PTR)); + my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff)); continue; } if (!got_error) @@ -528,9 +525,8 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) got_error=1; } } - my_free((uchar*) sinfo->sort_keys,MYF(0)); - my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff), - MYF(MY_ALLOW_ZERO_PTR)); + my_free(sinfo->sort_keys); + my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff)); sinfo->sort_keys=0; } @@ -638,15 +634,15 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) sinfo->notnull : NULL, (ulonglong) info->state->records); } - my_free((uchar*) mergebuf,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mergebuf); DBUG_RETURN(got_error); } #endif /* THREAD */ /* Write all keys in memory to file for later merge */ -static int NEAR_F write_keys(MI_SORT_PARAM *info, register uchar **sort_keys, - uint count, BUFFPEK *buffpek, IO_CACHE *tempfile) +static int write_keys(MI_SORT_PARAM *info, register uchar **sort_keys, + uint count, BUFFPEK *buffpek, IO_CACHE *tempfile) { uchar **end; uint sort_length=info->key_length; @@ -686,10 +682,10 @@ my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs) } -static int NEAR_F write_keys_varlen(MI_SORT_PARAM *info, - register uchar **sort_keys, - uint count, BUFFPEK *buffpek, - IO_CACHE *tempfile) +static int write_keys_varlen(MI_SORT_PARAM *info, + register uchar **sort_keys, + uint count, BUFFPEK *buffpek, + IO_CACHE *tempfile) { uchar **end; int err; @@ -713,8 +709,7 @@ static int NEAR_F write_keys_varlen(MI_SORT_PARAM *info, } /* write_keys_varlen */ -static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, - IO_CACHE *tempfile) +static int write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) { uint key_length=info->real_key_length; DBUG_ENTER("write_key"); @@ -733,8 +728,8 @@ static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, /* Write index */ -static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, - register uint count) +static int write_index(MI_SORT_PARAM *info, register uchar **sort_keys, + register uint count) { DBUG_ENTER("write_index"); @@ -751,9 +746,9 @@ static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, /* Merge buffers to make < MERGEBUFF2 buffers */ -static int NEAR_F merge_many_buff(MI_SORT_PARAM *info, uint keys, - uchar **sort_keys, BUFFPEK *buffpek, - int *maxbuffer, IO_CACHE *t_file) +static int merge_many_buff(MI_SORT_PARAM *info, uint keys, + uchar **sort_keys, BUFFPEK *buffpek, + int *maxbuffer, IO_CACHE *t_file) { register int i; IO_CACHE t_file2, *from_file, *to_file, *temp; @@ -814,16 +809,17 @@ cleanup: -1 Error */ -static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, - uint sort_length) +static uint read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, + uint sort_length) { register uint count; uint length; 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 */ @@ -833,8 +829,8 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, return (count*sort_length); } /* read_to_buffer */ -static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek, - uint sort_length) +static uint read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek, + uint sort_length) { register uint count; uint16 length_of_key = 0; @@ -847,12 +843,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; @@ -865,9 +861,9 @@ static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek, } /* read_to_buffer_varlen */ -static int NEAR_F write_merge_key_varlen(MI_SORT_PARAM *info, - IO_CACHE *to_file, uchar* key, - uint sort_length, uint count) +static int write_merge_key_varlen(MI_SORT_PARAM *info, + IO_CACHE *to_file, uchar* key, + uint sort_length, uint count) { uint idx; uchar *bufs = key; @@ -883,9 +879,9 @@ static int NEAR_F write_merge_key_varlen(MI_SORT_PARAM *info, } -static int NEAR_F write_merge_key(MI_SORT_PARAM *info __attribute__((unused)), - IO_CACHE *to_file, uchar *key, - uint sort_length, uint count) +static int write_merge_key(MI_SORT_PARAM *info __attribute__((unused)), + IO_CACHE *to_file, uchar *key, + uint sort_length, uint count) { return my_b_write(to_file, key, (size_t) sort_length*count); } @@ -895,7 +891,7 @@ static int NEAR_F write_merge_key(MI_SORT_PARAM *info __attribute__((unused)), If to_file == 0 then use info->key_write */ -static int NEAR_F +static int merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file, IO_CACHE *to_file, uchar **sort_keys, BUFFPEK *lastbuff, BUFFPEK *Fb, BUFFPEK *Tb) @@ -968,7 +964,7 @@ merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file, uchar *base=buffpek->base; uint max_keys=buffpek->max_keys; - VOID(queue_remove(&queue,0)); + (void) queue_remove(&queue,0); /* Put room used by buffer to use in other buffer */ for (refpek= (BUFFPEK**) &queue_top(&queue); @@ -1038,7 +1034,7 @@ err: /* Do a merge to output-file (save only positions) */ -static int NEAR_F +static int merge_index(MI_SORT_PARAM *info, uint keys, uchar **sort_keys, BUFFPEK *buffpek, int maxbuffer, IO_CACHE *tempfile) { @@ -1056,7 +1052,7 @@ flush_ft_buf(MI_SORT_PARAM *info) if (info->sort_info->ft_buf) { err=sort_ft_buf_flush(info); - my_free((uchar*)info->sort_info->ft_buf, MYF(0)); + my_free(info->sort_info->ft_buf); info->sort_info->ft_buf=0; } return err; diff --git a/storage/myisam/sp_key.c b/storage/myisam/sp_key.c index 3748a38ff81..bde0e1cb388 100644 --- a/storage/myisam/sp_key.c +++ b/storage/myisam/sp_key.c @@ -47,7 +47,7 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key, pos = (uchar*)record + keyseg->start; dlen = _mi_calc_blob_length(keyseg->bit_start, pos); - memcpy_fixed(&dptr, pos + keyseg->bit_start, sizeof(char*)); + memcpy(&dptr, pos + keyseg->bit_start, sizeof(char*)); if (!dptr) { my_errno= HA_ERR_NULL_IN_SPATIAL; diff --git a/storage/myisam/sp_test.c b/storage/myisam/sp_test.c index f572c7ab19b..d86fdc03908 100644 --- a/storage/myisam/sp_test.c +++ b/storage/myisam/sp_test.c @@ -299,26 +299,6 @@ static int read_with_pos (MI_INFO * file,int silent) } -#ifdef NOT_USED -static void bprint_record(uchar * record, - my_off_t offs __attribute__((unused)), - const char * tail) -{ - int i; - char * pos; - i=(unsigned char)record[0]; - printf("%02X ",i); - - for( pos=record+1, i=0; i<32; i++,pos++) - { - int b=(unsigned char)*pos; - printf("%02X",b); - } - printf("%s",tail); -} -#endif - - static void print_record(uchar * record, my_off_t offs,const char * tail) { uchar *pos; @@ -330,7 +310,7 @@ static void print_record(uchar * record, my_off_t offs,const char * tail) len=sint4korr(pos); pos+=4; printf(" len=%d ",len); - memcpy_fixed(&ptr,pos,sizeof(char*)); + memcpy(&ptr, pos, sizeof(char*)); if (ptr) rtree_PrintWKB((uchar*) ptr,SPDIMS); else @@ -340,34 +320,6 @@ static void print_record(uchar * record, my_off_t offs,const char * tail) } -#ifdef NOT_USED -static void create_point(uchar *record,uint rownr) -{ - uint tmp; - char *ptr; - char *pos=record; - double x[200]; - int i; - - for(i=0;i<SPDIMS;i++) - x[i]=rownr; - - bzero((char*) record,MAX_REC_LENGTH); - *pos=0x01; /* DEL marker */ - pos++; - - memset(blob_key,0,sizeof(blob_key)); - tmp=rtree_CreatePointWKB(x,SPDIMS,blob_key); - - int4store(pos,tmp); - pos+=4; - - ptr=blob_key; - memcpy_fixed(pos,&ptr,sizeof(char*)); -} -#endif - - static void create_linestring(uchar *record,uint rownr) { uint tmp; @@ -376,23 +328,23 @@ static void create_linestring(uchar *record,uint rownr) double x[200]; int i,j; int npoints=2; - + for(j=0;j<npoints;j++) for(i=0;i<SPDIMS;i++) x[i+j*SPDIMS]=rownr*j; - + bzero((char*) record,MAX_REC_LENGTH); *pos=0x01; /* DEL marker */ pos++; - + memset(blob_key,0,sizeof(blob_key)); tmp=rtree_CreateLineStringWKB(x,SPDIMS,npoints, (uchar*) blob_key); - + int4store(pos,tmp); pos+=4; - + ptr=blob_key; - memcpy_fixed(pos,&ptr,sizeof(char*)); + memcpy(pos, &ptr, sizeof(char*)); } @@ -401,7 +353,7 @@ static void create_key(uchar *key,uint rownr) double c=rownr; uchar *pos; uint i; - + bzero(key,MAX_REC_LENGTH); for (pos=key, i=0; i<2*SPDIMS; i++) { @@ -426,27 +378,6 @@ static void print_key(const uchar *key,const char * tail) } -#ifdef NOT_USED - -static int rtree_CreatePointWKB(double *ords, uint n_dims, uchar *wkb) -{ - uint i; - - *wkb = wkbXDR; - ++wkb; - int4store(wkb, wkbPoint); - wkb += 4; - - for (i=0; i < n_dims; ++i) - { - float8store(wkb, ords[i]); - wkb += 8; - } - return 5 + n_dims * 8; -} -#endif - - static int rtree_CreateLineStringWKB(double *ords, uint n_dims, uint n_points, uchar *wkb) { @@ -562,3 +493,4 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused))) } #endif /*HAVE_SPATIAL*/ +#include "mi_extrafunc.h" |