Commit 7bcfa00a authored by Alexander Barkov's avatar Alexander Barkov

MDEV-31039 mariadb-backup: remove global variables ds_data and ds_meta

This is a non-functional change.

simplifying the code logic:
- removing global variables ds_data and ds_meta
- passing these variables as parameters to functions instead
- adding helper classes: Datasink_free_list and Backup_datasinks
- moving some function accepting a ds_ctxt parameter
  as methods to ds_ctxt.
parent f83b7ae1
This diff is collapsed.
......@@ -14,30 +14,18 @@
extern bool binlog_locked;
bool
backup_file_printf(const char *filename, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf, 2, 0);
/************************************************************************
Return true if first and second arguments are the same path. */
bool
equal_paths(const char *first, const char *second);
/************************************************************************
Copy file for backup/restore.
@return true in case of success. */
bool
copy_file(ds_ctxt_t *datasink,
const char *src_file_path,
const char *dst_file_path,
uint thread_n);
/** Start --backup */
bool backup_start(CorruptedPages &corrupted_pages);
bool backup_start(ds_ctxt *ds_data, ds_ctxt *ds_meta,
CorruptedPages &corrupted_pages);
/** Release resources after backup_start() */
void backup_release();
/** Finish after backup_start() and backup_release() */
bool backup_finish();
bool backup_finish(ds_ctxt *ds_data);
bool
apply_log_finish();
bool
......@@ -51,6 +39,5 @@ directory_exists(const char *dir, bool create);
lsn_t
get_current_lsn(MYSQL *connection);
bool backup_file_print_buf(const char *filename, const char *buf, int buf_len);
#endif
......@@ -1383,7 +1383,7 @@ variable.
@returns true on success
*/
bool
write_slave_info(MYSQL *connection)
write_slave_info(ds_ctxt *datasink, MYSQL *connection)
{
String sql, comment;
bool show_all_slaves_status= false;
......@@ -1413,7 +1413,8 @@ write_slave_info(MYSQL *connection)
}
mysql_slave_position= strdup(comment.c_ptr());
return backup_file_print_buf(XTRABACKUP_SLAVE_INFO, sql.ptr(), sql.length());
return datasink->backup_file_print_buf(XTRABACKUP_SLAVE_INFO,
sql.ptr(), sql.length());
}
......@@ -1421,7 +1422,7 @@ write_slave_info(MYSQL *connection)
Retrieves MySQL Galera and
saves it in a file. It also prints it to stdout. */
bool
write_galera_info(MYSQL *connection)
write_galera_info(ds_ctxt *datasink, MYSQL *connection)
{
char *state_uuid = NULL, *state_uuid55 = NULL;
char *last_committed = NULL, *last_committed55 = NULL;
......@@ -1453,12 +1454,12 @@ write_galera_info(MYSQL *connection)
goto cleanup;
}
result = backup_file_printf(XTRABACKUP_GALERA_INFO,
result = datasink->backup_file_printf(XTRABACKUP_GALERA_INFO,
"%s:%s\n", state_uuid ? state_uuid : state_uuid55,
last_committed ? last_committed : last_committed55);
if (result)
{
write_current_binlog_file(connection);
write_current_binlog_file(datasink, connection);
}
cleanup:
......@@ -1472,7 +1473,7 @@ write_galera_info(MYSQL *connection)
Flush and copy the current binary log file into the backup,
if GTID is enabled */
bool
write_current_binlog_file(MYSQL *connection)
write_current_binlog_file(ds_ctxt *datasink, MYSQL *connection)
{
char *executed_gtid_set = NULL;
char *gtid_binlog_state = NULL;
......@@ -1542,7 +1543,7 @@ write_current_binlog_file(MYSQL *connection)
snprintf(filepath, sizeof(filepath), "%s%c%s",
log_bin_dir, FN_LIBCHAR, log_bin_file);
result = copy_file(ds_data, filepath, log_bin_file, 0);
result = datasink->copy_file(filepath, log_bin_file, 0);
}
cleanup:
......@@ -1558,7 +1559,7 @@ write_current_binlog_file(MYSQL *connection)
Retrieves MySQL binlog position and
saves it in a file. It also prints it to stdout. */
bool
write_binlog_info(MYSQL *connection)
write_binlog_info(ds_ctxt *datasink, MYSQL *connection)
{
char *filename = NULL;
char *position = NULL;
......@@ -1603,14 +1604,14 @@ write_binlog_info(MYSQL *connection)
"filename '%s', position '%s', "
"GTID of the last change '%s'",
filename, position, gtid) != -1);
result = backup_file_printf(XTRABACKUP_BINLOG_INFO,
result = datasink->backup_file_printf(XTRABACKUP_BINLOG_INFO,
"%s\t%s\t%s\n", filename, position,
gtid);
} else {
ut_a(asprintf(&mysql_binlog_position,
"filename '%s', position '%s'",
filename, position) != -1);
result = backup_file_printf(XTRABACKUP_BINLOG_INFO,
result = datasink->backup_file_printf(XTRABACKUP_BINLOG_INFO,
"%s\t%s\n", filename, position);
}
......@@ -1650,8 +1651,9 @@ PERCONA_SCHEMA.xtrabackup_history and writes a new history record to the
table containing all the history info particular to the just completed
backup. */
bool
write_xtrabackup_info(MYSQL *connection, const char * filename, bool history,
bool stream)
write_xtrabackup_info(ds_ctxt *datasink,
MYSQL *connection, const char * filename, bool history,
bool stream)
{
bool result = true;
......@@ -1727,7 +1729,7 @@ write_xtrabackup_info(MYSQL *connection, const char * filename, bool history,
}
if (stream) {
backup_file_printf(filename, "%s", buf);
datasink->backup_file_printf(filename, "%s", buf);
} else {
fp = fopen(filename, "w");
if (!fp) {
......@@ -1848,9 +1850,9 @@ static std::string make_local_paths(const char *data_file_path)
return buf.str();
}
bool write_backup_config_file()
bool write_backup_config_file(ds_ctxt *datasink)
{
int rc= backup_file_printf("backup-my.cnf",
int rc= datasink->backup_file_printf("backup-my.cnf",
"# This MySQL options file was generated by innobackupex.\n\n"
"# The MySQL server\n"
"[mysqld]\n"
......
......@@ -62,17 +62,18 @@ void
unlock_all(MYSQL *connection);
bool
write_current_binlog_file(MYSQL *connection);
write_current_binlog_file(ds_ctxt *datasink, MYSQL *connection);
bool
write_binlog_info(MYSQL *connection);
write_binlog_info(ds_ctxt *datasink, MYSQL *connection);
bool
write_xtrabackup_info(MYSQL *connection, const char * filename, bool history,
bool stream);
write_xtrabackup_info(ds_ctxt *datasink,
MYSQL *connection, const char * filename, bool history,
bool stream);
bool
write_backup_config_file();
write_backup_config_file(ds_ctxt *datasink);
bool
lock_binlog_maybe(MYSQL *connection);
......@@ -84,10 +85,10 @@ bool
wait_for_safe_slave(MYSQL *connection);
bool
write_galera_info(MYSQL *connection);
write_galera_info(ds_ctxt *datasink, MYSQL *connection);
bool
write_slave_info(MYSQL *connection);
write_slave_info(ds_ctxt *datasink, MYSQL *connection);
#endif
......@@ -37,6 +37,35 @@ typedef struct ds_ctxt {
char *root;
void *ptr;
struct ds_ctxt *pipe_ctxt;
/*
Copy file for backup/restore.
@return true in case of success.
*/
bool copy_file(const char *src_file_path,
const char *dst_file_path,
uint thread_n);
bool move_file(const char *src_file_path,
const char *dst_file_path,
const char *dst_dir,
uint thread_n);
bool make_hardlink(const char *from_path, const char *to_path);
void copy_or_move_dir(const char *from, const char *to,
bool do_copy, bool allow_hardlinks);
bool backup_file_vprintf(const char *filename,
const char *fmt, va_list ap);
bool backup_file_print_buf(const char *filename,
const char *buf,
int buf_len);
bool backup_file_printf(const char *filename,
const char *fmt, ...)
ATTRIBUTE_FORMAT(printf, 2, 0);
} ds_ctxt_t;
typedef struct {
......
......@@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
/************************************************************************
Write-through page write filter. */
static my_bool wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
static my_bool wf_wt_init(ds_ctxt *ds_meta,
xb_write_filt_ctxt_t *ctxt, char *dst_name,
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
static my_bool wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile);
......@@ -44,7 +45,8 @@ xb_write_filt_t wf_write_through = {
/************************************************************************
Incremental page write filter. */
static my_bool wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
static my_bool wf_incremental_init(ds_ctxt *ds_meta,
xb_write_filt_ctxt_t *ctxt, char *dst_name,
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
static my_bool wf_incremental_process(xb_write_filt_ctxt_t *ctxt,
ds_file_t *dstfile);
......@@ -64,7 +66,8 @@ Initialize incremental page write filter.
@return TRUE on success, FALSE on error. */
static my_bool
wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
wf_incremental_init(ds_ctxt *ds_meta,
xb_write_filt_ctxt_t *ctxt, char *dst_name,
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages)
{
char meta_name[FN_REFLEN];
......@@ -88,7 +91,7 @@ wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
XB_DELTA_INFO_SUFFIX);
const xb_delta_info_t info(cursor->page_size, cursor->zip_size,
cursor->space_id);
if (!xb_write_delta_metadata(meta_name, &info)) {
if (!xb_write_delta_metadata(ds_meta, meta_name, &info)) {
msg(cursor->thread_n,"Error: "
"failed to write meta info for %s",
cursor->rel_path);
......@@ -195,7 +198,8 @@ Initialize the write-through page write filter.
@return TRUE on success, FALSE on error. */
static my_bool
wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name __attribute__((unused)),
wf_wt_init(ds_ctxt *ds_meta __attribute__((unused)),
xb_write_filt_ctxt_t *ctxt, char *dst_name __attribute__((unused)),
xb_fil_cur_t *cursor, CorruptedPages *)
{
ctxt->cursor = cursor;
......
......@@ -45,7 +45,8 @@ typedef struct {
typedef struct {
my_bool (*init)(xb_write_filt_ctxt_t *ctxt, char *dst_name,
my_bool (*init)(ds_ctxt *ds_meta,
xb_write_filt_ctxt_t *ctxt, char *dst_name,
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
my_bool (*process)(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile);
my_bool (*finalize)(xb_write_filt_ctxt_t *, ds_file_t *dstfile);
......
This diff is collapsed.
......@@ -46,11 +46,13 @@ class CorruptedPages
bool contains(ulint space_id, ulint page_no) const;
void drop_space(ulint space_id);
void rename_space(ulint space_id, const std::string &new_name);
bool print_to_file(const char *file_name) const;
bool print_to_file(ds_ctxt *ds_data, const char *file_name) const;
void read_from_file(const char *file_name);
bool empty() const;
void zero_out_free_pages();
void backup_fix_ddl(ds_ctxt *ds_data, ds_ctxt *ds_meta);
private:
void add_page_no_lock(const char *space_name, ulint space_id, ulint page_no,
bool convert_space_name);
......@@ -63,6 +65,7 @@ class CorruptedPages
container_t m_spaces;
};
/* value of the --incremental option */
extern lsn_t incremental_lsn;
......@@ -76,8 +79,6 @@ extern char *xb_rocksdb_datadir;
extern my_bool xb_backup_rocksdb;
extern uint opt_protocol;
extern ds_ctxt_t *ds_meta;
extern ds_ctxt_t *ds_data;
/* The last checkpoint LSN at the backup startup time */
extern lsn_t checkpoint_lsn_start;
......@@ -177,7 +178,8 @@ extern ulong opt_binlog_info;
extern ulong xtrabackup_innodb_force_recovery;
void xtrabackup_io_throttling(void);
my_bool xb_write_delta_metadata(const char *filename,
my_bool xb_write_delta_metadata(ds_ctxt *ds_meta,
const char *filename,
const xb_delta_info_t *info);
/************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment