Skip to content

Commit 29a5829

Browse files
MDEV-22901 Accessing btr_search_sys->hash_tables when buffer pool resize happens
- btr_get_search_table() is accessing btr_search_sys->hash_tables, which is not safe if the buffer pool resize happens concurrently.
1 parent 32b34cb commit 29a5829

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

storage/innobase/btr/btr0sea.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,20 +1485,12 @@ btr_search_build_page_hash_index(
14851485

14861486
btr_search_check_free_space_in_heap(index);
14871487

1488-
hash_table_t* table = btr_get_search_table(index);
14891488
rw_lock_x_lock(ahi_latch);
14901489

14911490
if (!btr_search_enabled) {
14921491
goto exit_func;
14931492
}
14941493

1495-
table = btr_get_search_table(index);
1496-
if (block->index && ((block->curr_n_fields != n_fields)
1497-
|| (block->curr_n_bytes != n_bytes)
1498-
|| (block->curr_left_side != left_side))) {
1499-
goto exit_func;
1500-
}
1501-
15021494
/* This counter is decremented every time we drop page
15031495
hash index entries and is incremented here. Since we can
15041496
rebuild hash index for a page that is already hashed, we
@@ -1507,6 +1499,10 @@ btr_search_build_page_hash_index(
15071499
if (!block->index) {
15081500
assert_block_ahi_empty(block);
15091501
index->search_info->ref_count++;
1502+
} else if (block->curr_n_fields != n_fields
1503+
|| block->curr_n_bytes != n_bytes
1504+
|| block->curr_left_side != left_side) {
1505+
goto exit_func;
15101506
}
15111507

15121508
block->n_hash_helps = 0;
@@ -1516,9 +1512,11 @@ btr_search_build_page_hash_index(
15161512
block->curr_left_side = unsigned(left_side);
15171513
block->index = index;
15181514

1519-
for (i = 0; i < n_cached; i++) {
1520-
1521-
ha_insert_for_fold(table, folds[i], block, recs[i]);
1515+
{
1516+
hash_table_t* table = btr_get_search_table(index);
1517+
for (i = 0; i < n_cached; i++) {
1518+
ha_insert_for_fold(table, folds[i], block, recs[i]);
1519+
}
15221520
}
15231521

15241522
MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED);

0 commit comments

Comments
 (0)