@@ -3358,7 +3358,7 @@ bool buf_is_block_in_instance(const buf_pool_t *buf_pool,
3358
3358
static bool buf_debug_execute_is_force_flush () {
3359
3359
DBUG_EXECUTE_IF (" ib_buf_force_flush" , return (true ););
3360
3360
3361
- /* This is used during queisce testing, we want to ensure maximum
3361
+ /* This is used during quiesce testing, we want to ensure maximum
3362
3362
buffering by the change buffer. */
3363
3363
3364
3364
if (srv_ibuf_disable_background_merge) {
@@ -3373,29 +3373,19 @@ static bool buf_debug_execute_is_force_flush() {
3373
3373
@param[in] block The block to check */
3374
3374
static void buf_wait_for_read (buf_block_t *block) {
3375
3375
/* 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 );
3399
3389
}
3400
3390
}
3401
3391
0 commit comments