summaryrefslogtreecommitdiff
path: root/sql/sql_cache.cc
diff options
context:
space:
mode:
authorthek@adventure.(none) <>2007-09-03 10:59:44 +0200
committerthek@adventure.(none) <>2007-09-03 10:59:44 +0200
commit0184f50f2771e3869dacaa7e7ada44c8aaeed1d7 (patch)
treec337cf8e78b0610c68e5e36d071e972e7f2a113d /sql/sql_cache.cc
parentca2b2585a5debe6c2ca6f0fb9c48d5c107fe09cf (diff)
parent85d70078489a7c4eaa51e2887895b32e56130b01 (diff)
downloadmariadb-git-0184f50f2771e3869dacaa7e7ada44c8aaeed1d7.tar.gz
Merge kpettersson@bk-internal.mysql.com:/home/bk/mysql-5.0-runtime
into adventure.(none):/home/thek/Development/cpp/mysql-5.0-runtime
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r--sql/sql_cache.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index e1df1ce8d9a..4249f5e923f 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1032,6 +1032,13 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
Query_cache_block_table *block_table, *block_table_end;
ulong tot_length;
Query_cache_query_flags flags;
+ const uint spin_treshold= 50000;
+ const double lock_time_treshold= 0.1; /* Time in seconds */
+ uint spin_count= 0;
+ int lock_status= 0;
+ ulong new_time= 0;
+ ulong stop_time= 0;
+
DBUG_ENTER("Query_cache::send_result_to_client");
/*
@@ -1078,7 +1085,29 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
}
}
- STRUCT_LOCK(&structure_guard_mutex);
+ stop_time= my_clock()+(ulong)lock_time_treshold*CLOCKS_PER_SEC;
+ while ((lock_status= pthread_mutex_trylock(&structure_guard_mutex)) == EBUSY
+ && spin_count < spin_treshold
+ && new_time < stop_time)
+ {
+ spin_count++;
+ if (spin_count%5)
+ new_time= my_clock();
+ pthread_yield();
+ }
+
+ if (lock_status != 0)
+ {
+ /*
+ Query cache is too busy doing something else.
+ Fall back on ordinary statement execution. We also mark this
+ query as unsafe to cache because otherwise this thread will
+ still be halted when the result set is stored to the cache.
+ */
+ thd->lex->safe_to_cache_query= FALSE;
+ goto err;
+ }
+
if (query_cache_size == 0 || flush_in_progress)
{
DBUG_PRINT("qcache", ("query cache disabled"));