Skip to content

Commit 17e0f52

Browse files
committed
MDEV-27524: Incorrect binlogs after Galera SST using rsync and mariabackup
This commit adds correct handling of binlogs for SST using rsync or mariabackup. Before this fix, binlogs were handled incorrectly - - only one (last) binary log file was transferred during SST, which then led to various failures (for example, when trying to list all events from the binary log). These bugs were long masked by flaws in the primitive binlogs handling code in the SST scripts, which causing binary logs files to be erased after transfer or not added to the binlog index on the joiner node. Now the correct transfer of all binary logs (not just the last of the binary log files) has been implemented both for the rsync (at the script level) and for the mariabackup (at the level of the main utility code). This commit also adds a new sst_max_binlogs=<n> parameter, which can be located in the [sst] section or in the [xtrabackup] section (historically, supported for mariabackup only, not for rsync), or in one of the server sections. This parameter specifies the number of binary log files to be sent to the joiner node during SST. This option is added for compatibility with old SST scripting behavior, which can be emulated by setting the sst_max_binlogs=1 (although in general this can cause problems for the reasons described above). In addition, setting the sst_max_binlogs=0 can be used to suppress the transmission of binary logs to the joiner nodes during SST (although sometimes a single file with the current binary log can still be transmitted to the joiner, even with sst_max_binlogs=0, because this sometimes necessary in modes that involve the use of GTIDs with Galera). Also, this commit ensures correct handling of paths to various innodb files and directories in the SST scripts, and fixes some problems with this that existed in mariabackup utility (which were associated with incorrect handling of the innodb_data_dir parameter in some scenarios). In addition, this commit contains the following enhancements: 1) Added tests for mtr, which check the correct work with binlogs after SST (using rsync and mariabackup); 2) Added correct handling of slashes at the end of all paths that the SST script receives as parameters; 3) Improved parsing code for --mysqld-args parameters. Now it correctly processes the sequence "--" after the name of the one-letter option; 4) Checking the secret signature during joiner authentication is made independent of presence of bash (as a unix shell) in the system and diff utility no longer needed to check certificates compliance; 5) All directories that are necessary for the correct placement of various logs are automatically created by SST scripts in advance (before running mariabackup on the joiner node); 6) Removal of old binary logs on joiner is done using the binlog index (if it exists) (not only by fixed pattern that based on the current binlog name, as before); 7) Paths for placing binary logs are correctly processed if they are set as relative paths (to the datadir); 8) SST scripts are made even more resistant to spaces in filenames (now for binlogs); 9) In case of failure, SST scripts now always end with an exit code other than zero; 10) SST script for rsync now correctly create a tar file with the binlogs, even if the paths to them (in the binlog index file) are specified as a mix of absolute and relative paths, and even if they do not match with the datadir path specified in the current configuration settings.
1 parent 571eb9d commit 17e0f52

29 files changed

+1309
-517
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ datafile_read(datafile_cur_t *cursor)
582582
Check to see if a file exists.
583583
Takes name of the file to check.
584584
@return true if file exists. */
585-
static
586585
bool
587586
file_exists(const char *filename)
588587
{
@@ -1547,13 +1546,14 @@ bool backup_start(CorruptedPages &corrupted_pages)
15471546
if (!write_galera_info(mysql_connection)) {
15481547
return(false);
15491548
}
1550-
write_current_binlog_file(mysql_connection);
15511549
}
15521550

1553-
if (opt_binlog_info == BINLOG_INFO_ON) {
1551+
bool with_binlogs = opt_binlog_info == BINLOG_INFO_ON;
15541552

1555-
lock_binlog_maybe(mysql_connection);
1556-
write_binlog_info(mysql_connection);
1553+
if (with_binlogs || opt_galera_info) {
1554+
if (!write_current_binlog_file(mysql_connection, with_binlogs)) {
1555+
return(false);
1556+
}
15571557
}
15581558

15591559
if (have_flush_engine_logs && !opt_no_lock) {
@@ -1587,15 +1587,34 @@ void backup_release()
15871587
}
15881588
}
15891589

