diff options
author | unknown <thek@adventure.(none)> | 2007-07-02 19:14:48 +0200 |
---|---|---|
committer | unknown <thek@adventure.(none)> | 2007-07-02 19:14:48 +0200 |
commit | 289cc26c646f5a45e2c9fc6c0bb75f6f61d301a1 (patch) | |
tree | 6ae98744dc3b93525f63eb7f5c0c84bcbf702b47 /sql/lock.cc | |
parent | 0484d44eebff70ef5a2c328c7a9d50ac07a89409 (diff) | |
download | mariadb-git-289cc26c646f5a45e2c9fc6c0bb75f6f61d301a1.tar.gz |
Bug#21074 Large query_cache freezes mysql server sporadically under heavy load
Invaldating a subset of a sufficiently large query cache can take a long time.
During this time the server is efficiently frozen and no other operation can
be executed. This patch addresses this problem by moving the locks which cause
the freezing and also by temporarily disable the query cache while the
invalidation takes place.
sql/ha_ndbcluster.cc:
- mysql_rm_table_part2 has a new parameter to indicate if OPEN_lock mutex
protection is needed.
sql/lock.cc:
- Added function for acquiring table name exclusive locks.
- Added function for asserting that table name lock is acquired.
sql/mysql_priv.h:
- Added function for acquiring table name exclusive locks.
- Added function for asserting that table name lock is acquired.
- Added parameter to mysql_rm_table_part2 to indicate whether OPEN_lock mutex
protection is needed or not.
sql/sql_cache.cc:
- Changed flush_in_progress-flag into a state and added a function,
is_flushing() to reflect on this state. A new state was needed to indicate
that a partial invalidation was in progress.
- An unused parameter 'under_guard' was removed.
- The Query_cache mutex structural_guard was pushed down into one
invalidate_table function to avoid multiple entry points which makes
maintainens more difficult.
- Instead of keeping the structural_guard mutex during the entire invalidation
we set the query cache status state to TABLE_FLUSH_IN_PROGRESS to
temporarily disable the cache and avoid locking other threads needing the
Query_cache resource.
sql/sql_cache.h:
- Changed flush_in_progress-flag into a state and added a function,
is_flushing() to reflect on this state. A new state was needed to indicate
that a partial invalidation was in progress.
- An unused parameter 'under_guard' was removed.
- The Query_cache mutex structural_guard was pushed down into one
invalidate_table function to avoid multiple entry points which makes
maintainens more difficult.
- Instead of keeping the structural_guard mutex during the entire invalidation
we set the query cache status state to TABLE_FLUSH_IN_PROGRESS to
temporarily disable the cache and avoid locking other threads needing the
the Query_cache resource.
sql/sql_db.cc:
- mysql_rm_table_part2_with_lock is redundant and replaced
with mysql_rm_table_part2.
sql/sql_parse.cc:
- Function query_cache_invalidate3 isn't protect by a lock and we have a
race condition.
- Moving this function into mysql_rename_tables and make sure it is protected
by a exclusive table name lock.
sql/sql_rename.cc:
- Function query_cache_invalidation3 isn't protect by a lock and we have a
race condition.
- Moving this function into mysql_rename_tables and make sure it is protected
by a exclusive table name lock.
- Instead of using LOCK_open mutex, which excludes all other threads, the lock
is changed into exclusive table name locks instead. This prevents us from
locking the server if a query cache invalidation would take a long time to
complete.
sql/sql_table.cc:
- Instead of using LOCK_open mutex, which excludes all other threads, the lock
is changed into exclusive table name locks instead. This prevents us from
locking the server if a query cache invalidation would take a long time to
complete.
- Added new parameter to mysql_rm_table_part2 to control whether OPEN_lock mutex
needs to be aquired or not. This is currently needed by the NDB implemenation.
sql/sql_trigger.cc:
- Table_triggers don't need to be protexted by LOCK_open mutex. This
patch cancel this restriction.
- Refactored comments to doxygen style.
Diffstat (limited to 'sql/lock.cc')
-rw-r--r-- | sql/lock.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index 6f1dd0669ee..6c1196e29c0 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1027,6 +1027,102 @@ end: } +/** + @brief Lock all tables in list with an exclusive table name lock. + + @param thd Thread handle. + @param table_list Names of tables to lock. + + @note This function needs to be protected by LOCK_open. If we're + under LOCK TABLES, this function does not work as advertised. Namely, + it does not exclude other threads from using this table and does not + put an exclusive name lock on this table into the table cache. + + @see lock_table_names + @see unlock_table_names + + @retval TRUE An error occured. + @retval FALSE Name lock successfully acquired. +*/ + +bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list) +{ + if (lock_table_names(thd, table_list)) + return TRUE; + + /* + Upgrade the table name locks from semi-exclusive to exclusive locks. + */ + for (TABLE_LIST *table= table_list; table; table= table->next_global) + { + if (table->table) + table->table->open_placeholder= 1; + } + return FALSE; +} + + +/** + @brief Test is 'table' is protected by an exclusive name lock. + + @param[in] thd The current thread handler + @param[in] table Table container containing the single table to be tested + + @note Needs to be protected by LOCK_open mutex. + + @return Error status code + @retval TRUE Table is protected + @retval FALSE Table is not protected +*/ + +bool +is_table_name_exclusively_locked_by_this_thread(THD *thd, + TABLE_LIST *table_list) +{ + char key[MAX_DBKEY_LENGTH]; + uint key_length; + + key_length= create_table_def_key(thd, key, table_list, 0); + + return is_table_name_exclusively_locked_by_this_thread(thd, (uchar *)key, + key_length); +} + + +/** + @brief Test is 'table key' is protected by an exclusive name lock. + + @param[in] thd The current thread handler. + @param[in] table Table container containing the single table to be tested. + + @note Needs to be protected by LOCK_open mutex + + @retval TRUE Table is protected + @retval FALSE Table is not protected + */ + +bool +is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key, + int key_length) +{ + HASH_SEARCH_STATE state; + TABLE *table; + + for (table= (TABLE*) hash_first(&open_cache, key, + key_length, &state); + table ; + table= (TABLE*) hash_next(&open_cache, key, + key_length, &state)) + { + if (table->in_use == thd && + table->open_placeholder == 1 && + table->s->version == 0) + return TRUE; + } + + return FALSE; +} + /* Unlock all tables in list with a name lock |