summaryrefslogtreecommitdiff
path: root/myisam
diff options
context:
space:
mode:
Diffstat (limited to 'myisam')
-rw-r--r--myisam/ft_nlq_search.c3
-rw-r--r--myisam/ft_static.c8
-rw-r--r--myisam/mi_check.c34
-rw-r--r--myisam/mi_checksum.c1
-rw-r--r--myisam/mi_close.c2
-rw-r--r--myisam/mi_delete_all.c2
-rw-r--r--myisam/mi_extra.c5
-rw-r--r--myisam/mi_keycache.c172
-rw-r--r--myisam/mi_locking.c15
-rw-r--r--myisam/mi_open.c2
-rw-r--r--myisam/mi_page.c9
-rw-r--r--myisam/mi_panic.c2
-rw-r--r--myisam/mi_preload.c6
-rw-r--r--myisam/mi_test1.c2
-rw-r--r--myisam/mi_test2.c8
-rw-r--r--myisam/mi_test3.c2
-rw-r--r--myisam/myisamchk.c8
-rw-r--r--myisam/myisamdef.h5
-rw-r--r--myisam/myisamlog.c4
19 files changed, 169 insertions, 121 deletions
diff --git a/myisam/ft_nlq_search.c b/myisam/ft_nlq_search.c
index 3ddbe959cff..1e3d47577d2 100644
--- a/myisam/ft_nlq_search.c
+++ b/myisam/ft_nlq_search.c
@@ -225,7 +225,8 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
if (flags & FT_EXPAND && ft_query_expansion_limit)
{
QUEUE best;
- init_queue(&best,ft_query_expansion_limit,0,0, &FT_DOC_cmp, 0);
+ init_queue(&best,ft_query_expansion_limit,0,0, (queue_compare) &FT_DOC_cmp,
+ 0);
tree_walk(&aio.dtree, (tree_walk_action) &walk_and_push,
&best, left_root_right);
while (best.elements)
diff --git a/myisam/ft_static.c b/myisam/ft_static.c
index 2edb86679e9..cf4f3d6a02a 100644
--- a/myisam/ft_static.c
+++ b/myisam/ft_static.c
@@ -53,13 +53,17 @@ const struct _ft_vft _ft_vft_boolean = {
ft_boolean_get_relevance, ft_boolean_reinit_search
};
+
FT_INFO *ft_init_search(uint flags, void *info, uint keynr,
byte *query, uint query_len, byte *record)
{
+ FT_INFO *res;
if (flags & FT_BOOL)
- ft_init_boolean_search((MI_INFO *)info, keynr, query, query_len);
+ res= ft_init_boolean_search((MI_INFO *)info, keynr, query, query_len);
else
- ft_init_nlq_search((MI_INFO *)info, keynr, query, query_len, flags, record);
+ res= ft_init_nlq_search((MI_INFO *)info, keynr, query, query_len, flags,
+ record);
+ return res;
}
const char *ft_stopword_file = 0;
diff --git a/myisam/mi_check.c b/myisam/mi_check.c
index a75ac75a2e9..cfdb696b60b 100644
--- a/myisam/mi_check.c
+++ b/myisam/mi_check.c
@@ -77,6 +77,7 @@ void myisamchk_init(MI_CHECK *param)
param->tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
param->myf_rw=MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL);
param->start_check_pos=0;
+ param->key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
}
/* Check the status flags for the table */
@@ -241,7 +242,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(*info->s->keycache,
+ if (!(buff=key_cache_read(*info->s->key_cache,
info->s->kfile, next_link, DFLT_INIT_HITS,
(byte*) info->buff,
myisam_block_size, block_size, 1)))
@@ -272,7 +273,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info)
if (!(param->testflag & T_SILENT)) puts("- check file-size");
- flush_key_blocks(*info->s->keycache,
+ flush_key_blocks(*info->s->key_cache,
info->s->kfile, FLUSH_FORCE_WRITE); /* If called externally */
size=my_seek(info->s->kfile,0L,MY_SEEK_END,MYF(0));
@@ -1142,8 +1143,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_cache_var.block_size,
- param->use_buffers,&dflt_key_cache_var));
+ VOID(init_key_cache(dflt_keycache, param->key_cache_block_size,
+ param->use_buffers, &dflt_key_cache_var));
if (init_io_cache(&param->read_cache,info->dfile,
(uint) param->read_buffer_length,
@@ -1364,7 +1365,7 @@ err:
VOID(end_io_cache(&param->read_cache));
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
VOID(end_io_cache(&info->rec_cache));
- got_error|=flush_blocks(param,share->kfile);
+ got_error|=flush_blocks(param, *share->key_cache, share->kfile);
if (!got_error && param->testflag & T_UNPACK)
{
share->state.header.options[0]&= (uchar) ~HA_OPTION_COMPRESS_RECORD;
@@ -1500,15 +1501,15 @@ void lock_memory(MI_CHECK *param __attribute__((unused)))
/* Flush all changed blocks to disk */
-int flush_blocks(MI_CHECK *param, File file)
+int flush_blocks(MI_CHECK *param, KEY_CACHE_HANDLE key_cache, File file)
{
- if (flush_key_blocks(*dflt_keycache,file,FLUSH_RELEASE))
+ if (flush_key_blocks(key_cache, 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(key_cache,1);
return 0;
} /* flush_blocks */
@@ -1563,7 +1564,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(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED);
+ flush_key_blocks(*share->key_cache,share->kfile, FLUSH_IGNORE_CHANGED);
share->state.version=(ulong) time((time_t*) 0);
old_state= share->state; /* save state if not stored */
@@ -1873,7 +1874,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(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED);
+ flush_key_blocks(*share->key_cache,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;
@@ -1883,7 +1884,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
}
else
{
- if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE))
+ if (flush_key_blocks(*share->key_cache,share->kfile, FLUSH_FORCE_WRITE))
goto err;
key_map= ~key_map; /* Create the missing keys */
}
@@ -2075,7 +2076,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
memcpy( &share->state.state, info->state, sizeof(*info->state));
err:
- got_error|= flush_blocks(param,share->kfile);
+ got_error|= flush_blocks(param, *share->key_cache, share->kfile);
VOID(end_io_cache(&info->rec_cache));
if (!got_error)
{
@@ -2236,7 +2237,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(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED);
+ flush_key_blocks(*share->key_cache,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;
@@ -2246,7 +2247,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
}
else
{
- if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE))
+ if (flush_key_blocks(*share->key_cache,share->kfile, FLUSH_FORCE_WRITE))
goto err;
key_map= ~key_map; /* Create the missing keys */
}
@@ -2482,7 +2483,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
memcpy(&share->state.state, info->state, sizeof(*info->state));
err:
- got_error|= flush_blocks(param,share->kfile);
+ got_error|= flush_blocks(param, *share->key_cache, share->kfile);
VOID(end_io_cache(&info->rec_cache));
if (!got_error)
{
@@ -3087,7 +3088,8 @@ int sort_write_record(MI_SORT_PARAM *sort_param)
(info->state->records % WRITE_COUNT) == 0)
{
char llbuff[22];
- printf("%s\r", llstr(info->state->records,llbuff)); VOID(fflush(stdout));
+ printf("%s\r", llstr(info->state->records,llbuff));
+ VOID(fflush(stdout));
}
}
DBUG_RETURN(0);
diff --git a/myisam/mi_checksum.c b/myisam/mi_checksum.c
index cdbb634c5ff..95338434211 100644
--- a/myisam/mi_checksum.c
+++ b/myisam/mi_checksum.c
@@ -27,7 +27,6 @@ ha_checksum mi_checksum(MI_INFO *info, const byte *buf)
for (i=info->s->base.fields ; i-- ; buf+=(rec++)->length)
{
const byte *pos;
- const byte *end;
ulong length;
switch (rec->type) {
case FIELD_BLOB:
diff --git a/myisam/mi_close.c b/myisam/mi_close.c
index 8e7fb497dfc..66d5b08bbc4 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(*share->keycache,share->kfile,
+ flush_key_blocks(*share->key_cache, 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 99873661feb..357df9ebe3e 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(*share->keycache, share->kfile, FLUSH_IGNORE_CHANGED);
+ flush_key_blocks(*share->key_cache, 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 8c7515550e7..327d795d17b 100644
--- a/myisam/mi_extra.c
+++ b/myisam/mi_extra.c
@@ -329,7 +329,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(*share->keycache,share->kfile,FLUSH_KEEP);
+ flush_key_blocks(*share->key_cache, share->kfile, FLUSH_KEEP);
#ifdef HAVE_PWRITE
_mi_decrement_open_count(info);
#endif
@@ -362,9 +362,6 @@ 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 4b7d7d6b23f..c6fd1801740 100644
--- a/myisam/mi_keycache.c
+++ b/myisam/mi_keycache.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+/* Copyright (C) 2003 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
@@ -20,88 +20,136 @@
#include "myisamdef.h"
-
/*
Assign pages of the index file for a table to a key cache
SYNOPSIS
- mi_assign_to_keycache()
+ mi_assign_to_key_cache()
info open table
- map map of indexes to assign to the key cache
+ key_map map of indexes to assign to the key cache
key_cache_ptr pointer to the key cache handle
+ assign_lock Mutex to lock during assignment
- RETURN VALUE
- 0 if a success. error code - otherwise.
+ PREREQUESTS
+ One must have a READ lock or a WRITE lock on the table when calling
+ the function to ensure that there is no other writers to it.
- NOTES.
+ The caller must also ensure that one doesn't call this function from
+ two different threads with the same table.
+
+ NOTES
At present pages for all indexes must be assigned to the same key cache.
In future only pages for indexes specified in the key_map parameter
of the table will be assigned to the specified key cache.
-*/
-typedef struct st_assign_extra_info
-{
- pthread_mutex_t *lock;
- struct st_my_thread_var *waiting_thread;
-} ASSIGN_EXTRA_INFO;
+ RETURN VALUE
+ 0 If a success
+ # Error code
+*/
-static void remove_key_cache_assign(void *arg)
+int mi_assign_to_key_cache(MI_INFO *info,
+ ulonglong key_map __attribute__((unused)),
+ KEY_CACHE_VAR *key_cache)
{
- KEY_CACHE_VAR *key_cache= (KEY_CACHE_VAR *) arg;
- ASSIGN_EXTRA_INFO *extra_info= (ASSIGN_EXTRA_INFO *) key_cache->extra_info;
- struct st_my_thread_var *waiting_thread;
- pthread_mutex_t *lock= extra_info->lock;
- pthread_mutex_lock(lock);
- if (!(--key_cache->assignments) &&
- (waiting_thread = extra_info->waiting_thread))
+ int error= 0;
+ MYISAM_SHARE* share= info->s;
+ DBUG_ENTER("mi_assign_to_key_cache");
+ DBUG_PRINT("enter",("old_key_cache_handle: %lx new_key_cache_handle: %lx",
+ share->key_cache, &key_cache->cache));
+
+ /*
+ Skip operation if we didn't change key cache. This can happen if we
+ call this for all open instances of the same table
+ */
+ if (*share->key_cache == key_cache->cache)
+ DBUG_RETURN(0);
+
+ /*
+ First flush all blocks for the table in the old key cache.
+ This is to ensure that the disk is consistent with the data pages
+ in memory (which may not be the case if the table uses delayed_key_write)
+
+ Note that some other read thread may still fill in the key cache with
+ new blocks during this call and after, but this doesn't matter as
+ all threads will start using the new key cache for their next call to
+ myisam library and we know that there will not be any changed blocks
+ in the old key cache.
+ */
+
+ if (flush_key_blocks(*share->key_cache, share->kfile, FLUSH_REMOVE))
{
- my_free(extra_info, MYF(0));
- key_cache->extra_info= 0;
- if (waiting_thread != my_thread_var)
- pthread_cond_signal(&waiting_thread->suspend);
+ error= my_errno;
+ mi_mark_crashed(info); /* Mark that table must be checked */
}
- pthread_mutex_unlock(lock);
+
+ /*
+ Flush the new key cache for this file. This is needed to ensure
+ that there is no old blocks (with outdated data) left in the new key
+ cache from an earlier assign_to_keycache operation
+
+ (This can never fail as there is never any not written data in the
+ new key cache)
+ */
+ (void) flush_key_blocks(key_cache->cache, share->kfile, FLUSH_REMOVE);
+
+ /*
+ Tell all threads to use the new key cache
+ This should be seen at the lastes for the next call to an myisam function.
+ */
+ share->key_cache= &key_cache->cache;
+
+ /* store the key cache in the global hash structure for future opens */
+ if (multi_key_cache_set(share->unique_file_name, share->unique_name_length,
+ share->key_cache))
+ error= my_errno;
+ DBUG_RETURN(error);
}
-int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map,
- KEY_CACHE_VAR *key_cache,
- pthread_mutex_t *assign_lock)
-{
- ASSIGN_EXTRA_INFO *extra_info;
- int error= 0;
- MYISAM_SHARE* share= info->s;
- DBUG_ENTER("mi_assign_to_keycache");
+/*
+ Change all MyISAM entries that uses one key cache to another key cache
- share->reg_keycache= &key_cache->cache;
- pthread_mutex_lock(assign_lock);
- if (!(extra_info= (ASSIGN_EXTRA_INFO *) key_cache->extra_info))
- {
- if (!(extra_info= (ASSIGN_EXTRA_INFO*) my_malloc(sizeof(ASSIGN_EXTRA_INFO),
- MYF(MY_WME | MY_ZEROFILL))))
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- key_cache->extra_info= extra_info;
- key_cache->action= remove_key_cache_assign;
- extra_info->lock= assign_lock;
- }
- key_cache->assignments++;
- pthread_mutex_unlock(assign_lock);
-
- if (!(info->lock_type == F_WRLCK && share->w_locks))
- {
- if (flush_key_blocks(*share->keycache, share->kfile, FLUSH_REMOVE))
- {
- error=my_errno;
- mi_mark_crashed(info); /* Mark that table must be checked */
- }
- share->keycache= &key_cache->cache;
- }
- else
+ SYNOPSIS
+ mi_change_key_cache()
+ old_key_cache Old key cache
+ new_key_cache New key cache
+
+ NOTES
+ This is used when we delete one key cache.
+
+ To handle the case where some other threads tries to open an MyISAM
+ table associated with the to-be-deleted key cache while this operation
+ is running, we have to call 'multi_key_cache_change()' from this
+ function while we have a lock on the MyISAM table list structure.
+
+ This is safe as long as it's only MyISAM that is using this specific
+ key cache.
+*/
+
+
+void mi_change_key_cache(KEY_CACHE_VAR *old_key_cache,
+ KEY_CACHE_VAR *new_key_cache)
+{
+ LIST *pos;
+ DBUG_ENTER("mi_change_key_cache");
+
+ /*
+ Lock list to ensure that no one can close the table while we manipulate it
+ */
+ pthread_mutex_lock(&THR_LOCK_myisam);
+ for (pos=myisam_open_list ; pos ; pos=pos->next)
{
- extra_info->waiting_thread= my_thread_var;
+ MI_INFO *info= (MI_INFO*) pos->data;
+ MYISAM_SHARE *share= info->s;
+ if (share->key_cache == &old_key_cache->cache)
+ mi_assign_to_key_cache(info, (ulonglong) ~0, new_key_cache);
}
-
- DBUG_RETURN(error);
+ /*
+ We have to do the following call while we have the lock on the
+ MyISAM list structure to ensure that another thread is not trying to
+ open a new table that will be associted with the old key cache
+ */
+ multi_key_cache_change(&old_key_cache->cache, &new_key_cache->cache);
+ pthread_mutex_unlock(&THR_LOCK_myisam);
}
-
diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c
index 6f996ab5abd..2056b018a16 100644
--- a/myisam/mi_locking.c
+++ b/myisam/mi_locking.c
@@ -34,7 +34,6 @@ 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");
DBUG_PRINT("info",("lock_type: %d", lock_type));
@@ -61,21 +60,13 @@ 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.
- */
if (info->lock_type == F_WRLCK && !share->w_locks &&
- ((switch_fl= share->keycache != share->reg_keycache) ||
- !share->delay_key_write) &&
- flush_key_blocks(*share->keycache, share->kfile,
- switch_fl ? FLUSH_REMOVE : FLUSH_KEEP))
+ !share->delay_key_write && flush_key_blocks(*share->key_cache,
+ share->kfile,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))
@@ -398,7 +389,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->keycache,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;
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index 0b4e8681bdd..d5492ae5e35 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -104,6 +104,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share_buff.state.rec_per_key_part=rec_per_key_part;
share_buff.state.key_root=key_root;
share_buff.state.key_del=key_del;
+ share_buff.key_cache= multi_key_cache_search(name_buff, strlen(name_buff));
if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0)
{
@@ -293,6 +294,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
(char*) key_del, (sizeof(my_off_t) *
share->state.header.max_block_size));
strmov(share->unique_file_name, name_buff);
+ share->unique_name_length= strlen(name_buff);
strmov(share->index_file_name, index_name);
strmov(share->data_file_name, data_name);
diff --git a/myisam/mi_page.c b/myisam/mi_page.c
index 72aaac5d381..0aae267e05e 100644
--- a/myisam/mi_page.c
+++ b/myisam/mi_page.c
@@ -32,7 +32,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(*info->s->keycache,
+ tmp=(uchar*) key_cache_read(*info->s->key_cache,
info->s->kfile, page, level, (byte*) buff,
(uint) keyinfo->block_length,
(uint) keyinfo->block_length,
@@ -52,6 +52,7 @@ uchar *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo,
{
DBUG_PRINT("error",("page %lu had wrong page length: %u",
(ulong) page, page_size));
+ DBUG_DUMP("page", tmp, keyinfo->block_length);
info->last_keypage = HA_OFFSET_ERROR;
my_errno = HA_ERR_CRASHED;
tmp = 0;
@@ -94,7 +95,7 @@ int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo,
length=keyinfo->block_length;
}
#endif
- DBUG_RETURN((key_cache_write(*info->s->keycache,
+ DBUG_RETURN((key_cache_write(*info->s->key_cache,
info->s->kfile,page, level, (byte*) buff,length,
(uint) keyinfo->block_length,
(int) ((info->lock_type != F_UNLCK) ||
@@ -116,7 +117,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(*info->s->keycache,
+ DBUG_RETURN(key_cache_write(*info->s->key_cache,
info->s->kfile, pos , level, buff,
sizeof(buff),
(uint) keyinfo->block_length,
@@ -145,7 +146,7 @@ my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level)
}
else
{
- if (!key_cache_read(*info->s->keycache,
+ if (!key_cache_read(*info->s->key_cache,
info->s->kfile, pos, level,
buff,
(uint) sizeof(buff),
diff --git a/myisam/mi_panic.c b/myisam/mi_panic.c
index f1d1d839fcd..cefb3423ccc 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(*info->s->keycache,info->s->kfile,FLUSH_RELEASE))
+ if (flush_key_blocks(*info->s->key_cache, 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 dc4fff5700a..3219c00b0e2 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(*share->keycache,share->kfile, FLUSH_RELEASE))
+ if (flush_key_blocks(*share->key_cache,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(*share->keycache,
+ if (key_cache_insert(*share->key_cache,
share->kfile, pos, DFLT_INIT_HITS,
(byte*) buff, block_length))
goto err;
@@ -99,7 +99,7 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
}
else
{
- if (key_cache_insert(*share->keycache,
+ if (key_cache_insert(*share->key_cache,
share->kfile, pos, DFLT_INIT_HITS,
(byte*) buff, length))
goto err;
diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c
index ec68e23c0c2..c1b76408a7c 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,512,IO_SIZE*16,0);
+ init_key_cache(dflt_keycache,KEY_CACHE_BLOCK_SIZE,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 5a40db3171d..5918a2485b0 100644
--- a/myisam/mi_test2.c
+++ b/myisam/mi_test2.c
@@ -49,7 +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 key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
static uint keys=MYISAM_KEYS,recant=1000;
static uint use_blob=0;
@@ -274,9 +274,9 @@ int main(int argc, char *argv[])
puts("got error from mi_extra(HA_EXTRA_NO_CACHE)");
goto end;
}
- if (key_cacheing)
- resize_key_cache(dflt_keycache,key_cache_block_size,key_cache_size*2);
}
+ if (key_cacheing)
+ resize_key_cache(dflt_keycache,key_cache_block_size,key_cache_size*2);
if (!silent)
printf("- Delete\n");
@@ -829,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 866c6299fac..baeaba7bf24 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,512,65536L,0);
+ init_key_cache(dflt_keycache, KEY_CACHE_BLOCK_SIZE, 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 9136117b86e..9f97f352d39 100644
--- a/myisam/myisamchk.c
+++ b/myisam/myisamchk.c
@@ -715,6 +715,7 @@ static void get_options(register int *argc,register char ***argv)
exit(1);
check_param.tmpdir=&myisamchk_tmpdir;
+ check_param.key_cache_block_size= opt_key_cache_block_size;
if (set_charset_name)
if (!(set_charset=get_charset_by_name(set_charset_name, MYF(MY_WME))))
@@ -1047,7 +1048,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
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->kfile);
+ error|=flush_blocks(param, *share->key_cache, share->kfile);
VOID(end_io_cache(&param->read_cache));
}
if (!error)
@@ -1456,7 +1457,7 @@ 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,opt_key_cache_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,
@@ -1571,7 +1572,8 @@ err:
my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
sort_info.buff=0;
share->state.sortkey=sort_key;
- DBUG_RETURN(flush_blocks(param, share->kfile) | got_error);
+ DBUG_RETURN(flush_blocks(param, *share->key_cache, share->kfile) |
+ got_error);
} /* sort_records */
diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h
index c23959d995c..4f1bed5d50a 100644
--- a/myisam/myisamdef.h
+++ b/myisam/myisamdef.h
@@ -166,8 +166,7 @@ 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 */
+ KEY_CACHE_HANDLE *key_cache; /* ref to the current key cache */
MI_DECODE_TREE *decode_trees;
uint16 *decode_tables;
int (*read_record)(struct st_myisam_info*, my_off_t, byte*);
@@ -188,6 +187,7 @@ typedef struct st_mi_isam_share { /* Shared between opens */
ulong max_pack_length;
ulong state_diff_length;
uint rec_reflength; /* rec_reflength in use now */
+ uint unique_name_length;
File kfile; /* Shared keyfile */
File data_file; /* Shared data file */
int mode; /* mode of file on open */
@@ -713,6 +713,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param);
#ifdef THREAD
pthread_handler_decl(thr_find_all_keys,arg);
#endif
+int flush_blocks(MI_CHECK *param, KEY_CACHE_HANDLE key_cache, File file);
int sort_write_record(MI_SORT_PARAM *sort_param);
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
diff --git a/myisam/myisamlog.c b/myisam/myisamlog.c
index 9b987364521..fbe8b675821 100644
--- a/myisam/myisamlog.c
+++ b/myisam/myisamlog.c
@@ -648,7 +648,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)));
@@ -668,7 +668,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)));