Commit 0e11d96a authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17441: Pointer indirection for buf_block_t::debug_latch

This is a follow-up to commit 9581c4a8
which added a memcpy() call to rtr_copy_buf(), to copy
rw_lock_t debug_latch. This could emit a warning.

A cleaner approach is to make buf_block_t::debug_latch a pointer,
so that we can avoid copying it. An even cleaner approach would be to
redesign the InnoDB SPATIAL INDEX code so that the function
rtr_copy_buf() is not needed at all.
parent aa4e8dfd
......@@ -1396,7 +1396,7 @@ pfs_register_buffer_block(
: NULL;
# ifdef UNIV_DEBUG
rwlock = &block->debug_latch;
rwlock = block->debug_latch;
ut_a(!rwlock->pfs_psi);
rwlock->pfs_psi = (PSI_server)
? PSI_server->init_rwlock(buf_block_debug_latch_key,
......@@ -1458,6 +1458,7 @@ buf_block_init(
page_zip_des_init(&block->page.zip);
mutex_create(LATCH_ID_BUF_BLOCK_MUTEX, &block->mutex);
ut_d(block->debug_latch = UT_NEW_NOKEY(rw_lock_t()));
#if defined PFS_SKIP_BUFFER_MUTEX_RWLOCK || defined PFS_GROUP_BUFFER_SYNC
/* If PFS_SKIP_BUFFER_MUTEX_RWLOCK is defined, skip registration
......@@ -1469,7 +1470,7 @@ buf_block_init(
rw_lock_create(PFS_NOT_INSTRUMENTED, &block->lock, SYNC_LEVEL_VARYING);
ut_d(rw_lock_create(PFS_NOT_INSTRUMENTED, &block->debug_latch,
ut_d(rw_lock_create(PFS_NOT_INSTRUMENTED, block->debug_latch,
SYNC_LEVEL_VARYING));
#else /* PFS_SKIP_BUFFER_MUTEX_RWLOCK || PFS_GROUP_BUFFER_SYNC */
......@@ -1477,7 +1478,7 @@ buf_block_init(
rw_lock_create(buf_block_lock_key, &block->lock, SYNC_LEVEL_VARYING);
ut_d(rw_lock_create(buf_block_debug_latch_key,
&block->debug_latch, SYNC_LEVEL_VARYING));
block->debug_latch, SYNC_LEVEL_VARYING));
#endif /* PFS_SKIP_BUFFER_MUTEX_RWLOCK || PFS_GROUP_BUFFER_SYNC */
......@@ -1736,6 +1737,18 @@ buf_pool_set_sizes(void)
buf_pool_mutex_exit_all();
}
/** Free the synchronization objects of a buffer pool block descriptor
@param[in,out] block buffer pool block descriptor */
static void buf_block_free_mutexes(buf_block_t* block)
{
mutex_free(&block->mutex);
rw_lock_free(&block->lock);
ut_d(rw_lock_free(block->debug_latch));
ut_ad(!block->debug_latch->magic_n);
ut_d(block->debug_latch->magic_n = RW_LOCK_MAGIC_N);
ut_d(UT_DELETE(block->debug_latch));
}
/********************************************************************//**
Initialize a buffer pool instance.
@return DB_SUCCESS if all goes well. */
......@@ -1799,11 +1812,7 @@ buf_pool_init_instance(
buf_block_t* block = chunk->blocks;
for (i = chunk->size; i--; block++) {
mutex_free(&block->mutex);
rw_lock_free(&block->lock);
ut_d(rw_lock_free(
&block->debug_latch));
buf_block_free_mutexes(block);
}
buf_pool->allocator.deallocate_large(
......@@ -1949,10 +1958,7 @@ buf_pool_free_instance(
buf_block_t* block = chunk->blocks;
for (ulint i = chunk->size; i--; block++) {
mutex_free(&block->mutex);
rw_lock_free(&block->lock);
ut_d(rw_lock_free(&block->debug_latch));
buf_block_free_mutexes(block);
}
buf_pool->allocator.deallocate_large(
......@@ -2826,11 +2832,7 @@ buf_pool_resize()
for (ulint j = chunk->size;
j--; block++) {
mutex_free(&block->mutex);
rw_lock_free(&block->lock);
ut_d(rw_lock_free(
&block->debug_latch));
buf_block_free_mutexes(block);
}
buf_pool->allocator.deallocate_large(
......@@ -4750,7 +4752,7 @@ buf_page_get_gen(
if (!fsp_is_system_temporary(page_id.space())) {
ibool ret;
ret = rw_lock_s_lock_nowait(
&fix_block->debug_latch, file, line);
fix_block->debug_latch, file, line);
ut_a(ret);
}
#endif /* UNIV_DEBUG */
......
......@@ -1567,8 +1567,7 @@ rtr_copy_buf(
matches->block.curr_left_side = block->curr_left_side;
matches->block.index = block->index;
#endif /* BTR_CUR_HASH_ADAPT */
ut_d(memcpy(&matches->block.debug_latch, &block->debug_latch,
sizeof(rw_lock_t)));
ut_d(matches->block.debug_latch = NULL);
}
/****************************************************************//**
......
......@@ -1797,7 +1797,7 @@ struct buf_block_t{
# ifdef UNIV_DEBUG
/** @name Debug fields */
/* @{ */
rw_lock_t debug_latch; /*!< in the debug version, each thread
rw_lock_t* debug_latch; /*!< in the debug version, each thread
which bufferfixes the block acquires
an s-latch here; so we can use the
debug utilities in sync0rw */
......
......@@ -985,7 +985,7 @@ buf_block_buf_fix_inc_func(
threaded. */
if (!fsp_is_system_temporary(block->page.id.space())) {
ibool ret;
ret = rw_lock_s_lock_nowait(&block->debug_latch, file, line);
ret = rw_lock_s_lock_nowait(block->debug_latch, file, line);
ut_a(ret);
}
#endif /* UNIV_DEBUG */
......@@ -1033,7 +1033,7 @@ buf_block_buf_fix_dec(
Debug latch is not of much help if access to block is single
threaded. */
if (!fsp_is_system_temporary(block->page.id.space())) {
rw_lock_s_unlock(&block->debug_latch);
rw_lock_s_unlock(block->debug_latch);
}
#endif /* UNIV_DEBUG */
}
......@@ -1276,7 +1276,7 @@ buf_page_release_zip(
is single threaded. */
buf_block_t* block = reinterpret_cast<buf_block_t*>(bpage);
if (!fsp_is_system_temporary(block->page.id.space())) {
rw_lock_s_unlock(&block->debug_latch);
rw_lock_s_unlock(block->debug_latch);
}
}
#endif /* UNIV_DEBUG */
......@@ -1312,7 +1312,7 @@ buf_page_release_latch(
temporary. Debug latch is not of much help if access to block
is single threaded. */
if (!fsp_is_system_temporary(block->page.id.space())) {
rw_lock_s_unlock(&block->debug_latch);
rw_lock_s_unlock(block->debug_latch);
}
#endif /* UNIV_DEBUG */
......
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