Skip to content

Commit

Permalink
MDEV-24863 AHI entries mismatch with the index while reloading the ev…
Browse files Browse the repository at this point in the history
…icted tables.

This is after-merge fix of f33e57a.
In btr_search_drop_page_hash_index(), InnoDB should take
the exclusive lock on the AHI latch if index is already
freed to avoid the freed memory access during buf_pool_resize()
  • Loading branch information
Thirunarayanan committed Mar 3, 2021
1 parent 01b44c0 commit 4b166ca
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions storage/innobase/btr/btr0sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,24 @@ void btr_search_drop_page_hash_index(buf_block_t* block)
auto part = btr_search_sys.get_part(index_id,
block->page.id().space());

rw_lock_s_lock(&part->latch);
dict_index_t* index = block->index;
bool is_freed = index && index->freed();

if (is_freed) {
rw_lock_x_lock(&part->latch);
} else {
rw_lock_s_lock(&part->latch);
}

assert_block_ahi_valid(block);

dict_index_t* index = block->index;

if (!index || !btr_search_enabled) {
rw_lock_s_unlock(&part->latch);
if (is_freed) {
rw_lock_x_unlock(&part->latch);
} else {
rw_lock_s_unlock(&part->latch);
}
return;
}

Expand All @@ -1304,7 +1315,9 @@ void btr_search_drop_page_hash_index(buf_block_t* block)
/* NOTE: The AHI fields of block must not be accessed after
releasing search latch, as the index page might only be s-latched! */

rw_lock_s_unlock(&part->latch);
if (!is_freed) {
rw_lock_s_unlock(&part->latch);
}

ut_a(n_fields > 0 || n_bytes > 0);

Expand Down Expand Up @@ -1355,16 +1368,18 @@ void btr_search_drop_page_hash_index(buf_block_t* block)
mem_heap_free(heap);
}

rw_lock_x_lock(&part->latch);
if (!is_freed) {
rw_lock_x_lock(&part->latch);

if (UNIV_UNLIKELY(!block->index)) {
/* Someone else has meanwhile dropped the hash index */
if (UNIV_UNLIKELY(!block->index)) {
/* Someone else has meanwhile dropped the
hash index */
goto cleanup;
}

goto cleanup;
ut_a(block->index == index);
}

ut_a(block->index == index);

if (block->curr_n_fields != n_fields
|| block->curr_n_bytes != n_bytes) {

Expand Down

0 comments on commit 4b166ca

Please sign in to comment.