1590+
static const char *default_buffer_pool_file = "ib_buffer_pool";
1591+
1592+
static
1593+
const char * get_buffer_pool_filename(size_t *length)
1594+
{
1595+
/* If mariabackup is run for Galera, then the file
1596+
name is changed to the default so that the receiving
1597+
node can find this file and rename it according to its
1598+
settings, otherwise we keep the original file name: */
1599+
size_t dir_length = 0;
1600+
const char *dst_name = default_buffer_pool_file;
1601+
if (!opt_galera_info) {
1602+
dir_length = dirname_length(buffer_pool_filename);
1603+
dst_name = buffer_pool_filename + dir_length;
1604+
}
1605+
if (length) {
1606+
*length=dir_length;
1607+
}
1608+
return dst_name;
1609+
}
1610+
15901611
/** Finish after backup_start() and backup_release() */
15911612
bool backup_finish()
15921613
{
15931614
/* Copy buffer pool dump or LRU dump */
15941615
if (!opt_rsync) {
15951616
if (buffer_pool_filename && file_exists(buffer_pool_filename)) {
1596-
const char *dst_name;
1597-
1598-
dst_name = trim_dotslash(buffer_pool_filename);
1617+
const char *dst_name = get_buffer_pool_filename(NULL);
15991618
copy_file(ds_data, buffer_pool_filename, dst_name, 0);
16001619
}
16011620
if (file_exists("ib_lru_dump")) {
@@ -1684,17 +1703,14 @@ ibx_copy_incremental_over_full()
16841703

16851704
/* copy buffer pool dump */
16861705
if (innobase_buffer_pool_filename) {
1687-
const char *src_name;
1688-
1689-
src_name = trim_dotslash(innobase_buffer_pool_filename);
1706+
const char *src_name = get_buffer_pool_filename(NULL);
16901707

16911708
snprintf(path, sizeof(path), "%s/%s",
16921709
xtrabackup_incremental_dir,
16931710
src_name);
16941711

16951712
if (file_exists(path)) {
1696-
copy_file(ds_data, path,
1697-
innobase_buffer_pool_filename, 0);
1713+
copy_file(ds_data, path, src_name, 0);
16981714
}
16991715
}
17001716

@@ -1929,6 +1945,14 @@ copy_back()
19291945

19301946
datadir_node_init(&node);
19311947

1948+
/* If mariabackup is run for Galera, then the file
1949+
name is changed to the default so that the receiving
1950+
node can find this file and rename it according to its
1951+
settings, otherwise we keep the original file name: */
1952+
size_t dir_length;
1953+
const char *src_buffer_pool;
1954+
src_buffer_pool = get_buffer_pool_filename(&dir_length);
1955+
19321956
while (datadir_iter_next(it, &node)) {
19331957
const char *ext_list[] = {"backup-my.cnf",
19341958
"xtrabackup_binary", "xtrabackup_binlog_info",
@@ -1991,6 +2015,11 @@ copy_back()
19912015
continue;
19922016
}
19932017

2018+
/* skip buffer pool dump */
2019+
if (!strcmp(filename, src_buffer_pool)) {
2020+
continue;
2021+
}
2022+
19942023
/* skip innodb data files */
19952024
is_ibdata_file = false;
19962025
for (Tablespace::const_iterator iter(srv_sys_space.begin()),
@@ -2013,23 +2042,18 @@ copy_back()
20132042

20142043
/* copy buffer pool dump */
20152044

2016-
if (innobase_buffer_pool_filename) {
2017-
const char *src_name;
2018-
char path[FN_REFLEN];
2019-
2020-
src_name = trim_dotslash(innobase_buffer_pool_filename);
2021-
2022-
snprintf(path, sizeof(path), "%s/%s",
2023-
mysql_data_home,
2024-
src_name);
2025-
2026-
/* could be already copied with other files
2027-
from data directory */
2028-
if (file_exists(src_name) &&
2029-
!file_exists(innobase_buffer_pool_filename)) {
2030-
copy_or_move_file(src_name,
2031-
innobase_buffer_pool_filename,
2032-
mysql_data_home, 0);
2045+
if (file_exists(src_buffer_pool)) {
2046+
char dst_dir[FN_REFLEN];
2047+
while (IS_TRAILING_SLASH(buffer_pool_filename, dir_length)) {
2048+
dir_length--;
2049+
}
2050+
memcpy(dst_dir, buffer_pool_filename, dir_length);
2051+
dst_dir[dir_length] = 0;
2052+
if (!(ret = copy_or_move_file(src_buffer_pool,
2053+
src_buffer_pool,
2054+
dst_dir, 1)))
2055+
{
2056+
goto cleanup;
20332057
}
20342058
}
20352059

extra/mariabackup/backup_copy.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ copy_file(ds_ctxt_t *datasink,
3232
const char *dst_file_path,
3333
uint thread_n);
3434

35+
/************************************************************************
36+
Check to see if a file exists.
37+
Takes name of the file to check.
38+
@return true if file exists. */
39+
bool
40+
file_exists(const char *filename);
41+
3542
/** Start --backup */
3643
bool backup_start(CorruptedPages &corrupted_pages);
3744
/** Release resources after backup_start() */

0 commit comments

Comments
 (0)