Skip to content

Commit

Permalink
MDEV-28415 ALTER TABLE on a large table hangs InnoDB
Browse files Browse the repository at this point in the history
buf_flush_page(): Never wait for a page latch, even in checkpoint
flushing (flush_type == BUF_FLUSH_LIST), to prevent a hang of the
page cleaner threads when a large number of pages is latched.

In mysql/mysql-server@9542f30
it was claimed that such a hang only affects CREATE FULLTEXT INDEX.
Their fix was to retain buffer-fix but release exclusive latch
on non-leaf pages, and subsequently write to those pages while
they are not associated with the mini-transaction, which would
trip a debug assertion in the MariaDB version of
mtr_t::memo_modify_page() and cause potential corruption
when using the default MariaDB setting innodb_log_optimize_ddl=OFF.

This change essentially backports a small part of
commit 7cffb5f (MDEV-23399)
from MariaDB Server 10.5.7.
  • Loading branch information
dr-m committed Apr 27, 2022
1 parent 3999013 commit f21a875
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions storage/innobase/buf/buf0flu.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2020, MariaDB Corporation.
Copyright (c) 2013, 2022, MariaDB Corporation.
Copyright (c) 2013, 2014, Fusion-io
This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -1160,15 +1160,10 @@ buf_flush_page(
/* For table residing in temporary tablespace sync is done
using IO_FIX and so before scheduling for flush ensure that
page is not fixed. */
flush = FALSE;
return FALSE;
} else {
rw_lock = &reinterpret_cast<buf_block_t*>(bpage)->lock;
if (flush_type != BUF_FLUSH_LIST) {
flush = rw_lock_sx_lock_nowait(rw_lock, BUF_IO_WRITE);
} else {
/* Will SX lock later */
flush = TRUE;
}
flush = rw_lock_sx_lock_nowait(rw_lock, BUF_IO_WRITE);
}

if (flush) {
Expand All @@ -1190,22 +1185,6 @@ buf_flush_page(

buf_pool_mutex_exit(buf_pool);

if (flush_type == BUF_FLUSH_LIST
&& is_uncompressed
&& !rw_lock_sx_lock_nowait(rw_lock, BUF_IO_WRITE)) {

if (!fsp_is_system_temporary(bpage->id.space())) {
/* avoiding deadlock possibility involves
doublewrite buffer, should flush it, because
it might hold the another block->lock. */
buf_dblwr_flush_buffered_writes();
} else {
buf_dblwr_sync_datafiles();
}

rw_lock_sx_lock_gen(rw_lock, BUF_IO_WRITE);
}

/* If there is an observer that want to know if the asynchronous
flushing was sent then notify it.
Note: we set flush observer to a page with x-latch, so we can
Expand Down

0 comments on commit f21a875

Please sign in to comment.