Skip to content

Commit

Permalink
Fixed shutdown crash in Aria that affects debug binaries
Browse files Browse the repository at this point in the history
MDEV-18286 Assertion `pagecache->cnt_for_resize_op == 0' failed in
check_pagecache_is_cleaned_up on server shutdown

The reason for the crash is that the counter-of-pinned-pages in the
Aria pagecache goes wrong.
This only affects debug builds, as in these we do an assert on shutdown
if the counter-of-pinned-pages is not 0 (some page was left pinned).

The bug was that in 2 places in the page cache, when not succeeding to
pin a page and a retry was made, the counter-of-pinned-pages counter was
not properly adjusted.

In the given test case, BLOCK_COMMIT flushed all Aria files. If a block was flushed at the same time the insert tried to access it, the insert would retry to get the block and that would cause the counter to go wrong.
  • Loading branch information
montywi committed Apr 26, 2020
1 parent a197825 commit 81511b4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion storage/maria/ma_pagecache.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct st_pagecache_hash_link

/* simple states of a block */
#define PCBLOCK_ERROR 1 /* an error occurred when performing disk i/o */
#define PCBLOCK_READ 2 /* the is page in the block buffer */
#define PCBLOCK_READ 2 /* there is an active page in the block buffer */

/*
A tread is reading the data to the page.
Expand Down Expand Up @@ -3431,6 +3431,7 @@ uchar *pagecache_read(PAGECACHE *pagecache,
*/
if (reg_request)
unreg_request(pagecache, block, 1);
dec_counter_for_resize_op(pagecache);
pagecache_pthread_mutex_unlock(&pagecache->cache_lock);
DBUG_PRINT("info", ("restarting..."));
goto restart;
Expand Down Expand Up @@ -3707,6 +3708,7 @@ my_bool pagecache_delete_by_link(PAGECACHE *pagecache,
DBUG_ASSERT((block->status &
(PCBLOCK_IN_SWITCH | PCBLOCK_REASSIGNED)) == 0);

/* This lock is deleted in pagecache_delete_internal() called below */
inc_counter_for_resize_op(pagecache);
/*
make_lock_and_pin() can't fail here, because we are keeping pin on the
Expand Down Expand Up @@ -3851,6 +3853,7 @@ my_bool pagecache_delete(PAGECACHE *pagecache,
*/
if (pin == PAGECACHE_PIN)
unreg_request(pagecache, block, 1);
dec_counter_for_resize_op(pagecache);
pagecache_pthread_mutex_unlock(&pagecache->cache_lock);
DBUG_PRINT("info", ("restarting..."));
goto restart;
Expand Down

0 comments on commit 81511b4

Please sign in to comment.