Skip to content

Commit 0c015c2

Browse files
author
Marcin Babij
committed
Merge branch 'mysql-8.0' into mysql-trunk
2 parents 6eb6c61 + 4894770 commit 0c015c2

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

storage/innobase/buf/buf0buf.cc

+14-24
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ bool buf_is_block_in_instance(const buf_pool_t *buf_pool,
33583358
static bool buf_debug_execute_is_force_flush() {
33593359
DBUG_EXECUTE_IF("ib_buf_force_flush", return (true););
33603360

3361-
/* This is used during queisce testing, we want to ensure maximum
3361+
/* This is used during quiesce testing, we want to ensure maximum
33623362
buffering by the change buffer. */
33633363

33643364
if (srv_ibuf_disable_background_merge) {
@@ -3373,29 +3373,19 @@ static bool buf_debug_execute_is_force_flush() {
33733373
@param[in] block The block to check */
33743374
static void buf_wait_for_read(buf_block_t *block) {
33753375
/* Note:
3376-
3377-
We are using the block->lock to check for IO state (and a dirty read).
3378-
We set the IO_READ state under the protection of the hash_lock
3379-
(and block->mutex). This is safe because another thread can only
3380-
access the block (and check for IO state) after the block has been
3381-
added to the page hashtable. */
3382-
3383-
if (buf_block_get_io_fix_unlocked(block) == BUF_IO_READ) {
3384-
/* Wait until the read operation completes */
3385-
for (;;) {
3386-
if (buf_block_get_io_fix_unlocked(block) == BUF_IO_READ) {
3387-
/* Wait by temporaly s-latch */
3388-
if (rw_lock_s_lock_low(&block->lock, 0, __FILE__, __LINE__)) {
3389-
rw_lock_s_unlock(&block->lock);
3390-
} else {
3391-
/* If we can't acquire the latch in S mode then the IO thread
3392-
must have read the page in. */
3393-
os_thread_sleep(20);
3394-
}
3395-
} else {
3396-
break;
3397-
}
3398-
}
3376+
This unlocked read of IO fix is safe as we have the block buf-fixed. The page
3377+
can only transition away from the IO_READ state, and once this is done, it
3378+
will not be IO_READ again as long as we have it buf-fixed.
3379+
3380+
The read of the io fix will not be optimized out in this loop, as rw_lock
3381+
result in a memory barrier, which causes compiler to be
3382+
unable to do so.*/
3383+
while (buf_block_get_io_fix_unlocked(block) == BUF_IO_READ) {
3384+
/* Page is X-latched on block->lock until the read is completed.
3385+
Let's just wait for S-lock on block->lock, it will be granted as soon as the
3386+
read completes. */
3387+
rw_lock_s_lock(&block->lock);
3388+
rw_lock_s_unlock(&block->lock);
33993389
}
34003390
}
34013391

0 commit comments

Comments
 (0)