Skip to content

Commit

Permalink
Restore getting InnoDB position from mariabackup --no-lock
Browse files Browse the repository at this point in the history
Revert the patch for MDEV-18917, which removed this functionality.
This restores that mariabackup --prepare recovers the transactional
binlog position from the redo log, and writes it to the file
xtrabackup_binlog_pos_innodb.

This position is updated only on every InnoDB commit. This means that
if the last event in the binlog at the time of backup is a DDL or
non-transactional update, the recovered position from --no-lock will
be behind the state of the backup.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
  • Loading branch information
knielsen committed Nov 3, 2023
1 parent e695337 commit 167fe66
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
47 changes: 45 additions & 2 deletions extra/mariabackup/xtrabackup.cc
Expand Up @@ -421,6 +421,9 @@ uint opt_safe_slave_backup_timeout = 0;

const char *opt_history = NULL;

/* Whether xtrabackup_binlog_info should be created on recovery */
static bool recover_binlog_info;


char mariabackup_exe[FN_REFLEN];
char orig_argv1[FN_REFLEN];
Expand Down Expand Up @@ -2340,6 +2343,7 @@ xtrabackup_read_metadata(char *filename)
{
FILE *fp;
my_bool r = TRUE;
int t;

fp = fopen(filename,"r");
if(!fp) {
Expand Down Expand Up @@ -2370,6 +2374,9 @@ xtrabackup_read_metadata(char *filename)
}
/* Optional fields */

if (fscanf(fp, "recover_binlog_info = %d\n", &t) == 1) {
recover_binlog_info = (t == 1);
}
end:
fclose(fp);

Expand All @@ -2388,11 +2395,13 @@ xtrabackup_print_metadata(char *buf, size_t buf_len)
"backup_type = %s\n"
"from_lsn = " UINT64PF "\n"
"to_lsn = " UINT64PF "\n"
"last_lsn = " UINT64PF "\n",
"last_lsn = " UINT64PF "\n"
"recover_binlog_info = %d\n",
metadata_type,
metadata_from_lsn,
metadata_to_lsn,
metadata_last_lsn);
metadata_last_lsn,
MY_TEST(opt_binlog_info == BINLOG_INFO_LOCKLESS));
}

/***********************************************************************
Expand Down Expand Up @@ -6036,6 +6045,26 @@ static ibool prepare_handle_del_files(const char *datadir, const char *db, const
return TRUE;
}


/**************************************************************************
Store the current binary log coordinates in a specified file.
@return 'false' on error. */
static bool
store_binlog_info(const char *filename, const char* name, ulonglong pos)
{
FILE *fp = fopen(filename, "w");

if (!fp) {
msg("mariabackup: failed to open '%s'\n", filename);
return(false);
}

fprintf(fp, "%s\t%llu\n", name, pos);
fclose(fp);

return(true);
}

/** Implement --prepare
@return whether the operation succeeded */
static bool xtrabackup_prepare_func(char** argv)
Expand Down Expand Up @@ -6275,6 +6304,20 @@ static bool xtrabackup_prepare_func(char** argv)
msg("Last binlog file %s, position %lld",
trx_sys.recovered_binlog_filename,
longlong(trx_sys.recovered_binlog_offset));

/* output to xtrabackup_binlog_pos_innodb and (if
backup_safe_binlog_info was available on the server) to
xtrabackup_binlog_info. In the latter case
xtrabackup_binlog_pos_innodb becomes redundant and is created
only for compatibility. */
ok = store_binlog_info(
"xtrabackup_binlog_pos_innodb",
trx_sys.recovered_binlog_filename,
trx_sys.recovered_binlog_offset)
&& (!recover_binlog_info || store_binlog_info(
XTRABACKUP_BINLOG_INFO,
trx_sys.recovered_binlog_filename,
trx_sys.recovered_binlog_offset));
}

/* Check whether the log is applied enough or not. */
Expand Down
2 changes: 1 addition & 1 deletion extra/mariabackup/xtrabackup.h
Expand Up @@ -171,7 +171,7 @@ extern uint opt_safe_slave_backup_timeout;

extern const char *opt_history;

enum binlog_info_enum { BINLOG_INFO_OFF, BINLOG_INFO_ON,
enum binlog_info_enum { BINLOG_INFO_OFF, BINLOG_INFO_LOCKLESS, BINLOG_INFO_ON,
BINLOG_INFO_AUTO};

extern ulong opt_binlog_info;
Expand Down

0 comments on commit 167fe66

Please sign in to comment.