mariadb/extra/mariabackup
Marko Mäkelä 14d9323f60 MDEV-37994 Race condition between checkpoint and .ibd file creation
It was possible that a log checkpoint was completed and the server killed
between the time that fil_ibd_create() durably wrote a FILE_CREATE record,
and the initialization of the tablespace. This could lead to a failure
to start up after the server was killed during TRUNCATE TABLE or any
table-rebuilding operation such as OPTIMIZE TABLE.

In the case of TRUNCATE TABLE, an attempt to rename a file #sql-ibNNN.ibd
(the contents of the table before truncation) to tablename.ibd would fail,
because both files existed and the file tablename.ibd would have been
filled with NUL bytes. It was possible to resume from this error by
deleting the file tablename.ibd and restarting the server.

We will prevent this class of errors by ensuring that both the FILE_CREATE
record and the records written by fsp_header_init() will be part of the
same atomic transaction, which must be durably written before any file
is created or allocated.

NOTE: There is another possible crash recovery problem, which we are not
attempting to solve here and which will be covered by the subsequent
change (MDEV-38026). If fil_ibd_create() fails to create the file and
the server were killed, recovery would not even attempt to create the file
at all.

fil_space_t::create(): Remove the DBUG_EXECUTE_IF fault injection that
was the only cause of return nullptr. This allows us to simplify
several callers.

fil_space_t::set_stopped(), fil_space_t::clear_stopped(): Accessor
functions for fil_ibd_create() for preventing any concurrent access
to an incompletely created tablespace.

fil_ibd_create(): In a single atomic mini-transaction, write the
FILE_CREATE record as well as the log for initializing the tablespace.
After durably writing the log, create the file in the file system
Only after the file has been successfully created and allocated,
open the tablespace for business. Finally, release the exclusive page
latches so that the header pages may be written to the file.

fil_ibd_open(): Move some fault injection from fil_space_t::create()
to a higher level, to the place where an existing file is being opened.

Reviewed by: Thirunarayanan Balathandayuthapani
Tested by: Saahil Alam
2025-11-07 08:06:27 +02:00
..
quicklz
backup_copy.cc MDEV-22250 InnoDB: Failing assertion: opt_no_lock during mariabackup --backup 2025-07-14 16:30:06 +03:00
backup_copy.h MDEV-22250 InnoDB: Failing assertion: opt_no_lock during mariabackup --backup 2025-07-14 16:30:06 +03:00
backup_debug.h MDEV-25312 Replace fil_space_t::name with fil_space_t::name() 2021-04-07 18:01:13 +03:00
backup_mysql.cc Merge 10.5 into 10.6 2025-01-08 08:48:21 +02:00
backup_mysql.h Cleanup: Remove changed_pages_bitmap 2024-02-12 17:01:35 +02:00
backup_wsrep.h Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
CMakeLists.txt MDEV-33091 pcre2 headers aren't found on Solaris 2024-09-05 12:14:06 +10:00
common.h Fix a case of unused-but-set-variable 2024-02-13 14:00:26 +11:00
datasink.cc Merge 10.2 into 10.3 2021-09-22 18:01:41 +03:00
datasink.h MDEV-31039 mariadb-backup: remove global variables ds_data and ds_meta 2023-04-12 15:14:03 +04:00
ds_buffer.cc Merge 10.4 into 10.5 2021-04-14 11:35:39 +03:00
ds_buffer.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ds_compress.cc Merge 10.4 into 10.5 2022-08-22 13:38:40 +03:00
ds_compress.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ds_local.cc Merge branch '10.4' into 10.5 2023-11-08 12:59:00 +01:00
ds_local.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ds_stdout.cc MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
ds_stdout.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ds_tmpfile.cc Merge 10.4 into 10.5 2021-04-14 11:35:39 +03:00
ds_tmpfile.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ds_xbstream.cc Merge 10.4 into 10.5 2021-09-24 08:42:23 +03:00
ds_xbstream.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
encryption_plugin.cc heap-buffer-overflow in mariadb-backup 2025-01-09 10:00:36 +01:00
encryption_plugin.h
fil_cur.cc MDEV-34388: Stack overflow on Alpine Linux 2025-05-20 17:27:05 +03:00
fil_cur.h MDEV-34388: Stack overflow on Alpine Linux 2025-05-20 17:27:05 +03:00
innobackupex.cc Merge branch '10.4' into 10.5 2021-07-31 23:19:51 +02:00
innobackupex.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
read_filt.cc Cleanup: Remove changed_pages_bitmap 2024-02-12 17:01:35 +02:00
read_filt.h Cleanup: Remove changed_pages_bitmap 2024-02-12 17:01:35 +02:00
write_filt.cc Merge branch '10.4' into 10.5 2023-04-24 12:43:47 +02:00
write_filt.h MDEV-31039 mariadb-backup: remove global variables ds_data and ds_meta 2023-04-12 15:14:03 +04:00
wsrep.cc MDEV-31905 GTID inconsistency 2023-12-22 00:10:23 +01:00
xb_regex.h MDEV-14024 PCRE2. 2019-12-21 10:34:02 +01:00
xbcloud.cc Fix few vulnerabilities found by Cppcheck 2023-03-02 14:38:24 +11:00
xbstream.cc MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
xbstream.h Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
xbstream_read.cc MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
xbstream_write.cc MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
xtrabackup.cc MDEV-37994 Race condition between checkpoint and .ibd file creation 2025-11-07 08:06:27 +02:00
xtrabackup.h Merge 10.5 into 10.6 2024-02-13 20:42:59 +02:00