diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index ad026abf64f59..101fe6b72c368 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -2294,6 +2294,12 @@ redo log capacity filled threshold. @return true if adaptive flushing is recommended. */ static bool af_needed_for_redo(lsn_t oldest_lsn) noexcept { + /* We may have oldest_lsn > log_sys.get_lsn_approx() if + log_t::write_buf() or log_t::persist() are executing concurrently + with this. In that case, age > af_lwm should hold, and + buf_flush_page_cleaner() would execute one more timed wait. (Not a + big problem.) */ + lsn_t age= log_sys.get_lsn_approx() - oldest_lsn; lsn_t af_lwm= static_cast(srv_adaptive_flushing_lwm * static_cast(log_sys.log_capacity) / 100); @@ -2355,8 +2361,10 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, ulint n_pages = 0; const lsn_t cur_lsn = log_sys.get_lsn_approx(); - ut_ad(oldest_lsn <= cur_lsn); - ulint pct_for_lsn = af_get_pct_for_lsn(cur_lsn - oldest_lsn); + /* We may have cur_lsn < oldest_lsn if + log_t::write_buf() or log_t::persist() were executing concurrently. */ + ulint pct_for_lsn = cur_lsn < oldest_lsn + ? 0 : af_get_pct_for_lsn(cur_lsn - oldest_lsn); time_t curr_time = time(nullptr); const double max_pct = srv_max_buf_pool_modified_pct; diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index 55ffbc0df996a..134bb1f756787 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -406,9 +406,10 @@ struct log_t @param encrypted whether the log is encrypted */ static void header_write(byte *buf, lsn_t lsn, bool encrypted) noexcept; - /** @return a lower bound estimate of get_lsn(), + /** @return an estimate of get_lsn(), using acquire-release ordering with write_buf() or persist(); - this is exact unless append_prepare_wait() is pending */ + an upper bound if said functions have updated only one of the fields, + a lower bound if append_prepare_wait() is pending, otherwise exact */ lsn_t get_lsn_approx() const noexcept { /* acquire-release ordering with write_buf() and persist() */