Skip to content

MDEV-39092 Copy Aria data and logs as part of backup#4971

Open
mariadb-andrzejjarzabek wants to merge 19 commits into
MariaDB:MDEV-14992from
mariadb-andrzejjarzabek:MDEV-39092
Open

MDEV-39092 Copy Aria data and logs as part of backup#4971
mariadb-andrzejjarzabek wants to merge 19 commits into
MariaDB:MDEV-14992from
mariadb-andrzejjarzabek:MDEV-39092

Conversation

@mariadb-andrzejjarzabek

@mariadb-andrzejjarzabek mariadb-andrzejjarzabek commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

An interim solution with some room for optimization:

  • All DDL is blcoked while Aria is being backed up
  • All table caches purged when Aria backup starts (including for non-Aria tables)
  • Writes to non-transactional, but not to transactional tables are blocked when table files are being backed up
  • All commits blocked when Aria log files are being backed up

@CLAassistant

CLAassistant commented Apr 22, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread include/my_backup.h Outdated
Comment thread include/my_backup.h Outdated
Comment thread include/my_backup.h Outdated
Comment thread mysys/CMakeLists.txt Outdated
Comment thread mysys/my_backup.cc Outdated
Comment thread sql/handler.h Outdated
Comment thread sql/sql_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread sql/sql_backup.cc Outdated
@mariadb-andrzejjarzabek mariadb-andrzejjarzabek force-pushed the MDEV-39092 branch 2 times, most recently from 8565956 to 04e3bc2 Compare May 21, 2026 10:53
@mariadb-andrzejjarzabek mariadb-andrzejjarzabek force-pushed the MDEV-39092 branch 2 times, most recently from 14ca552 to c9429eb Compare May 29, 2026 09:47
@mariadb-andrzejjarzabek mariadb-andrzejjarzabek force-pushed the MDEV-39092 branch 2 times, most recently from d35cd47 to 824afeb Compare June 1, 2026 15:15
@mariadb-andrzejjarzabek mariadb-andrzejjarzabek marked this pull request as ready for review June 1, 2026 15:16
@mariadb-andrzejjarzabek mariadb-andrzejjarzabek marked this pull request as draft June 1, 2026 15:17
dr-m added 2 commits June 8, 2026 12:31
This introduces a basic driver Sql_cmd_backup, storage engine interfaces,
and basic copying of InnoDB data files.
On Windows, we pass a target directory name; elsewhere, we pass a
target directory handle.

backup_target: A structured data type to represent a directory or a
stream. On Microsoft Windows, we must use directory paths because
there is no variant of CopyFileEx() that would work on file handles.

copy_entire_file(): A file copying service for POSIX systems.

copy_file(): A sparse file-copying service for all systems.

backup_context: An InnoDB backup context, attached to trx->lock.backup
so that context can exist between InnoDB_backup::end(), which is
releasing all locks, and InnoDB_backup::fini() in the same thread,
which is expected to finalize the backup without modifying files
in the server data directory.

fil_space_t::write_or_backup: Keep track of in-flight page writes and
pending backup operation. We must not allow them concurrently, because
that could lead into torn pages in the backup.

fil_space_t::backup_end: The first page number that is not being backed up
(by default 0, to indicate that no backup is in progress).

fil_space_t::BACKUP_BATCH_SIZE: The number of preceding pages that will be
covered by fil_space_t::backup_end. This is the unit of "page range locking"
during InnoDB backup.

TRX_STATE_BACKUP: A special InnoDB transaction state indicating association
with BACKUP SERVER, which allows us to pass some context in trx_t from
innodb_backup_end() to innodb_backup_finalize().

log_t::backup: Whether BACKUP SERVER is in progress. The purpose of this
is to make BACKUP SERVER prevent the concurrent execution of
SET GLOBAL innodb_log_archive=OFF or SET GLOBAL innodb_log_file_size
when innodb_log_archive=OFF.

log_sys.archived_checkpoint: Keep track of the earliest available
checkpoint, corresponding to log_sys.archived_lsn. This reflects
SET GLOBAL innodb_log_recovery_start (which is settable now), for
incremental backup.

buf_flush_list_space(): Check for concurrent backup before writing each
page. This is inefficient, but this function may be invoked from multiple
threads concurrently, and it cannot be changed easily, especially for
fil_crypt_thread().
Comment thread sql/handler.h Outdated
Comment thread sql/handler.h Outdated
Comment thread sql/sql_backup.cc Outdated
Comment on lines 217 to 220
backup_target target;
#ifndef _WIN32
const int datadir_fd;
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a declaration of datadir_fd in the first place? It turns out that it is never being assigned, only passed to openat(2). This seems to rely on zero-initialization and some undefined behaviour. For example, in Linux, AT_FDCWD is defined as -100.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed later that this data member is being initialized from a call to open(…, O_DIRECTORY) in the constructor. I think that this is bad practice; we should allow the singleton object to be initialized statically.

It is unclear when if ever the directory handle would be closed. I suspect that we would hold the handle open until the server is shut down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datadir_fd is initialized in the Aria_backup constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a reasonable trade-off to have a descriptor permanently opened for backups for the purpose of just one plugin? Should each plugin that performs the backup keep an open descriptor to the data directory? When adding another bit of functionality (not backup) to any part of the server or a plugin, with its own class/module/translation unit, which needs to open files in the data directory, should it also maintain a file descriptor to the data directory? There may be a case for defining an API for the server to maintain a single descriptor and make it available for other code, but given that there isn't one, I would argue that opening a descriptor for the duration of the backup and closing it on backup end. A backup isn't a fine-grained operation which we expect to be performed multiple times per second (or even minute), but we expect that many hours may pass between successive backups. And every backup will typically open hundreds or thousands of files, so saving the time and I/O of one open/close is not significant and it's not clear that maintaining an additional open descriptor the whole time the server is running is is balanced out by that.

In any case I propose putting that discussion off for a possible future improvement, where we could discuss defining an API to make a data directory descriptor available to the whole server.

Comment thread storage/maria/ma_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread storage/maria/ma_backup.cc Outdated
Comment thread mysql-test/main/backup_server_restore.result Outdated
dr-m added 7 commits June 9, 2026 11:19
Simplify the backup_target
backup_config_append(): C compatible API
MDEV-39101: BACKUP STAGE compatible locking

handlerton::backup_end: Includes backup_finalize
This reverts commit 75ff32f.
Comment on lines +621 to +625
case BACKUP_PHASE_NO_DML_NON_TRANS:
/* FIXME: Would be better to selectively purge only the tables we need. */
tc_purge();
tdc_purge(true);
return 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is missing a reference to a ticket where this performance problem will be fixed. As far as I understand, we only need such cleanup for ENGINE=Aria and ENGINE=MyISAM. We don’t want unnecessary disruption of ENGINE=InnoDB. The BACKUP_PHASE_NO_COMMIT that will be executed a couple of steps after this one will be disruptive enough.

@mariadb-andrzejjarzabek mariadb-andrzejjarzabek marked this pull request as ready for review June 17, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants