diff options
author | Alexander Nozdrin <alik@sun.com> | 2009-12-12 23:38:59 +0300 |
---|---|---|
committer | Alexander Nozdrin <alik@sun.com> | 2009-12-12 23:38:59 +0300 |
commit | aceea2342faa7e9a4b8b5cea6d18c0801e6975b6 (patch) | |
tree | 2a2432e481d124691d9fa4b39d8a192264178bd1 /sql/sql_cache.cc | |
parent | 376cf4275f28f6b8167eaf19b2c66dee41fbc5c5 (diff) | |
parent | 567671368723c704d60902b4d0ccff951b414552 (diff) | |
download | mariadb-git-aceea2342faa7e9a4b8b5cea6d18c0801e6975b6.tar.gz |
Manual merge from mysql-trunk-merge.
Conflicts:
- extra/comp_err.c
- mysql-test/collections/default.experimental
- mysql-test/r/archive.result
- mysql-test/r/select.result
- mysql-test/suite/binlog/r/binlog_unsafe.result
- mysql-test/suite/binlog/t/binlog_unsafe.test
- mysql-test/suite/rpl/t/disabled.def
- mysql-test/t/archive.test
- mysql-test/t/select.test
- sql/item.cc
- sql/item.h
- sql/item_timefunc.cc
- sql/sql_base.cc
- sql/sql_delete.cc
- sql/sql_load.cc
- sql/sql_partition.cc
- sql/sql_table.cc
- storage/innobase/handler/ha_innodb.cc
- vio/vio.c
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r-- | sql/sql_cache.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index fb370cbd16a..40316299366 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -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); @@ -1213,8 +1236,14 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", 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) { @@ -1415,8 +1444,10 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) Try to obtain an exclusive lock on the query cache. If the cache is disabled or if a full cache flush is in progress, the attempt to get the lock is aborted. + + The 'TRUE' parameter indicate that the lock is allowed to timeout */ - if (try_lock()) + if (try_lock(TRUE)) goto err; if (query_cache_size == 0) |