From 76acc16c5fb732f803fffcfed1594304f7ee6487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 15 Oct 2026 12:41:01 +0300 Subject: [PATCH] Allow log file extension during backup --- storage/innobase/buf/buf0flu.cc | 3 +- storage/innobase/handler/backup_innodb.cc | 59 +++++++++++++++++++++-- storage/innobase/handler/backup_innodb.h | 7 +++ storage/innobase/log/log0log.cc | 3 +- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 4c1b870c92b..c7af5e57da3 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -2033,8 +2033,7 @@ inline lsn_t log_t::write_checkpoint(lsn_t checkpoint, lsn_t end_lsn) noexcept checkpoint quickly enough. Automatically adjust innodb_log_file_size to a larger size. */ resize_target= (offset + 4095) & ~off_t{4095}; - sql_print_warning("InnoDB: Adjusting innodb_log_file_size=" - LSN_PF "k", resize_target >> 10); + innodb_backup_archive_extend(first_lsn); ut_a(os_file_set_size(get_archive_path().c_str(), log.m_file, resize_target, false)); } diff --git a/storage/innobase/handler/backup_innodb.cc b/storage/innobase/handler/backup_innodb.cc index 397110b2ce2..a7b923a3aca 100644 --- a/storage/innobase/handler/backup_innodb.cc +++ b/storage/innobase/handler/backup_innodb.cc @@ -188,8 +188,8 @@ private: }; /** the LSN at log_sys.START_OFFSET */ const lsn_t first_lsn{}; - /** the file size */ - const lsn_t file_size{}; + /** the file size; protected by innodb_backup.mutex */ + lsn_t file_size{}; /** Constructor */ tracked_log(os_file_t file, lsn_t first_lsn, lsn_t file_size) : @@ -244,6 +244,17 @@ private: /** @return whether we are copying the log in real time */ bool is_log_tracking() const noexcept { return log_dst != OS_FILE_CLOSED; } + /** @return pointer to last tracked log */ + tracked_log *log_track_last() const noexcept + { + ut_ad(is_log_tracking()); + ut_ad(tracked); + tracked_log *t= tracked; + while (tracked_log *next= t->next) + t= next; + return t; + } + /** @return reference to the pointer to the end of the tracked log list */ tracked_log *&log_track_tail() noexcept { @@ -1297,8 +1308,7 @@ public: */ ut_ad((log_sys.first_lsn <= ctx.last_lsn) == !!ctx.is_log_tracking(log_sys.log.m_file)); - ut_ad(!ctx.tracked || ctx.tracked->first_lsn >= lsn); - const bool disown{ctx.tracked && ctx.tracked->first_lsn == lsn}; + const bool disown{ctx.tracked && ctx.tracked->first_lsn <= lsn}; ut_ad(disown == !!ctx.is_log_tracking(log_sys.resize_log.m_file)); if (disown) @@ -1359,7 +1369,7 @@ public: @param lsn first_lsn of log_sys.log @param file_size size of log_sys.log */ - void archive_create(lsn_t lsn, lsn_t file_size) noexcept + ATTRIBUTE_COLD void archive_create(lsn_t lsn, lsn_t file_size) noexcept { ut_ad(log_sys.latch_have_any()); if (ctx.state == PROCESSING && @@ -1385,6 +1395,39 @@ public: } } + /** + Notify that log_sys.log was extended to log_sys.resize_target + @param lsn first_lsn of log_sys.log + */ + ATTRIBUTE_COLD void archive_extend(lsn_t lsn) noexcept + { + ut_ad(log_sys.latch_have_wr()); + const lsn_t size{log_sys.resize_target}; + + if (ctx.state == PROCESSING && +#ifdef HAVE_PMEM + !log_sys.is_mmap() && +#endif + true) + { + mutex.wr_lock(); + if (ctx.state == PROCESSING && ctx.last_lsn > lsn && + ctx.is_log_tracking()) + { + tracked_log *last{ctx.log_track_last()}; + ut_ad(last); + ut_ad(last->first_lsn == lsn); + ut_ad(last->file == log_sys.log.m_file); + ut_ad(last->file_size < size); + ut_ad(ctx.is_log_tracking(log_sys.resize_log.m_file)); + last->file_size= size; + } + mutex.wr_unlock(); + } + sql_print_warning("InnoDB: Adjusting innodb_log_file_size=" LSN_PF "k", + size >> 10); + } + /** @return whether log-tracking backup is in progress */ bool is_log_tracking() noexcept { @@ -2635,11 +2678,17 @@ bool innodb_backup_log_tracking() noexcept return innodb_backup.is_log_tracking(); } +ATTRIBUTE_COLD void innodb_backup_archive_create(lsn_t lsn, lsn_t file_size) noexcept { innodb_backup.archive_create(lsn, file_size); } +ATTRIBUTE_COLD void innodb_backup_archive_extend(lsn_t lsn) noexcept +{ + innodb_backup.archive_extend(lsn); +} + #ifdef HAVE_PMEM void innodb_backup_checkpoint_pmem() noexcept { diff --git a/storage/innobase/handler/backup_innodb.h b/storage/innobase/handler/backup_innodb.h index e8514a852b4..9a3e48a168c 100644 --- a/storage/innobase/handler/backup_innodb.h +++ b/storage/innobase/handler/backup_innodb.h @@ -69,8 +69,15 @@ bool innodb_backup_log_tracking() noexcept; @param lsn first_lsn of log_sys.log @param file_size size of log_sys.log */ +ATTRIBUTE_COLD void innodb_backup_archive_create(lsn_t lsn, lsn_t file_size) noexcept; +/** + Notify that log_sys.log was extended to log_sys.resize_target. + @param lsn first_lsn of log_sys.log +*/ +ATTRIBUTE_COLD void innodb_backup_archive_extend(lsn_t lsn) noexcept; + #ifdef HAVE_PMEM /** Complete the first checkpoint in a new memory-mapped archive log file. */ void innodb_backup_checkpoint_pmem() noexcept; diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index 05cfcc079f2..1fbd025b3a8 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -1319,8 +1319,7 @@ ATTRIBUTE_COLD void log_t::archive_new_write(const byte *buf, size_t length, checkpoint quickly enough. Automatically adjust innodb_log_file_size to a larger size. */ resize_target= (offset + 4095) & ~off_t{4095}; - sql_print_warning("InnoDB: Adjusting innodb_log_file_size=" - LSN_PF "k", resize_target >> 10); + innodb_backup_archive_extend(first_lsn + capacity()); length= size_t(offset) & 4095; if (length) log.write(offset, {field_ref_zero, 4096 - length});