Skip to content

Commit

Permalink
MDEV-27524: Incorrect binlogs after Galera SST using rsync and mariab…
Browse files Browse the repository at this point in the history
…ackup

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.
  • Loading branch information
sysprg committed Feb 22, 2022
1 parent 571eb9d commit 17e0f52
Show file tree
Hide file tree
Showing 29 changed files with 1,309 additions and 517 deletions.
84 changes: 54 additions & 30 deletions extra/mariabackup/backup_copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ datafile_read(datafile_cur_t *cursor)
Check to see if a file exists.
Takes name of the file to check.
@return true if file exists. */
static
bool
file_exists(const char *filename)
{
Expand Down Expand Up @@ -1547,13 +1546,14 @@ bool backup_start(CorruptedPages &corrupted_pages)
if (!write_galera_info(mysql_connection)) {
return(false);
}
write_current_binlog_file(mysql_connection);
}

if (opt_binlog_info == BINLOG_INFO_ON) {
bool with_binlogs = opt_binlog_info == BINLOG_INFO_ON;

lock_binlog_maybe(mysql_connection);
write_binlog_info(mysql_connection);
if (with_binlogs || opt_galera_info) {
if (!write_current_binlog_file(mysql_connection, with_binlogs)) {
return(false);
}
}

if (have_flush_engine_logs && !opt_no_lock) {
Expand Down Expand Up @@ -1587,15 +1587,34 @@ void backup_release()
}
}

static const char *default_buffer_pool_file = "ib_buffer_pool";

static
const char * get_buffer_pool_filename(size_t *length)
{
/* If mariabackup is run for Galera, then the file
name is changed to the default so that the receiving
node can find this file and rename it according to its
settings, otherwise we keep the original file name: */
size_t dir_length = 0;
const char *dst_name = default_buffer_pool_file;
if (!opt_galera_info) {
dir_length = dirname_length(buffer_pool_filename);
dst_name = buffer_pool_filename + dir_length;
}
if (length) {
*length=dir_length;
}
return dst_name;
}

/** Finish after backup_start() and backup_release() */
bool backup_finish()
{
/* Copy buffer pool dump or LRU dump */
if (!opt_rsync) {
if (buffer_pool_filename && file_exists(buffer_pool_filename)) {
const char *dst_name;

dst_name = trim_dotslash(buffer_pool_filename);
const char *dst_name = get_buffer_pool_filename(NULL);
copy_file(ds_data, buffer_pool_filename, dst_name, 0);
}
if (file_exists("ib_lru_dump")) {
Expand Down Expand Up @@ -1684,17 +1703,14 @@ ibx_copy_incremental_over_full()

/* copy buffer pool dump */
if (innobase_buffer_pool_filename) {
const char *src_name;

src_name = trim_dotslash(innobase_buffer_pool_filename);
const char *src_name = get_buffer_pool_filename(NULL);

snprintf(path, sizeof(path), "%s/%s",
xtrabackup_incremental_dir,
src_name);

if (file_exists(path)) {
copy_file(ds_data, path,
innobase_buffer_pool_filename, 0);
copy_file(ds_data, path, src_name, 0);
}
}

Expand Down Expand Up @@ -1929,6 +1945,14 @@ copy_back()

datadir_node_init(&node);

/* If mariabackup is run for Galera, then the file
name is changed to the default so that the receiving
node can find this file and rename it according to its
settings, otherwise we keep the original file name: */
size_t dir_length;
const char *src_buffer_pool;
src_buffer_pool = get_buffer_pool_filename(&dir_length);

while (datadir_iter_next(it, &node)) {
const char *ext_list[] = {"backup-my.cnf",
"xtrabackup_binary", "xtrabackup_binlog_info",
Expand Down Expand Up @@ -1991,6 +2015,11 @@ copy_back()
continue;
}

/* skip buffer pool dump */
if (!strcmp(filename, src_buffer_pool)) {
continue;
}

/* skip innodb data files */
is_ibdata_file = false;
for (Tablespace::const_iterator iter(srv_sys_space.begin()),
Expand All @@ -2013,23 +2042,18 @@ copy_back()

/* copy buffer pool dump */

if (innobase_buffer_pool_filename) {
const char *src_name;
char path[FN_REFLEN];

src_name = trim_dotslash(innobase_buffer_pool_filename);

snprintf(path, sizeof(path), "%s/%s",
mysql_data_home,
src_name);

/* could be already copied with other files
from data directory */
if (file_exists(src_name) &&
!file_exists(innobase_buffer_pool_filename)) {
copy_or_move_file(src_name,
innobase_buffer_pool_filename,
mysql_data_home, 0);
if (file_exists(src_buffer_pool)) {
char dst_dir[FN_REFLEN];
while (IS_TRAILING_SLASH(buffer_pool_filename, dir_length)) {
dir_length--;
}
memcpy(dst_dir, buffer_pool_filename, dir_length);
dst_dir[dir_length] = 0;
if (!(ret = copy_or_move_file(src_buffer_pool,
src_buffer_pool,
dst_dir, 1)))
{
goto cleanup;
}
}

Expand Down
7 changes: 7 additions & 0 deletions extra/mariabackup/backup_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ copy_file(ds_ctxt_t *datasink,
const char *dst_file_path,
uint thread_n);

/************************************************************************
Check to see if a file exists.
Takes name of the file to check.
@return true if file exists. */
bool
file_exists(const char *filename);

/** Start --backup */
bool backup_start(CorruptedPages &corrupted_pages);
/** Release resources after backup_start() */
Expand Down
Loading

0 comments on commit 17e0f52

Please sign in to comment.