Commit 6bef652d authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-4409 - Fix deadlock in MySQL key cache code, that can happen if there is...

MDEV-4409 - Fix deadlock in MySQL key cache code, that can happen if there is a key cache resize running in parallel with an update.

If there is a key cache resize,a  thread writing to key cache, will pause waiting  until resize finishes. However this thread is won't be woken, because resize does not  signaling waiters anymore. This is a regression introduced in WL#86(segmented MyISAM key cache)
The fix is to unconditionally release  threads waiting on resize_queue when resize  finishes, as in pre-WL#86 code.
parent 762d3cb8
......@@ -652,7 +652,6 @@ err:
SYNOPSIS
prepare_resize_simple_key_cache()
keycache pointer to the control block of a simple key cache
with_resize_queue <=> resize queue is used
release_lock <=> release the key cache lock before return
DESCRIPTION
......@@ -660,10 +659,8 @@ err:
this it destroys the key cache calling end_simple_key_cache. The function
takes the parameter keycache as a pointer to the control block
structure of the type SIMPLE_KEY_CACHE_CB for this key cache.
The parameter with_resize_queue determines weather the resize queue is
involved (MySQL server never uses this queue). The parameter release_lock
says weather the key cache lock must be released before return from
the function.
The parameter release_lock says whether the key cache lock must be
released before return from the function.
RETURN VALUE
0 - on success,
......@@ -677,7 +674,6 @@ err:
static
int prepare_resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache,
my_bool with_resize_queue,
my_bool release_lock)
{
int res= 0;
......@@ -692,7 +688,7 @@ int prepare_resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache,
one resizer only. In set_var.cc keycache->in_init is used to block
multiple attempts.
*/
while (with_resize_queue && keycache->in_resize)
while (keycache->in_resize)
{
/* purecov: begin inspected */
wait_on_queue(&keycache->resize_queue, &keycache->cache_lock);
......@@ -760,7 +756,6 @@ finish:
SYNOPSIS
finish_resize_simple_key_cache()
keycache pointer to the control block of a simple key cache
with_resize_queue <=> resize queue is used
acquire_lock <=> acquire the key cache lock at start
DESCRIPTION
......@@ -769,9 +764,7 @@ finish:
keycache as a pointer to the control block structure of the type
SIMPLE_KEY_CACHE_CB for this key cache. The function sets the flag
in_resize in this structure to FALSE.
The parameter with_resize_queue determines weather the resize queue
is involved (MySQL server never uses this queue).
The parameter acquire_lock says weather the key cache lock must be
The parameter acquire_lock says whether the key cache lock must be
acquired at the start of the function.
RETURN VALUE
......@@ -785,7 +778,6 @@ finish:
static
void finish_resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache,
my_bool with_resize_queue,
my_bool acquire_lock)
{
DBUG_ENTER("finish_resize_simple_key_cache");
......@@ -801,11 +793,10 @@ void finish_resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache,
*/
keycache->in_resize= 0;
if (with_resize_queue)
{
/* Signal waiting threads. */
release_whole_queue(&keycache->resize_queue);
}
keycache_pthread_mutex_unlock(&keycache->cache_lock);
......@@ -872,7 +863,7 @@ int resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, uint key_cache_block_
We do not lose the cache_lock and will release it only at the end of
this function.
*/
if (prepare_resize_simple_key_cache(keycache, 1, 0))
if (prepare_resize_simple_key_cache(keycache, 0))
goto finish;
/* The following will work even if use_mem is 0 */
......@@ -880,7 +871,7 @@ int resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, uint key_cache_block_
division_limit, age_threshold);
finish:
finish_resize_simple_key_cache(keycache, 1, 0);
finish_resize_simple_key_cache(keycache, 0);
DBUG_RETURN(blocks);
}
......@@ -5279,7 +5270,7 @@ int resize_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache,
}
for (i= 0; i < partitions; i++)
{
err|= prepare_resize_simple_key_cache(keycache->partition_array[i], 0, 1);
err|= prepare_resize_simple_key_cache(keycache->partition_array[i], 1);
}
if (!err)
blocks= init_partitioned_key_cache(keycache, key_cache_block_size,
......@@ -5288,7 +5279,7 @@ int resize_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache,
{
for (i= 0; i < partitions; i++)
{
finish_resize_simple_key_cache(keycache->partition_array[i], 0, 1);
finish_resize_simple_key_cache(keycache->partition_array[i], 1);
}
}
DBUG_RETURN(blocks);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment