From MariaDB 10.6.1, we have improved readability for DDL (Data Definition Language) operations to make most of them atomic, and the rest crash-safe, even if the server crashes in the middle of an operation.
The design of Atomic/Crash-safe DDL (MDEV-17567) allows it to work with all storage engines.
ddl_recovery.log by default, that stores all DDL operations in progress. This is used to recover the state of the server in case of sudden crash. Before 10.6, in case of a crash, there was a small possibility that one of the following things could happen:
#sql-alter or #sql-shadow or temporary files ending with '' left. DROP TABLE over multiple tables is treated as if every DROP is a separate, atomic operation. This means that after a crash, all fully, or partly, dropped tables will be dropped and logged to the binary log. The undropped tables will be left untouched.
CREATE OR REPLACE TABLE foo is implemented as:
DROP TABLE IF EXISTS foo; CREATE TABLE foo ...
This means that if there is a crash during CREATE TABLE then the original table 'foo' will be dropped even if the new table was not created. If the table was not re-created, the binary log will contain the DROP TABLE.
DROP DATABASE is implemented as:
loop over all tables DROP TABLE table
Each DROP TABLE is atomic, but in case of a crash, things will work the same way as DROP TABLE with multiple tables.
Atomic/Crash-safe DDL works with all storage engines that either have atomic DDLs internally or are able to re-execute DROP or RENAME in case of failure.
This should be true for most storage engines. The ones that still need some work are:
The new startup option --log-ddl-recovery=path (ddl_recovery.log by default) can be used to specify the place for the DDL log file. This is mainly useful in the case when one has a filesystem on persistent memory, as there is a lot of sync on this file during DDL operations.
This file contains all DDL operations that are in progress.
At MariaDB server startup, the DDL log file is copied to a file with the same base name but with a -backup.log suffix. This is mainly done to be able to find out what went wrong if recovery fails.
If the server crashes during recovery (unlikely but possible), the recovery will continue where it was before. The recovery will retry each entry up to 3 times before giving up and proceeding with the next entry.
rollback and purge triggers for the InnoDB SYS_INDEXES table. Thanks to Atomic/Crash-safe DDL, the MariaDB server is now much more stable and reliable in unstable environments. There is still ongoing work to fix the few remaining issues mentioned above to make all DDL operations Atomic. The target for these is MariaDB 10.7.
© 2023 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/atomic-ddl/