Skip to content

Commit fd39c63

Browse files
committed
MDEV-37520 Failure to detect corruption during backups of Aria table
Fixed the following issues: - aria_read_index() and aria_read_data(), used by mariabackup, checked the wrong status from maria_page_crc_check(). - Both functions did infinite retries if crc did not match. - Wrong usage of ma_check_if_zero() in maria_page_crc_check() Author: Thirunarayanan Balathandayuthapani <thiru@mariadb.com>
1 parent 5a35fff commit fd39c63

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

extra/mariabackup/aria_backup_client.cc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -399,21 +399,19 @@ bool Table::copy(ds_ctxt_t *ds, bool is_index, unsigned thread_num) {
399399

400400
for (ulonglong block= 0 ; ; block++) {
401401
size_t length = m_cap.block_size;
402-
if (is_index) {
403-
if ((error= aria_read_index(
404-
partition.m_index_file, &m_cap, block, copy_buffer) ==
405-
HA_ERR_END_OF_FILE))
406-
break;
407-
} else {
408-
if ((error= aria_read_data(
409-
partition.m_data_file, &m_cap, block, copy_buffer, &length) ==
410-
HA_ERR_END_OF_FILE))
411-
break;
412-
}
413-
if (error) {
414-
msg(thread_num, "error: aria_read %s failed: %d",
415-
is_index ? "index" : "data", error);
416-
goto err;
402+
if (is_index)
403+
error= aria_read_index(partition.m_index_file, &m_cap,
404+
block, copy_buffer);
405+
else
406+
error= aria_read_data(partition.m_data_file, &m_cap,
407+
block, copy_buffer, &length);
408+
if (error)
409+
{
410+
if (error == HA_ERR_END_OF_FILE)
411+
break;
412+
msg(thread_num, "error: aria_read %s failed: %d",
413+
is_index ? "index" : "data", error);
414+
goto err;
417415
}
418416
xtrabackup_io_throttling();
419417
if ((error = ds_write(dst_file, copy_buffer, length))) {

mysql-test/suite/mariabackup/aria_log_rotate_during_backup.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ CREATE TABLE test.t1(id INT, txt LONGTEXT) ENGINE=Aria;
3434
--source include/aria_log_control_load.inc
3535
CALL display_aria_log_control(@aria_log_control);
3636

37-
37+
let $backuplog= $MYSQLTEST_VARDIR/tmp/backup.log;
3838
--echo # Running --backup
3939
--let after_scanning_log_files=CALL test.populate_t1
4040
--disable_result_log
41-
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --parallel=10 --target-dir=$targetdir --dbug=+d,mariabackup_events 2>&1
41+
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --dbug=+d,mariabackup_events > $backuplog
4242
--let after_scanning_log_files=
4343
--enable_result_log
4444

@@ -77,6 +77,7 @@ CALL display_aria_log_control(@aria_log_control);
7777
SELECT id, LENGTH(txt) FROM t1 ORDER BY id;
7878
DROP TABLE t1;
7979
rmdir $targetdir;
80+
remove_file $backuplog;
8081

8182
DROP PROCEDURE populate_t1;
8283
DROP PROCEDURE display_aria_log_control;

storage/maria/ma_backup.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ int aria_read_index(File kfile, ARIA_TABLE_CAPABILITIES *cap, ulonglong block,
202202
error= maria_page_crc_check(buffer, block, &share,
203203
MARIA_NO_CRC_NORMAL_PAGE,
204204
(int) length);
205-
if (error != HA_ERR_WRONG_CRC)
205+
if (error == 0 || my_errno != HA_ERR_WRONG_CRC)
206206
DBUG_RETURN(error);
207207
}
208208
my_sleep(100000); /* Sleep 0.1 seconds */
209-
} while (retry < MAX_RETRY);
209+
} while (retry++ < MAX_RETRY);
210210
DBUG_RETURN(HA_ERR_WRONG_CRC);
211211
}
212212

@@ -264,15 +264,18 @@ int aria_read_data(File dfile, ARIA_TABLE_CAPABILITIES *cap, ulonglong block,
264264

265265
if (length == cap->block_size)
266266
{
267-
error= maria_page_crc_check(buffer, block, &share,
267+
if (!_ma_check_if_zero(buffer, share.block_size - CRC_SIZE))
268+
error= 0;
269+
else
270+
error= maria_page_crc_check(buffer, block, &share,
268271
((block % cap->bitmap_pages_covered) == 0 ?
269272
MARIA_NO_CRC_BITMAP_PAGE :
270273
MARIA_NO_CRC_NORMAL_PAGE),
271274
share.block_size - CRC_SIZE);
272-
if (error != HA_ERR_WRONG_CRC)
275+
if (error == 0 || my_errno != HA_ERR_WRONG_CRC)
273276
DBUG_RETURN(error);
274277
}
275278
my_sleep(100000); /* Sleep 0.1 seconds */
276-
} while (retry < MAX_RETRY);
279+
} while (retry++ < MAX_RETRY);
277280
DBUG_RETURN(HA_ERR_WRONG_CRC);
278281
}

storage/maria/ma_pagecrc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ my_bool maria_page_crc_check(uchar *page,
103103
the CRC will be corrected at next write)
104104
*/
105105
if (no_crc_val == MARIA_NO_CRC_BITMAP_PAGE &&
106-
crc == 0 && _ma_check_if_zero(page, data_length))
106+
crc == 0 && !_ma_check_if_zero(page, data_length))
107107
{
108108
DBUG_PRINT("warning", ("Found bitmap page that was not initialized"));
109109
DBUG_RETURN(0);

0 commit comments

Comments
 (0)