mariadb/mysql-test/suite/mariabackup/aria_log_rotate_during_backup.test
Thirunarayanan Balathandayuthapani 360d8ffc74 MDEV-37520 Failure to detect corruption during backups of Aria table
Problem
=======
- Mariabackup tool silently produce corrupted backups of
Aria tables. Identified three issues that prevents proper
detection of page corruption:

aria_read_data(), aria_read_index() does incorrect
CRC validation after doing CRC check, allows corrupted
pages to pass undetected.

aria_read_data(), aria_read_index() couldn't handle
zero filled pages. Based on the size of
aria_pagecache_buffer_size, pages could be
in cache when backup tries to read the data from file

maria_page_crc_check(): Prevents correctly identifying
and skipping zero-filled pages.

Solution:
========
This commit resolves these critical issues to ensure
the integrity of Aria table backups.

Corrected CRC check: Updated the code in aria_read_data() to
correctly check the return value from maria_page_crc_check(),
so any CRC mismatch will now properly fail the backup and
prevent corruption.

Improved zero-page handling: The aria_read_data() and
aria_read_index() functions are now robust enough to tolerate
and correctly process zero-filled pages.

The flawed conditional check in maria_page_crc_check() has
been corrected to reliably identify zero-filled pages.
2025-08-28 16:54:19 +05:30

83 lines
2.2 KiB
Text

--source include/have_debug.inc
--source include/have_aria.inc
SHOW VARIABLES LIKE 'aria_log_file_size';
--let $MYSQLD_DATADIR= `select @@datadir`
--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup
mkdir $targetdir;
DELIMITER $$;
CREATE PROCEDURE display_aria_log_control(ctrl BLOB)
BEGIN
SELECT HEX(REVERSE(SUBSTRING(ctrl, 42, 4))) AS last_logno;
END;
$$
DELIMITER ;$$
DELIMITER $$;
CREATE PROCEDURE populate_t1()
BEGIN
FOR id IN 0..9 DO
INSERT INTO test.t1 (id, txt) VALUES (id, REPEAT(id,1024*1024));
END FOR;
END;
$$
DELIMITER ;$$
CREATE TABLE test.t1(id INT, txt LONGTEXT) ENGINE=Aria;
--echo # MYSQLD_DATADIR/aria_log_control before --backup
--let ARIA_DATADIR=$MYSQLD_DATADIR
--source include/aria_log_control_load.inc
CALL display_aria_log_control(@aria_log_control);
let $backuplog= $MYSQLTEST_VARDIR/tmp/backup.log;
--echo # Running --backup
--let after_scanning_log_files=CALL test.populate_t1
--disable_result_log
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --dbug=+d,mariabackup_events > $backuplog
--let after_scanning_log_files=
--enable_result_log
--echo # MYSQLD_DATADIR/aria_log_control after --backup
--let ARIA_DATADIR=$MYSQLD_DATADIR
--source include/aria_log_control_load.inc
CALL display_aria_log_control(@aria_log_control);
--echo # targetdir/aria_log_control after --backup
--let ARIA_DATADIR=$targetdir
--source include/aria_log_control_load.inc
CALL display_aria_log_control(@aria_log_control);
--echo # Running --prepare
--disable_result_log
--exec $XTRABACKUP --prepare --target-dir=$targetdir
--enable_result_log
--echo # targetdir/aria_log_control after --prepare
--let ARIA_DATADIR=$targetdir
--source include/aria_log_control_load.inc
CALL display_aria_log_control(@aria_log_control);
--disable_result_log
--source include/restart_and_restore.inc
--enable_result_log
--echo # MYSQLD_DATADIR/aria_log_control after --copy-back
--let ARIA_DATADIR=$MYSQLD_DATADIR
--source include/aria_log_control_load.inc
CALL display_aria_log_control(@aria_log_control);
--echo # Checking that after --restore all t1 data is there
SELECT id, LENGTH(txt) FROM t1 ORDER BY id;
DROP TABLE t1;
rmdir $targetdir;
remove_file $backuplog;
DROP PROCEDURE populate_t1;
DROP PROCEDURE display_aria_log_control;