summaryrefslogtreecommitdiff
path: root/sql/sql_cache.h
diff options
context:
space:
mode:
authorunknown <thek@adventure.(none)>2007-07-02 19:14:48 +0200
committerunknown <thek@adventure.(none)>2007-07-02 19:14:48 +0200
commit289cc26c646f5a45e2c9fc6c0bb75f6f61d301a1 (patch)
tree6ae98744dc3b93525f63eb7f5c0c84bcbf702b47 /sql/sql_cache.h
parent0484d44eebff70ef5a2c328c7a9d50ac07a89409 (diff)
downloadmariadb-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/sql_cache.h')
-rw-r--r--sql/sql_cache.h72
1 files changed, 59 insertions, 13 deletions
diff --git a/sql/sql_cache.h b/sql/sql_cache.h
index 3c5d784ce94..cfc52e5d33a 100644
--- a/sql/sql_cache.h
+++ b/sql/sql_cache.h
@@ -65,17 +65,44 @@ struct Query_cache_query;
struct Query_cache_result;
class Query_cache;
+/**
+ @brief This class represents a node in the linked chain of queries
+ belonging to one table.
+ @note The root of this linked list is not a query-type block, but the table-
+ type block which all queries has in common.
+*/
struct Query_cache_block_table
{
Query_cache_block_table() {} /* Remove gcc warning */
- TABLE_COUNTER_TYPE n; // numbr in table (from 0)
+
+ /**
+ This node holds a position in a static table list belonging
+ to the associated query (base 0).
+ */
+ TABLE_COUNTER_TYPE n;
+
+ /**
+ Pointers to the next and previous node, linking all queries with
+ a common table.
+ */
Query_cache_block_table *next, *prev;
+
+ /**
+ A pointer to the table-type block which all
+ linked queries has in common.
+ */
Query_cache_table *parent;
+
+ /**
+ A method to calculate the address of the query cache block
+ owning this node. The purpose of this calculation is to
+ make it easier to move the query cache block without having
+ to modify all the pointer addresses.
+ */
inline Query_cache_block *block();
};
-
struct Query_cache_block
{
Query_cache_block() {} /* Remove gcc warning */
@@ -151,6 +178,11 @@ struct Query_cache_table
/* data need by some engines */
ulonglong engine_data_buff;
+ /**
+ The number of queries depending of this table.
+ */
+ int32 m_cached_query_count;
+
inline char *db() { return (char *) data(); }
inline char *table() { return tbl; }
inline void table(char *table_arg) { tbl= table_arg; }
@@ -237,9 +269,14 @@ public:
ulong free_memory, queries_in_cache, hits, inserts, refused,
free_memory_blocks, total_blocks, lowmem_prunes;
+
private:
- pthread_cond_t COND_flush_finished;
- bool flush_in_progress;
+ pthread_cond_t COND_cache_status_changed;
+
+ enum Cache_status { NO_FLUSH_IN_PROGRESS, FLUSH_IN_PROGRESS,
+ TABLE_FLUSH_IN_PROGRESS };
+
+ Cache_status m_cache_status;
void free_query_internal(Query_cache_block *point);
@@ -253,7 +290,7 @@ protected:
2. query block (for operation inside query (query block/results))
Thread doing cache flush releases the mutex once it sets
- flush_in_progress flag, so other threads may bypass the cache as
+ m_cache_status flag, so other threads may bypass the cache as
if it is disabled, not waiting for reset to finish. The exception
is other threads that were going to do cache flush---they'll wait
till the end of a flush operation.
@@ -270,6 +307,7 @@ protected:
/* options */
ulong min_allocation_unit, min_result_data_size;
uint def_query_hash_size, def_table_hash_size;
+
uint mem_bin_num, mem_bin_steps; // See at init_cache & find_bin
my_bool initialized;
@@ -295,10 +333,13 @@ protected:
ulong data_len,
Query_cache_block *query_block,
my_bool first_block);
- void invalidate_table(TABLE_LIST *table);
- void invalidate_table(TABLE *table);
- void invalidate_table(uchar *key, uint32 key_length);
- void invalidate_table(Query_cache_block *table_block);
+ void invalidate_table(THD *thd, TABLE_LIST *table);
+ void invalidate_table(THD *thd, TABLE *table);
+ void invalidate_table(THD *thd, uchar *key, uint32 key_length);
+ void invalidate_table(THD *thd, Query_cache_block *table_block);
+ void invalidate_query_block_list(THD *thd,
+ Query_cache_block_table *list_root);
+
TABLE_COUNTER_TYPE
register_tables_from_list(TABLE_LIST *tables_used,
TABLE_COUNTER_TYPE counter,
@@ -337,6 +378,8 @@ protected:
Query_cache_block *pprev);
my_bool join_results(ulong join_limit);
+ void wait_while_table_flush_is_in_progress(bool *interrupt);
+
/*
Following function control structure_guard_mutex
by themself or don't need structure_guard_mutex
@@ -347,8 +390,7 @@ protected:
Query_cache_block *write_block_data(ulong data_len, uchar* data,
ulong header_len,
Query_cache_block::block_type type,
- TABLE_COUNTER_TYPE ntab = 0,
- my_bool under_guard=0);
+ TABLE_COUNTER_TYPE ntab = 0);
my_bool append_result_data(Query_cache_block **result,
ulong data_len, uchar* data,
Query_cache_block *parent);
@@ -360,8 +402,7 @@ protected:
inline ulong get_min_first_result_data_size();
inline ulong get_min_append_result_data_size();
Query_cache_block *allocate_block(ulong len, my_bool not_less,
- ulong min,
- my_bool under_guard=0);
+ ulong min);
/*
If query is cacheable return number tables in query
(query without tables not cached)
@@ -424,6 +465,11 @@ protected:
friend void query_cache_end_of_result(THD *thd);
friend void query_cache_abort(NET *net);
+ bool is_flushing(void)
+ {
+ return (m_cache_status != Query_cache::NO_FLUSH_IN_PROGRESS);
+ }
+
/*
The following functions are only used when debugging
We don't protect these with ifndef DBUG_OFF to not have to recompile