From f577d864cdac14d9a5cf7714b3506bab7688b1c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 17:35:30 +0300 Subject: A fix for Bug#7209 "Client error with "Access Denied" on updates when high concurrency": remove HASH::current_record and make it an external search parameter, so that it can not be the cause of a race condition under high concurrent load. The bug was in a race condition in table_hash_search, when column_priv_hash.current_record was overwritten simultaneously by multiple threads, causing the search for a suitable grant record to fail. No test case as the bug is repeatable only under concurrent load. include/hash.h: - remove current_record from HASH, instead modify hash_first, hash_next to accept HASH_SEARCH_STATE as an IN/OUT parameter mysys/hash.c: - remove HASH::current_record - change declarations of functions that use HASH in read-only mode to accept const HASH * instead of HASH *. - implement hash_search; move the old implementation of hash_search to hash_first mysys/testhash.c: - adjust the test case to changed function declarations sql/lock.cc: - adjust to changed declarations of hash_search, hash_next sql/sql_acl.cc: - adjust to changed declarations of hash_search, hash_next sql/sql_base.cc: - adjust to changed declarations of hash_search, hash_nex sql/sql_cache.cc: - adjust to a changed declaration of hash_replace --- sql/sql_base.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8b1fa754929..c8443948a4a 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -799,6 +799,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, reg1 TABLE *table; char key[MAX_DBKEY_LENGTH]; uint key_length; + HASH_SEARCH_STATE state; DBUG_ENTER("open_table"); /* find a unused table in the open table cache */ @@ -863,9 +864,11 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, /* close handler tables which are marked for flush */ mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); - for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; + for (table= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, + &state); table && table->in_use ; - table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + table= (TABLE*) hash_next(&open_cache, (byte*) key, key_length, + &state)) { if (table->version != refresh_version) { @@ -1236,12 +1239,14 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock) { do { + HASH_SEARCH_STATE state; char *key= table->table_cache_key; uint key_length=table->key_length; - for (TABLE *search=(TABLE*) hash_search(&open_cache, - (byte*) key,key_length) ; + for (TABLE *search= (TABLE*) hash_first(&open_cache, (byte*) key, + key_length, &state); search ; - search = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + search= (TABLE*) hash_next(&open_cache, (byte*) key, + key_length, &state)) { if (search->locked_by_flush || search->locked_by_name && wait_for_name_lock || @@ -2958,11 +2963,14 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; for (;;) { + HASH_SEARCH_STATE state; result= signalled= 0; - for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; + for (table= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, + &state); table; - table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + table= (TABLE*) hash_next(&open_cache, (byte*) key, key_length, + &state)) { THD *in_use; table->version=0L; /* Free when thread is ready */ -- cgit v1.2.1 From 58d4830c6352422177630ce31160d0d0aaa9aab1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 21:39:39 +0300 Subject: Post-merge fixes. sql/sql_acl.cc: A post-merge fix. sql/sql_base.cc: A post-merge fix. --- sql/sql_base.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 290f16a09d6..0b414f59223 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1624,7 +1624,8 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock) { char *key= table->s->table_cache_key; uint key_length= table->s->key_length; - for (TABLE *search= (TABLE*) hash_search(&open_cache, (byte*) key, + HASH_SEARCH_STATE state; + for (TABLE *search= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, &state); search ; search= (TABLE*) hash_next(&open_cache, (byte*) key, -- cgit v1.2.1