#At file:///Users/thek/Development/mysql-pe/ based on revid:joro@stripped
3698 Kristofer Pettersson 2009-11-20 [merge]
Merge mysql-5.1-bugteam => mysql-pe
modified:
sql/sql_cache.cc
sql/sql_cache.h
=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc 2009-11-20 12:49:47 +0000
+++ b/sql/sql_cache.cc 2009-11-20 20:14:11 +0000
@@ -423,12 +423,16 @@ TYPELIB query_cache_type_typelib=
effect by another thread. This enables a quick path in execution to skip waits
when the outcome is known.
+ @param use_timeout TRUE if the lock can abort because of a timeout.
+
+ @note use_timeout is optional and default value is FALSE.
+
@return
@retval FALSE An exclusive lock was taken
@retval TRUE The locking attempt failed
*/
-bool Query_cache::try_lock(void)
+bool Query_cache::try_lock(bool use_timeout)
{
bool interrupt= FALSE;
DBUG_ENTER("Query_cache::try_lock");
@@ -458,7 +462,26 @@ bool Query_cache::try_lock(void)
else
{
DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED);
- pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
+ /*
+ To prevent send_result_to_client() and query_cache_insert() from
+ blocking execution for too long a timeout is put on the lock.
+ */
+ if (use_timeout)
+ {
+ struct timespec waittime;
+ set_timespec_nsec(waittime,(ulong)(50000000L)); /* Wait for 50 msec */
+ int res= pthread_cond_timedwait(&COND_cache_status_changed,
+ &structure_guard_mutex,&waittime);
+ if (res == ETIMEDOUT)
+ {
+ interrupt= TRUE;
+ break;
+ }
+ }
+ else
+ {
+ pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
+ }
}
}
pthread_mutex_unlock(&structure_guard_mutex);
@@ -1207,8 +1230,13 @@ def_week_frmt: %lu, in_trans: %d, autoco
A table- or a full flush operation can potentially take a long time to
finish. We choose not to wait for them and skip caching statements
instead.
+
+ In case the wait time can't be determined there is an upper limit which
+ causes try_lock() to abort with a time out.
+
+ The 'TRUE' parameter indicate that the lock is allowed to timeout
*/
- if (try_lock())
+ if (try_lock(TRUE))
DBUG_VOID_RETURN;
if (query_cache_size == 0)
{
@@ -1406,7 +1434,10 @@ Query_cache::send_result_to_client(THD *
}
}
- if (try_lock())
+ /*
+ The 'TRUE' parameter indicate that the lock is allowed to timeout
+ */
+ if (try_lock(TRUE))
goto err;
if (query_cache_size == 0)
=== modified file 'sql/sql_cache.h'
--- a/sql/sql_cache.h 2009-11-02 15:16:58 +0000
+++ b/sql/sql_cache.h 2009-11-20 20:14:11 +0000
@@ -495,7 +495,7 @@ protected:
const char *name);
my_bool in_blocks(Query_cache_block * point);
- bool try_lock(void);
+ bool try_lock(bool use_timeout= FALSE);
void lock(void);
void lock_and_suspend(void);
void unlock(void);
Attachment: [text/bzr-bundle]
| Thread |
|---|
| • bzr commit into mysql-pe branch (kristofer.pettersson:3698) | Kristofer Pettersson | 20 Nov |