diff options
Diffstat (limited to 'myisam')
-rw-r--r-- | myisam/mi_check.c | 22 | ||||
-rw-r--r-- | myisam/mi_close.c | 2 | ||||
-rw-r--r-- | myisam/mi_delete_all.c | 2 | ||||
-rw-r--r-- | myisam/mi_extra.c | 7 | ||||
-rw-r--r-- | myisam/mi_keycache.c | 24 | ||||
-rw-r--r-- | myisam/mi_locking.c | 20 | ||||
-rw-r--r-- | myisam/mi_page.c | 8 | ||||
-rw-r--r-- | myisam/mi_panic.c | 2 | ||||
-rw-r--r-- | myisam/mi_preload.c | 6 | ||||
-rw-r--r-- | myisam/mi_test1.c | 2 | ||||
-rw-r--r-- | myisam/mi_test2.c | 7 | ||||
-rw-r--r-- | myisam/mi_test3.c | 2 | ||||
-rw-r--r-- | myisam/myisamchk.c | 16 | ||||
-rw-r--r-- | myisam/myisamdef.h | 2 | ||||
-rw-r--r-- | myisam/myisamlog.c | 7 |
15 files changed, 87 insertions, 42 deletions
diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 61eba7d44bf..1b29fd01272 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -230,7 +230,7 @@ static int check_k_link(MI_CHECK *param, register MI_INFO *info, uint nr) if (next_link > info->state->key_file_length || next_link & (info->s->blocksize-1)) DBUG_RETURN(1); - if (!(buff=key_cache_read(dflt_keycache, + if (!(buff=key_cache_read(*info->s->keycache, info->s->kfile, next_link, (byte*) info->buff, myisam_block_size, block_size, 1))) DBUG_RETURN(1); @@ -260,7 +260,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) if (!(param->testflag & T_SILENT)) puts("- check file-size"); - flush_key_blocks(dflt_keycache, + flush_key_blocks(*info->s->keycache, info->s->kfile, FLUSH_FORCE_WRITE); /* If called externally */ size=my_seek(info->s->kfile,0L,MY_SEEK_END,MYF(0)); @@ -1121,8 +1121,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, param->testflag|=T_REP; /* for easy checking */ if (!param->using_global_keycache) - VOID(init_key_cache(&dflt_keycache,dflt_key_block_size, - param->use_buffers)); + VOID(init_key_cache(dflt_keycache,dflt_key_cache_var.block_size, + param->use_buffers,&dflt_key_cache_var)); if (init_io_cache(¶m->read_cache,info->dfile, (uint) param->read_buffer_length, @@ -1480,13 +1480,13 @@ void lock_memory(MI_CHECK *param __attribute__((unused))) int flush_blocks(MI_CHECK *param, File file) { - if (flush_key_blocks(dflt_keycache,file,FLUSH_RELEASE)) + if (flush_key_blocks(*dflt_keycache,file,FLUSH_RELEASE)) { mi_check_print_error(param,"%d when trying to write bufferts",my_errno); return(1); } if (!param->using_global_keycache) - end_key_cache(&dflt_keycache,1); + end_key_cache(dflt_keycache,1); return 0; } /* flush_blocks */ @@ -1540,7 +1540,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name) } /* Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(dflt_keycache,share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); share->state.version=(ulong) time((time_t*) 0); old_state=share->state; /* save state if not stored */ @@ -1846,7 +1846,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(dflt_keycache,share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); /* Clear the pointers to the given rows */ for (i=0 ; i < share->base.keys ; i++) share->state.key_root[i]= HA_OFFSET_ERROR; @@ -1856,7 +1856,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, } else { - if (flush_key_blocks(dflt_keycache,share->kfile, FLUSH_FORCE_WRITE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE)) goto err; key_map= ~key_map; /* Create the missing keys */ } @@ -2209,7 +2209,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(dflt_keycache,share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); /* Clear the pointers to the given rows */ for (i=0 ; i < share->base.keys ; i++) share->state.key_root[i]= HA_OFFSET_ERROR; @@ -2219,7 +2219,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, } else { - if (flush_key_blocks(dflt_keycache,share->kfile, FLUSH_FORCE_WRITE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE)) goto err; key_map= ~key_map; /* Create the missing keys */ } diff --git a/myisam/mi_close.c b/myisam/mi_close.c index 6f13af41fbd..8e7fb497dfc 100644 --- a/myisam/mi_close.c +++ b/myisam/mi_close.c @@ -64,7 +64,7 @@ int mi_close(register MI_INFO *info) if (flag) { if (share->kfile >= 0 && - flush_key_blocks(dflt_keycache,share->kfile, + flush_key_blocks(*share->keycache,share->kfile, share->temporary ? FLUSH_IGNORE_CHANGED : FLUSH_RELEASE)) error=my_errno; diff --git a/myisam/mi_delete_all.c b/myisam/mi_delete_all.c index 46d887a90d8..99873661feb 100644 --- a/myisam/mi_delete_all.c +++ b/myisam/mi_delete_all.c @@ -53,7 +53,7 @@ int mi_delete_all_rows(MI_INFO *info) If we are using delayed keys or if the user has done changes to the tables since it was locked then there may be key blocks in the key cache */ - flush_key_blocks(dflt_keycache, share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache, share->kfile, FLUSH_IGNORE_CHANGED); if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) goto err; diff --git a/myisam/mi_extra.c b/myisam/mi_extra.c index f0d8966c9e3..40bfd0edd30 100644 --- a/myisam/mi_extra.c +++ b/myisam/mi_extra.c @@ -279,7 +279,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) #ifdef __WIN__ /* Close the isam and data files as Win32 can't drop an open table */ pthread_mutex_lock(&share->intern_lock); - if (flush_key_blocks(dflt_keycache, share->kfile, + if (flush_key_blocks(*share->keycache, share->kfile, (function == HA_EXTRA_FORCE_REOPEN ? FLUSH_RELEASE : FLUSH_IGNORE_CHANGED))) { @@ -325,7 +325,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) break; case HA_EXTRA_FLUSH: if (!share->temporary) - flush_key_blocks(dflt_keycache,share->kfile,FLUSH_KEEP); + flush_key_blocks(*share->keycache,share->kfile,FLUSH_KEEP); #ifdef HAVE_PWRITE _mi_decrement_open_count(info); #endif @@ -370,6 +370,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) case HA_EXTRA_PRELOAD_BUFFER_SIZE: info->preload_buff_size= *((ulong *) extra_arg); break; + case HA_EXTRA_SET_KEY_CACHE: + share->reg_keycache= share->keycache= (KEY_CACHE_HANDLE *) extra_arg; + break; case HA_EXTRA_KEY_CACHE: case HA_EXTRA_NO_KEY_CACHE: default: diff --git a/myisam/mi_keycache.c b/myisam/mi_keycache.c index 75a6819f598..1010aef9e1d 100644 --- a/myisam/mi_keycache.c +++ b/myisam/mi_keycache.c @@ -28,7 +28,7 @@ mi_assign_to_keycache() info open table map map of indexes to assign to the key cache - keycache_name name of of the key cache to assign index to + key_cache_ptr pointer to the key cache handle RETURN VALUE 0 if a success. error code - otherwise. @@ -39,9 +39,25 @@ of the table will be assigned to the specified key cache. */ -int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map, - char *keycache_name) +int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map, + KEY_CACHE_HANDLE *reg_keycache) { - return 0; + int error= 0; + MYISAM_SHARE* share= info->s; + + DBUG_ENTER("mi_assign_to_keycache"); + + share->reg_keycache= reg_keycache; + if (!(info->lock_type == F_WRLCK && share->w_locks)) + { + if (flush_key_blocks(*share->keycache, share->kfile, FLUSH_RELEASE)) + { + error=my_errno; + mi_mark_crashed(info); /* Mark that table must be checked */ + } + share->keycache= reg_keycache; + } + + DBUG_RETURN(error); } diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c index 7ede4852ccd..fa415269d61 100644 --- a/myisam/mi_locking.c +++ b/myisam/mi_locking.c @@ -34,6 +34,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) uint count; MYISAM_SHARE *share=info->s; uint flag; + uint switch_fl= 0; DBUG_ENTER("mi_lock_database"); if (share->options & HA_OPTION_READ_ONLY_DATA || @@ -50,13 +51,26 @@ int mi_lock_database(MI_INFO *info, int lock_type) else count= --share->w_locks; --share->tot_locks; + /* + During a key cache reassignment the current and registered + key caches for the table are different. + Although at present key cache ressignment is always + performed with a shared cache for the table acquired, + for future possible optimizations we still + handle this situation as if we could come to this point + during the ressignment (in non-reassignment thread). + */ if (info->lock_type == F_WRLCK && !share->w_locks && - !share->delay_key_write && - flush_key_blocks(dflt_keycache,share->kfile,FLUSH_KEEP)) + ((switch_fl= share->keycache != share->reg_keycache) || + !share->delay_key_write) && + flush_key_blocks(*share->keycache, share->kfile, + switch_fl ? FLUSH_RELEASE : FLUSH_KEEP)) { error=my_errno; mi_mark_crashed(info); /* Mark that table must be checked */ } + if (switch_fl) + share->keycache= share->reg_keycache; if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) { if (end_io_cache(&info->rec_cache)) @@ -386,7 +400,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(dflt_keycache,share->kfile,FLUSH_RELEASE)); + VOID(flush_key_blocks(*share->keycache,share->kfile,FLUSH_RELEASE)); share->last_process=share->state.process; info->last_unique= share->state.unique; info->last_loop= share->state.update_count; diff --git a/myisam/mi_page.c b/myisam/mi_page.c index eef65f03493..61a0c98233c 100644 --- a/myisam/mi_page.c +++ b/myisam/mi_page.c @@ -31,7 +31,7 @@ uchar *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo, DBUG_ENTER("_mi_fetch_keypage"); DBUG_PRINT("enter",("page: %ld",page)); - tmp=(uchar*) key_cache_read(dflt_keycache, + tmp=(uchar*) key_cache_read(*info->s->keycache, info->s->kfile,page,(byte*) buff, (uint) keyinfo->block_length, (uint) keyinfo->block_length, @@ -93,7 +93,7 @@ int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, length=keyinfo->block_length; } #endif - DBUG_RETURN((key_cache_write(dflt_keycache, + DBUG_RETURN((key_cache_write(*info->s->keycache, info->s->kfile,page,(byte*) buff,length, (uint) keyinfo->block_length, (int) ((info->lock_type != F_UNLCK) || @@ -114,7 +114,7 @@ int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos) info->s->state.key_del[keyinfo->block_size]=pos; mi_sizestore(buff,old_link); info->s->state.changed|= STATE_NOT_SORTED_PAGES; - DBUG_RETURN(key_cache_write(dflt_keycache, + DBUG_RETURN(key_cache_write(*info->s->keycache, info->s->kfile,pos,buff, sizeof(buff), (uint) keyinfo->block_length, @@ -143,7 +143,7 @@ my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo) } else { - if (!key_cache_read(dflt_keycache, + if (!key_cache_read(*info->s->keycache, info->s->kfile,pos, buff, (uint) sizeof(buff), diff --git a/myisam/mi_panic.c b/myisam/mi_panic.c index 3a436969b06..f1d1d839fcd 100644 --- a/myisam/mi_panic.c +++ b/myisam/mi_panic.c @@ -48,7 +48,7 @@ int mi_panic(enum ha_panic_function flag) if (info->s->options & HA_OPTION_READ_ONLY_DATA) break; #endif - if (flush_key_blocks(dflt_keycache,info->s->kfile,FLUSH_RELEASE)) + if (flush_key_blocks(*info->s->keycache,info->s->kfile,FLUSH_RELEASE)) error=my_errno; if (info->opt_flag & WRITE_CACHE_USED) if (flush_io_cache(&info->rec_cache)) diff --git a/myisam/mi_preload.c b/myisam/mi_preload.c index 39237886b57..02d5229bd4d 100644 --- a/myisam/mi_preload.c +++ b/myisam/mi_preload.c @@ -69,7 +69,7 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME)))) DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM); - if (flush_key_blocks(dflt_keycache,share->kfile, FLUSH_RELEASE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_RELEASE)) goto err; do @@ -87,7 +87,7 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) { if (mi_test_if_nod(buff)) { - if (key_cache_insert(dflt_keycache, + if (key_cache_insert(*share->keycache, share->kfile, pos, (byte*) buff, block_length)) goto err; } @@ -98,7 +98,7 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) } else { - if (key_cache_insert(dflt_keycache, + if (key_cache_insert(*share->keycache, share->kfile, pos, (byte*) buff, length)) goto err; pos+= length; diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c index d08066f6028..ec68e23c0c2 100644 --- a/myisam/mi_test1.c +++ b/myisam/mi_test1.c @@ -50,7 +50,7 @@ int main(int argc,char *argv[]) MY_INIT(argv[0]); my_init(); if (key_cacheing) - init_key_cache(&dflt_keycache,dflt_key_block_size,IO_SIZE*16); + init_key_cache(dflt_keycache,512,IO_SIZE*16,0); get_options(argc,argv); exit(run_test("test1")); diff --git a/myisam/mi_test2.c b/myisam/mi_test2.c index d69673c319d..11a8e12a7e5 100644 --- a/myisam/mi_test2.c +++ b/myisam/mi_test2.c @@ -49,6 +49,7 @@ static int verbose=0,testflag=0, static int pack_seg=HA_SPACE_PACK,pack_type=HA_PACK_KEY,remove_count=-1, create_flag=0; static ulong key_cache_size=IO_SIZE*16; +static uint key_cache_block_size=IO_SIZE; static uint keys=MYISAM_KEYS,recant=1000; static uint use_blob=0; @@ -214,7 +215,7 @@ int main(int argc, char *argv[]) if (!silent) printf("- Writing key:s\n"); if (key_cacheing) - init_key_cache(&dflt_keycache,dflt_key_block_size,key_cache_size); /* Use a small cache */ + init_key_cache(dflt_keycache,key_cache_block_size,key_cache_size,0); /* Use a small cache */ if (locking) mi_lock_database(file,F_WRLCK); if (write_cacheing) @@ -274,7 +275,7 @@ int main(int argc, char *argv[]) goto end; } if (key_cacheing) - resize_key_cache(&dflt_keycache,key_cache_size*2); + resize_key_cache(dflt_keycache,key_cache_size*2); } if (!silent) @@ -828,7 +829,7 @@ reads: %10lu\n", my_cache_r_requests, my_cache_read); #endif } - end_key_cache(&dflt_keycache,1); + end_key_cache(dflt_keycache,1); if (blob_buffer) my_free(blob_buffer,MYF(0)); my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO); diff --git a/myisam/mi_test3.c b/myisam/mi_test3.c index dde8758f9bf..866c6299fac 100644 --- a/myisam/mi_test3.c +++ b/myisam/mi_test3.c @@ -177,7 +177,7 @@ void start_test(int id) exit(1); } if (key_cacheing && rnd(2) == 0) - init_key_cache(&dflt_keycache,dflt_key_block_size,65536L); + init_key_cache(dflt_keycache,512,65536L,0); printf("Process %d, pid: %d\n",id,getpid()); fflush(stdout); for (error=i=0 ; i < tests && !error; i++) diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 94fbea87de3..9bec92f40a8 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -44,6 +44,7 @@ static const char *load_default_groups[]= { "myisamchk", 0 }; static const char *set_charset_name, *opt_tmpdir; static CHARSET_INFO *set_charset; static long opt_myisam_block_size; +static long opt_key_cache_block_size; static const char *my_progname_short; static int stopwords_inited= 0; static MY_TMPDIR myisamchk_tmpdir; @@ -148,7 +149,8 @@ int main(int argc, char **argv) enum options { OPT_CHARSETS_DIR=256, OPT_SET_CHARSET,OPT_START_CHECK_POS, - OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, OPT_MYISAM_BLOCK_SIZE, + OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, + OPT_KEY_CACHE_BLOCK_SIZE, OPT_MYISAM_BLOCK_SIZE, 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_MAX_WORD_LEN_FOR_SORT @@ -283,6 +285,11 @@ static struct my_option my_long_options[] = (gptr*) &check_param.use_buffers, (gptr*) &check_param.use_buffers, 0, GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0}, + { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE, "", + (gptr*) &opt_key_cache_block_size, + (gptr*) &opt_key_cache_block_size, 0, + GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, + MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0}, { "myisam_block_size", OPT_MYISAM_BLOCK_SIZE, "", (gptr*) &opt_myisam_block_size, (gptr*) &opt_myisam_block_size, 0, GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, @@ -1020,8 +1027,8 @@ static int myisamchk(MI_CHECK *param, my_string filename) !(param->testflag & (T_FAST | T_FORCE_CREATE))) { if (param->testflag & (T_EXTEND | T_MEDIUM)) - VOID(init_key_cache(&dflt_keycache,dflt_key_block_size, - param->use_buffers)); + VOID(init_key_cache(dflt_keycache,opt_key_cache_block_size, + param->use_buffers,&dflt_key_cache_var)); VOID(init_io_cache(¶m->read_cache,datafile, (uint) param->read_buffer_length, READ_CACHE, @@ -1438,7 +1445,8 @@ static int mi_sort_records(MI_CHECK *param, if (share->state.key_root[sort_key] == HA_OFFSET_ERROR) DBUG_RETURN(0); /* Nothing to do */ - init_key_cache(&dflt_keycache,dflt_key_block_size,param->use_buffers); + init_key_cache(dflt_keycache,opt_key_cache_block_size,param->use_buffers, + &dflt_key_cache_var); if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length, WRITE_CACHE,share->pack.header_length,1, MYF(MY_WME | MY_WAIT_IF_FULL))) diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h index 83e28a42797..e02858453d2 100644 --- a/myisam/myisamdef.h +++ b/myisam/myisamdef.h @@ -166,6 +166,8 @@ typedef struct st_mi_isam_share { /* Shared between opens */ char *data_file_name, /* Resolved path names from symlinks */ *index_file_name; byte *file_map; /* mem-map of file if possible */ + KEY_CACHE_HANDLE *keycache; /* ref to the current key cache */ + KEY_CACHE_HANDLE *reg_keycache; /* ref to the registered key cache */ MI_DECODE_TREE *decode_trees; uint16 *decode_tables; int (*read_record)(struct st_myisam_info*, my_off_t, byte*); diff --git a/myisam/myisamlog.c b/myisam/myisamlog.c index ff1a9d30206..5bca25dd439 100644 --- a/myisam/myisamlog.c +++ b/myisam/myisamlog.c @@ -333,7 +333,8 @@ static int examine_log(my_string file_name, char **table_names) bzero((gptr) 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_keycache,dflt_key_block_size,KEY_CACHE_SIZE)); + VOID(init_key_cache(dflt_keycache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, + &dflt_key_cache_var)); files_open=0; access_time=0; while (access_time++ != number_of_commands && @@ -639,7 +640,7 @@ static int examine_log(my_string file_name, char **table_names) goto end; } } - end_key_cache(&dflt_keycache,1); + end_key_cache(dflt_keycache,1); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); @@ -659,7 +660,7 @@ static int examine_log(my_string file_name, char **table_names) llstr(isamlog_filepos,llbuff))); fflush(stderr); end: - end_key_cache(&dflt_keycache,1); + end_key_cache(dflt_keycache,1); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); |