summaryrefslogtreecommitdiff
path: root/myisam
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2003-10-01 18:20:07 -0700
committerunknown <igor@rurik.mysql.com>2003-10-01 18:20:07 -0700
commit7de7c38f2f1b678e6d1894b94dd9abe9de9d8c70 (patch)
treeab4010966244b960fcb1389f9520f9dc880f6c8e /myisam
parent5a85cb66be2dd3562f042d2ef08a1b2382c713e8 (diff)
downloadmariadb-git-7de7c38f2f1b678e6d1894b94dd9abe9de9d8c70.tar.gz
Many files:
Improved concurrency for key cache reassignment include/my_sys.h: Improved concurrency for key cache reassignment include/myisam.h: Improved concurrency for key cache reassignment myisam/mi_keycache.c: Improved concurrency for key cache reassignment myisam/mi_locking.c: Improved concurrency for key cache reassignment mysys/mf_keycache.c: Improved concurrency for key cache reassignment sql/ha_myisam.cc: Improved concurrency for key cache reassignment sql/sql_table.cc: Improved concurrency for key cache reassignment
Diffstat (limited to 'myisam')
-rw-r--r--myisam/mi_keycache.c52
-rw-r--r--myisam/mi_locking.c7
2 files changed, 49 insertions, 10 deletions
diff --git a/myisam/mi_keycache.c b/myisam/mi_keycache.c
index 1010aef9e1d..4b7d7d6b23f 100644
--- a/myisam/mi_keycache.c
+++ b/myisam/mi_keycache.c
@@ -39,24 +39,68 @@
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;
+
+static void remove_key_cache_assign(void *arg)
+{
+ 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))
+ {
+ my_free(extra_info, MYF(0));
+ key_cache->extra_info= 0;
+ if (waiting_thread != my_thread_var)
+ pthread_cond_signal(&waiting_thread->suspend);
+ }
+ pthread_mutex_unlock(lock);
+}
+
int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map,
- KEY_CACHE_HANDLE *reg_keycache)
+ 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");
- share->reg_keycache= reg_keycache;
+ 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_RELEASE))
+ 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= reg_keycache;
+ share->keycache= &key_cache->cache;
}
+ else
+ {
+ extra_info->waiting_thread= my_thread_var;
+ }
+
DBUG_RETURN(error);
}
diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c
index 14d0b60741f..af0c760b706 100644
--- a/myisam/mi_locking.c
+++ b/myisam/mi_locking.c
@@ -62,17 +62,12 @@ int mi_lock_database(MI_INFO *info, int lock_type)
/*
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 &&
((switch_fl= share->keycache != share->reg_keycache) ||
!share->delay_key_write) &&
flush_key_blocks(*share->keycache, share->kfile,
- switch_fl ? FLUSH_RELEASE : FLUSH_KEEP))
+ switch_fl ? FLUSH_REMOVE : FLUSH_KEEP))
{
error=my_errno;
mi_mark_crashed(info); /* Mark that table must be checked */