Skip to content

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

Draft
mariadb-andrzejjarzabek wants to merge 5 commits into
MariaDB:MDEV-14992from
mariadb-andrzejjarzabek:MDEV-39092
Draft

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

Conversation

@mariadb-andrzejjarzabek
Copy link
Copy Markdown

This is an initial simple implementation which copies all the Aria files in the "end" phase of the backup. Nothing protects the copy from concurrent DDL or DML. Copying only works on MacOS (intended for refactoring to use common file copy method across engines and SQL layer).

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 22, 2026

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 on lines +108 to +119
int perform_backup() noexcept
{
if (scan_datadir())
return 1;
if (copy_databases())
return 1;
if (copy_control_file())
return 1;
if (copy_logs())
return 1;
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.

This is fundamentally incompatible with the handlerton::backup_step API. Even if you are for now copying everything in handlerton::backup_end, the internal API should be kept as compatible with handlerton::backup_step as possible: copying one file at a time. At least the copy_databases() step must be refactored so that the higher-level API is invoking something that copies one file at a time. Possibly, the copying of log files should be interleaved with that, like innodb_backup_step is doing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is a stop-gap to get something working. Eventual final implementation will require re-working the hadlerton API and Sql_cmd_backup to take into account that different subsets of files may be copied under diffefent levels of metadata lock, and also "start" and potentially even "end" may need to be split into different phases with different levels of metadata lock. Given that the stage API is written that way to support multi-threaded copy, which isn't implemented at this time, I propose to merge the change as proposed (I will fix some of the other problems you mentioned) and iteratively improve from there.

Comment thread sql/sql_backup.cc Outdated
Comment on lines +30 to +38
int copy_entire_file(int src, int dst)
{
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
}

extern "C" int copy_file(int src, int dst, off_t)
{
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
}
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.

This is adding unnecessary object code duplication. Macros would allow zero-overhead abstraction:

diff --git a/sql/sql_backup_interface.h b/sql/sql_backup_interface.h
index d781acff3d9..b7d04705985 100644
--- a/sql/sql_backup_interface.h
+++ b/sql/sql_backup_interface.h
@@ -21,6 +21,7 @@
 # include <copyfile.h>
 # define copy_file(src, dst, off) \
   fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE)
+# define copy_entire_file(src, dst) copy_file(src, dst,)
 #else
 # ifdef __cplusplus
 extern "C"
@@ -32,4 +33,15 @@ extern "C"
 @return error code (negative)
 @retval 0   on success */
 int copy_file(int src, int dst, off_t size);
+
+# ifdef __cplusplus
+extern "C"
+# endif
+/** Copy an entire file.
+@param src  source file descriptor
+@param dst  target to append src to
+@param size amount of data to be copied
+@return error code (negative)
+@retval 0   on success */
+int copy_entire_file(int src, int dst);
 #endif

Outside Windows and Apple, it does make sense to introduce a non-inline function for copy_entire_file() even though it rather small (48 bytes for AMD64). I will include this in the next update of #4817.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Would defining it as an inline function not be better then? Macros have the problem of replacing tokens lexically, so if there's any identifier in code called copy_file and this header is included, it will get messed up. The fact that it would only happen on a Mac makes this problem even worse.

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.

We have a mandatory macOS builder https://buildbot.mariadb.org/#/builders/708 that must pass in order for anything to be merged to a main branch. Hence, compilation failures should only be possible in development branches.

The benefit of defining a macro copy_file() is that the third argument will be guaranteed to be omitted from the generated code. If we had an inline function that ignores the third parameter, some unnecessary code could be emitted related to the evaluation of that parameter.

This is an initial simple implementation which copies all the Aria files
in the "end" phase of the backup. Nothing protects the copy from
concurrent DDL or DML. Copying only works on MacOS (intended for
refactoring to use common file copy method across engines and SQL
layer).
Copy non-Aria-specific files *.frm and db.opt as part of Aria backup.
Add MTR test. Copy MyISAM files in Aria plugin so that the MTR works.
Perform the end step under maximum level of backup MDL to safely copy
non-transactional Aria and MyISAM files.
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