Skip to content

Commit b68ae6d

Browse files
committed
Merge 10.3 into 10.4
2 parents 316847e + c7f8cfc commit b68ae6d

File tree

5 files changed

+63
-22
lines changed

5 files changed

+63
-22
lines changed

storage/innobase/btr/btr0btr.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,9 @@ void btr_page_free(dict_index_t* index, buf_block_t* block, mtr_t* mtr,
732732
bool blob)
733733
{
734734
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
735-
#ifdef BTR_CUR_HASH_ADAPT
736-
if (block->index && !block->index->freed()) {
735+
#if defined BTR_CUR_HASH_ADAPT && defined UNIV_DEBUG
736+
if (block->index
737+
&& !btr_search_check_marked_free_index(block)) {
737738
ut_ad(!blob);
738739
ut_ad(page_is_leaf(block->frame));
739740
}

storage/innobase/btr/btr0sea.cc

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,11 @@ btr_search_guess_on_hash(
10951095
index page for which we know that
10961096
block->buf_fix_count == 0 or it is an index page which
10971097
has already been removed from the buf_pool->page_hash
1098-
i.e.: it is in state BUF_BLOCK_REMOVE_HASH */
1099-
void btr_search_drop_page_hash_index(buf_block_t* block)
1098+
i.e.: it is in state BUF_BLOCK_REMOVE_HASH
1099+
@param[in] garbage_collect drop ahi only if the index is marked
1100+
as freed */
1101+
void btr_search_drop_page_hash_index(buf_block_t* block,
1102+
bool garbage_collect)
11001103
{
11011104
ulint n_fields;
11021105
ulint n_bytes;
@@ -1142,13 +1145,21 @@ void btr_search_drop_page_hash_index(buf_block_t* block)
11421145
% btr_ahi_parts;
11431146
latch = btr_search_latches[ahi_slot];
11441147

1148+
rw_lock_s_lock(latch);
1149+
11451150
dict_index_t* index = block->index;
11461151

11471152
bool is_freed = index && index->freed();
11481153
if (is_freed) {
1154+
rw_lock_s_unlock(latch);
11491155
rw_lock_x_lock(latch);
1150-
} else {
1151-
rw_lock_s_lock(latch);
1156+
if (index != block->index) {
1157+
rw_lock_x_unlock(latch);
1158+
goto retry;
1159+
}
1160+
} else if (garbage_collect) {
1161+
rw_lock_s_unlock(latch);
1162+
return;
11521163
}
11531164

11541165
assert_block_ahi_valid(block);
@@ -2213,5 +2224,22 @@ btr_search_validate()
22132224
return(true);
22142225
}
22152226

2227+
#ifdef UNIV_DEBUG
2228+
bool btr_search_check_marked_free_index(const buf_block_t *block)
2229+
{
2230+
const index_id_t index_id= btr_page_get_index_id(block->frame);
2231+
2232+
rw_lock_t *ahi_latch= btr_get_search_latch(
2233+
index_id, block->page.id.space());
2234+
2235+
rw_lock_s_lock(ahi_latch);
2236+
2237+
bool is_freed= block->index && block->index->freed();
2238+
2239+
rw_lock_s_unlock(ahi_latch);
2240+
2241+
return is_freed;
2242+
}
2243+
#endif /* UNIV_DEBUG */
22162244
#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
22172245
#endif /* BTR_CUR_HASH_ADAPT */

storage/innobase/buf/buf0buf.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,18 +3915,14 @@ static void buf_defer_drop_ahi(buf_block_t *block, mtr_memo_type_t fix_type)
39153915
/* Temporarily release our S-latch. */
39163916
rw_lock_s_unlock(&block->lock);
39173917
rw_lock_x_lock(&block->lock);
3918-
if (dict_index_t *index= block->index)
3919-
if (index->freed())
3920-
btr_search_drop_page_hash_index(block);
3918+
btr_search_drop_page_hash_index(block, true);
39213919
rw_lock_x_unlock(&block->lock);
39223920
rw_lock_s_lock(&block->lock);
39233921
break;
39243922
case MTR_MEMO_PAGE_SX_FIX:
39253923
rw_lock_sx_unlock(&block->lock);
39263924
rw_lock_x_lock(&block->lock);
3927-
if (dict_index_t *index= block->index)
3928-
if (index->freed())
3929-
btr_search_drop_page_hash_index(block);
3925+
btr_search_drop_page_hash_index(block, true);
39303926
rw_lock_x_unlock(&block->lock);
39313927
rw_lock_sx_lock(&block->lock);
39323928
break;
@@ -3973,8 +3969,7 @@ static buf_block_t* buf_page_mtr_lock(buf_block_t *block,
39733969

39743970
#ifdef BTR_CUR_HASH_ADAPT
39753971
{
3976-
dict_index_t *index= block->index;
3977-
if (index && index->freed())
3972+
if (block->index)
39783973
buf_defer_drop_ahi(block, fix_type);
39793974
}
39803975
#endif /* BTR_CUR_HASH_ADAPT */
@@ -4899,7 +4894,7 @@ buf_page_get_known_nowait(
48994894

49004895
# ifdef BTR_CUR_HASH_ADAPT
49014896
ut_ad(!block->page.file_page_was_freed
4902-
|| (block->index && block->index->freed()));
4897+
|| btr_search_check_marked_free_index(block));
49034898
# else /* BTR_CUR_HASH_ADAPT */
49044899
ut_ad(!block->page.file_page_was_freed);
49054900
# endif /* BTR_CUR_HASH_ADAPT */

storage/innobase/include/btr0sea.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ btr_search_move_or_delete_hash_entries(
9999
index page for which we know that
100100
block->buf_fix_count == 0 or it is an index page which
101101
has already been removed from the buf_pool->page_hash
102-
i.e.: it is in state BUF_BLOCK_REMOVE_HASH */
103-
void btr_search_drop_page_hash_index(buf_block_t* block);
102+
i.e.: it is in state BUF_BLOCK_REMOVE_HASH
103+
@param[in] garbage_collect drop ahi only if the index is marked
104+
as freed */
105+
void btr_search_drop_page_hash_index(buf_block_t* block,
106+
bool garbage_collect= false);
104107

105108
/** Drop possible adaptive hash index entries when a page is evicted
106109
from the buffer pool or freed in a file, or the index is being dropped.
@@ -173,16 +176,25 @@ A table is selected from an array of tables using pair of index-id, space-id.
173176
@param[in] index index handler
174177
@return hash table */
175178
static inline hash_table_t* btr_get_search_table(const dict_index_t* index);
179+
180+
#ifdef UNIV_DEBUG
181+
/** @return if the index is marked as freed */
182+
bool btr_search_check_marked_free_index(const buf_block_t *block);
183+
#endif /* UNIV_DEBUG */
184+
176185
#else /* BTR_CUR_HASH_ADAPT */
177186
# define btr_search_sys_create(size)
178187
# define btr_search_sys_free()
179-
# define btr_search_drop_page_hash_index(block)
188+
# define btr_search_drop_page_hash_index(block, garbage_collect)
180189
# define btr_search_s_lock_all(index)
181190
# define btr_search_s_unlock_all(index)
182191
# define btr_search_info_update(index, cursor)
183192
# define btr_search_move_or_delete_hash_entries(new_block, block)
184193
# define btr_search_update_hash_on_insert(cursor, ahi_latch)
185194
# define btr_search_update_hash_on_delete(cursor)
195+
#ifdef UNIV_DEBUG
196+
# define btr_search_check_marked_free_index(block)
197+
#endif /* UNIV_DEBUG */
186198
#endif /* BTR_CUR_HASH_ADAPT */
187199

188200
#ifdef BTR_CUR_ADAPT

storage/innobase/include/btr0sea.inl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ static inline bool btr_search_own_any()
158158
}
159159
#endif /* UNIV_DEBUG */
160160

161+
static inline rw_lock_t* btr_get_search_latch(
162+
index_id_t index_id, ulint space_id)
163+
{
164+
ulint ifold = ut_fold_ulint_pair(ulint(index_id), space_id);
165+
166+
return(btr_search_latches[ifold % btr_ahi_parts]);
167+
}
168+
161169
/** Get the adaptive hash search index latch for a b-tree.
162170
@param[in] index b-tree index
163171
@return latch */
@@ -167,10 +175,7 @@ static inline rw_lock_t* btr_get_search_latch(const dict_index_t* index)
167175
ut_ad(!index->table->space
168176
|| index->table->space->id == index->table->space_id);
169177

170-
ulint ifold = ut_fold_ulint_pair(ulint(index->id),
171-
index->table->space_id);
172-
173-
return(btr_search_latches[ifold % btr_ahi_parts]);
178+
return btr_get_search_latch(index->id, index->table->space_id);
174179
}
175180

176181
/** Get the hash-table based on index attributes.

0 commit comments

Comments
 (0)