"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "extra/mariabackup/backup_copy.cc" between
mariadb-10.2.21.tar.gz and mariadb-10.2.22.tar.gz

About: MariaDB is a relational database management system (a drop-in replacement for MySQL). Stable (GA) release (10.2).

backup_copy.cc  (mariadb-10.2.21):backup_copy.cc  (mariadb-10.2.22)
skipping to change at line 237 skipping to change at line 237
} }
static static
bool bool
datadir_iter_next_database(datadir_iter_t *it) datadir_iter_next_database(datadir_iter_t *it)
{ {
if (it->dbdir != NULL) { if (it->dbdir != NULL) {
if (os_file_closedir(it->dbdir) != 0) { if (os_file_closedir(it->dbdir) != 0) {
msg("Warning: could not" msg("Warning: could not"
" close database directory %s\n", it->dbpath); " close database directory %s", it->dbpath);
it->err = DB_ERROR; it->err = DB_ERROR;
} }
it->dbdir = NULL; it->dbdir = NULL;
} }
while (os_file_readdir_next_file(it->datadir_path, while (os_file_readdir_next_file(it->datadir_path,
it->dir, &it->dbinfo) == 0) { it->dir, &it->dbinfo) == 0) {
ulint len; ulint len;
skipping to change at line 278 skipping to change at line 278
snprintf(it->dbpath, it->dbpath_len, "%s/%s", snprintf(it->dbpath, it->dbpath_len, "%s/%s",
it->datadir_path, it->dbinfo.name); it->datadir_path, it->dbinfo.name);
os_normalize_path(it->dbpath); os_normalize_path(it->dbpath);
if (it->dbinfo.type == OS_FILE_TYPE_FILE) { if (it->dbinfo.type == OS_FILE_TYPE_FILE) {
it->is_file = true; it->is_file = true;
return(true); return(true);
} }
if (check_if_skip_database_by_path(it->dbpath)) { if (check_if_skip_database_by_path(it->dbpath)) {
msg("Skipping db: %s\n", it->dbpath); msg("Skipping db: %s", it->dbpath);
continue; continue;
} }
/* We want wrong directory permissions to be a fatal error for /* We want wrong directory permissions to be a fatal error for
XtraBackup. */ XtraBackup. */
it->dbdir = os_file_opendir(it->dbpath, TRUE); it->dbdir = os_file_opendir(it->dbpath, TRUE);
if (it->dbdir != NULL) { if (it->dbdir != NULL) {
it->is_file = false; it->is_file = false;
skipping to change at line 521 skipping to change at line 521
xb_get_relative_path(cursor->abs_path, FALSE), xb_get_relative_path(cursor->abs_path, FALSE),
sizeof(cursor->rel_path)); sizeof(cursor->rel_path));
cursor->file = os_file_create_simple_no_error_handling( cursor->file = os_file_create_simple_no_error_handling(
0, cursor->abs_path, 0, cursor->abs_path,
OS_FILE_OPEN, OS_FILE_READ_ALLOW_DELETE, true, &success); OS_FILE_OPEN, OS_FILE_READ_ALLOW_DELETE, true, &success);
if (!success) { if (!success) {
/* The following call prints an error message */ /* The following call prints an error message */
os_file_get_last_error(TRUE); os_file_get_last_error(TRUE);
msg("[%02u] error: cannot open " msg(thread_n,"error: cannot open "
"file %s\n", "file %s", cursor->abs_path);
thread_n, cursor->abs_path);
return(false); return(false);
} }
if (!my_stat(cursor->abs_path, &cursor->statinfo, 0)) { if (!my_stat(cursor->abs_path, &cursor->statinfo, 0)) {
msg("[%02u] error: cannot stat %s\n", msg(thread_n, "error: cannot stat %s", cursor->abs_path);
thread_n, cursor->abs_path);
datafile_close(cursor); datafile_close(cursor);
return(false); return(false);
} }
posix_fadvise(cursor->file, 0, 0, POSIX_FADV_SEQUENTIAL); posix_fadvise(cursor->file, 0, 0, POSIX_FADV_SEQUENTIAL);
cursor->buf_size = 10 * 1024 * 1024; cursor->buf_size = 10 * 1024 * 1024;
cursor->buf = static_cast<byte *>(malloc((ulint)cursor->buf_size)); cursor->buf = static_cast<byte *>(malloc((ulint)cursor->buf_size));
return(true); return(true);
} }
skipping to change at line 722 skipping to change at line 718
char errbuf[MYSYS_STRERROR_SIZE]; char errbuf[MYSYS_STRERROR_SIZE];
if (my_stat(dir, &stat_arg, MYF(0)) == NULL) { if (my_stat(dir, &stat_arg, MYF(0)) == NULL) {
if (!create) { if (!create) {
return(false); return(false);
} }
if (mkdirp(dir, 0777, MYF(0)) < 0) { if (mkdirp(dir, 0777, MYF(0)) < 0) {
my_strerror(errbuf, sizeof(errbuf), my_errno); my_strerror(errbuf, sizeof(errbuf), my_errno);
msg("Can not create directory %s: %s\n", dir, errbuf); msg("Can not create directory %s: %s", dir, errbuf);
return(false); return(false);
} }
} }
/* could be symlink */ /* could be symlink */
os_dir = os_file_opendir(dir, FALSE); os_dir = os_file_opendir(dir, FALSE);
if (os_dir == NULL) { if (os_dir == NULL) {
my_strerror(errbuf, sizeof(errbuf), my_errno); my_strerror(errbuf, sizeof(errbuf), my_errno);
msg("Can not open directory %s: %s\n", dir, msg("Can not open directory %s: %s", dir,
errbuf); errbuf);
return(false); return(false);
} }
os_file_closedir(os_dir); os_file_closedir(os_dir);
return(true); return(true);
} }
skipping to change at line 762 skipping to change at line 757
os_file_stat_t info; os_file_stat_t info;
bool empty; bool empty;
if (!directory_exists(dir, true)) { if (!directory_exists(dir, true)) {
return(false); return(false);
} }
os_dir = os_file_opendir(dir, FALSE); os_dir = os_file_opendir(dir, FALSE);
if (os_dir == NULL) { if (os_dir == NULL) {
msg("%s can not open directory %s\n", comment, dir); msg("%s can not open directory %s", comment, dir);
return(false); return(false);
} }
empty = (fil_file_readdir_next_file(&err, dir, os_dir, &info) != 0); empty = (fil_file_readdir_next_file(&err, dir, os_dir, &info) != 0);
os_file_closedir(os_dir); os_file_closedir(os_dir);
if (!empty) { if (!empty) {
msg("%s directory %s is not empty!\n", comment, dir); msg("%s directory %s is not empty!", comment, dir);
} }
return(empty); return(empty);
} }
/************************************************************************ /************************************************************************
Check if file name ends with given set of suffixes. Check if file name ends with given set of suffixes.
@return true if it does. */ @return true if it does. */
static static
bool bool
skipping to change at line 818 skipping to change at line 813
/* Get the name and the path for the tablespace. node->name always /* Get the name and the path for the tablespace. node->name always
contains the path (which may be absolute for remote tablespaces in contains the path (which may be absolute for remote tablespaces in
5.6+). space->name contains the tablespace name in the form 5.6+). space->name contains the tablespace name in the form
"./database/table.ibd" (in 5.5-) or "database/table" (in 5.6+). For a "./database/table.ibd" (in 5.5-) or "database/table" (in 5.6+). For a
multi-node shared tablespace, space->name contains the name of the first multi-node shared tablespace, space->name contains the name of the first
node, but that's irrelevant, since we only need node_name to match them node, but that's irrelevant, since we only need node_name to match them
against filters, and the shared tablespace is always copied regardless against filters, and the shared tablespace is always copied regardless
of the filters value. */ of the filters value. */
if (check_if_skip_table(filepath)) { if (check_if_skip_table(filepath)) {
msg_ts("[%02u] Skipping %s.\n", thread_n, filepath); msg(thread_n,"Skipping %s.", filepath);
return(true); return(true);
} }
if (filename_matches(filepath, ext_list)) { if (filename_matches(filepath, ext_list)) {
return copy_file(ds_data, filepath, filepath, thread_n); return copy_file(ds_data, filepath, filepath, thread_n);
} }
return(true); return(true);
} }
skipping to change at line 882 skipping to change at line 877
memset(&stat, 0, sizeof(stat)); memset(&stat, 0, sizeof(stat));
buf_len = vasprintf(&buf, fmt, ap); buf_len = vasprintf(&buf, fmt, ap);
stat.st_size = buf_len; stat.st_size = buf_len;
stat.st_mtime = my_time(0); stat.st_mtime = my_time(0);
dstfile = ds_open(ds_data, filename, &stat); dstfile = ds_open(ds_data, filename, &stat);
if (dstfile == NULL) { if (dstfile == NULL) {
msg("[%02u] error: " msg("error: Can't open the destination stream for %s",
"cannot open the destination stream for %s\n", filename);
0, filename);
goto error; goto error;
} }
action = xb_get_copy_action("Writing"); action = xb_get_copy_action("Writing");
msg_ts("[%02u] %s %s\n", 0, action, filename); msg("%s %s", action, filename);
if (buf_len == -1) { if (buf_len == -1) {
goto error; goto error;
} }
if (ds_write(dstfile, buf, buf_len)) { if (ds_write(dstfile, buf, buf_len)) {
goto error; goto error;
} }
/* close */ /* close */
msg_ts("[%02u] ...done\n", 0); msg(" ...done");
free(buf); free(buf);
if (ds_close(dstfile)) { if (ds_close(dstfile)) {
goto error_close; goto error_close;
} }
return(true); return(true);
error: error:
free(buf); free(buf);
if (dstfile != NULL) { if (dstfile != NULL) {
ds_close(dstfile); ds_close(dstfile);
} }
error_close: error_close:
msg("[%02u] Error: backup file failed.\n", 0); msg("Error: backup file failed.");
return(false); /*ERROR*/ return(false); /*ERROR*/
} }
bool bool
backup_file_printf(const char *filename, const char *fmt, ...) backup_file_printf(const char *filename, const char *fmt, ...)
{ {
bool result; bool result;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
skipping to change at line 975 skipping to change at line 969
} }
pthread_mutex_unlock(&count_mutex); pthread_mutex_unlock(&count_mutex);
} }
pthread_mutex_destroy(&count_mutex); pthread_mutex_destroy(&count_mutex);
ret = true; ret = true;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
ret = data_threads[i].ret && ret; ret = data_threads[i].ret && ret;
if (!data_threads[i].ret) { if (!data_threads[i].ret) {
msg("Error: thread %u failed.\n", i); msg("Error: thread %u failed.", i);
} }
} }
free(data_threads); free(data_threads);
return(ret); return(ret);
} }
/************************************************************************ /************************************************************************
Copy file for backup/restore. Copy file for backup/restore.
skipping to change at line 1009 skipping to change at line 1003
dst_file_path : trim_dotslash(dst_file_path); dst_file_path : trim_dotslash(dst_file_path);
if (!datafile_open(src_file_path, &cursor, thread_n)) { if (!datafile_open(src_file_path, &cursor, thread_n)) {
goto error_close; goto error_close;
} }
strncpy(dst_name, cursor.rel_path, sizeof(dst_name)); strncpy(dst_name, cursor.rel_path, sizeof(dst_name));
dstfile = ds_open(datasink, dst_path, &cursor.statinfo); dstfile = ds_open(datasink, dst_path, &cursor.statinfo);
if (dstfile == NULL) { if (dstfile == NULL) {
msg("[%02u] error: " msg(thread_n,"error: "
"cannot open the destination stream for %s\n", "cannot open the destination stream for %s", dst_name);
thread_n, dst_name);
goto error; goto error;
} }
msg_ts("[%02u] %s %s to %s\n", msg(thread_n, "%s %s to %s", xb_get_copy_action(), src_file_path, dstfile
thread_n, xb_get_copy_action(), src_file_path, dstfile->path); ->path);
/* The main copy loop */ /* The main copy loop */
while ((res = datafile_read(&cursor)) == XB_FIL_CUR_SUCCESS) { while ((res = datafile_read(&cursor)) == XB_FIL_CUR_SUCCESS) {
if (ds_write(dstfile, cursor.buf, cursor.buf_read)) { if (ds_write(dstfile, cursor.buf, cursor.buf_read)) {
goto error; goto error;
} }
} }
if (res == XB_FIL_CUR_ERROR) { if (res == XB_FIL_CUR_ERROR) {
goto error; goto error;
} }
/* close */ /* close */
msg_ts("[%02u] ...done\n", thread_n); msg(thread_n," ...done");
datafile_close(&cursor); datafile_close(&cursor);
if (ds_close(dstfile)) { if (ds_close(dstfile)) {
goto error_close; goto error_close;
} }
return(true); return(true);
error: error:
datafile_close(&cursor); datafile_close(&cursor);
if (dstfile != NULL) { if (dstfile != NULL) {
ds_close(dstfile); ds_close(dstfile);
} }
error_close: error_close:
msg("[%02u] Error: copy_file() failed.\n", thread_n); msg(thread_n,"Error: copy_file() failed.");
return(false); /*ERROR*/ return(false); /*ERROR*/
} }
/************************************************************************ /************************************************************************
Try to move file by renaming it. If source and destination are on Try to move file by renaming it. If source and destination are on
different devices fall back to copy and unlink. different devices fall back to copy and unlink.
@return true in case of success. */ @return true in case of success. */
static static
bool bool
move_file(ds_ctxt_t *datasink, move_file(ds_ctxt_t *datasink,
skipping to change at line 1076 skipping to change at line 1068
"%s/%s", dst_dir, dst_file_path); "%s/%s", dst_dir, dst_file_path);
dirname_part(dst_dir_abs, dst_file_path_abs, &dirname_length); dirname_part(dst_dir_abs, dst_file_path_abs, &dirname_length);
if (!directory_exists(dst_dir_abs, true)) { if (!directory_exists(dst_dir_abs, true)) {
return(false); return(false);
} }
if (file_exists(dst_file_path_abs)) { if (file_exists(dst_file_path_abs)) {
msg("Error: Move file %s to %s failed: Destination " msg("Error: Move file %s to %s failed: Destination "
"file exists\n", "file exists", src_file_path, dst_file_path_abs);
src_file_path, dst_file_path_abs);
return(false); return(false);
} }
msg_ts("[%02u] Moving %s to %s\n", msg(thread_n,"Moving %s to %s", src_file_path, dst_file_path_abs);
thread_n, src_file_path, dst_file_path_abs);
if (my_rename(src_file_path, dst_file_path_abs, MYF(0)) != 0) { if (my_rename(src_file_path, dst_file_path_abs, MYF(0)) != 0) {
if (my_errno == EXDEV) { if (my_errno == EXDEV) {
bool ret; bool ret;
ret = copy_file(datasink, src_file_path, ret = copy_file(datasink, src_file_path,
dst_file_path, thread_n); dst_file_path, thread_n);
msg_ts("[%02u] Removing %s\n", thread_n, src_file_path); msg(thread_n,"Removing %s", src_file_path);
if (unlink(src_file_path) != 0) { if (unlink(src_file_path) != 0) {
my_strerror(errbuf, sizeof(errbuf), errno); my_strerror(errbuf, sizeof(errbuf), errno);
msg("Error: unlink %s failed: %s\n", msg("Error: unlink %s failed: %s",
src_file_path, src_file_path,
errbuf); errbuf);
} }
return(ret); return(ret);
} }
my_strerror(errbuf, sizeof(errbuf), my_errno); my_strerror(errbuf, sizeof(errbuf), my_errno);
msg("Can not move file %s to %s: %s\n", msg("Can not move file %s to %s: %s",
src_file_path, dst_file_path_abs, src_file_path, dst_file_path_abs,
errbuf); errbuf);
return(false); return(false);
} }
msg_ts("[%02u] ...done\n", thread_n); msg(thread_n," ...done");
return(true); return(true);
} }
/************************************************************************ /************************************************************************
Read link from .isl file if any and store it in the global map associated Read link from .isl file if any and store it in the global map associated
with given tablespace. */ with given tablespace. */
static static
void void
read_link_file(const char *ibd_filepath, const char *link_filepath) read_link_file(const char *ibd_filepath, const char *link_filepath)
skipping to change at line 1251 skipping to change at line 1241
return(true); return(true);
} }
if (opt_rsync) { if (opt_rsync) {
snprintf(rsync_tmpfile_name, sizeof(rsync_tmpfile_name), snprintf(rsync_tmpfile_name, sizeof(rsync_tmpfile_name),
"%s/%s%d", opt_mysql_tmpdir, "%s/%s%d", opt_mysql_tmpdir,
"xtrabackup_rsyncfiles_pass", "xtrabackup_rsyncfiles_pass",
prep_mode ? 1 : 2); prep_mode ? 1 : 2);
rsync_tmpfile = fopen(rsync_tmpfile_name, "w"); rsync_tmpfile = fopen(rsync_tmpfile_name, "w");
if (rsync_tmpfile == NULL) { if (rsync_tmpfile == NULL) {
msg("Error: can't create file %s\n", msg("Error: can't create file %s",
rsync_tmpfile_name); rsync_tmpfile_name);
return(false); return(false);
} }
} }
msg_ts("Starting %s non-InnoDB tables and files\n", msg("Starting %s non-InnoDB tables and files",
prep_mode ? "prep copy of" : "to backup"); prep_mode ? "prep copy of" : "to backup");
datadir_node_init(&node); datadir_node_init(&node);
it = datadir_iter_new(from); it = datadir_iter_new(from);
while (datadir_iter_next(it, &node)) { while (datadir_iter_next(it, &node)) {
if (!node.is_empty_dir) { if (!node.is_empty_dir) {
if (opt_rsync) { if (opt_rsync) {
ret = datafile_rsync_backup(node.filepath, ret = datafile_rsync_backup(node.filepath,
!prep_mode, rsync_tmpfile); !prep_mode, rsync_tmpfile);
} else { } else {
ret = datafile_copy_backup(node.filepath, 1); ret = datafile_copy_backup(node.filepath, 1);
} }
if (!ret) { if (!ret) {
msg("Failed to copy file %s\n", node.filepath); msg("Failed to copy file %s", node.filepath);
goto out; goto out;
} }
} else if (!prep_mode) { } else if (!prep_mode) {
/* backup fake file into empty directory */ /* backup fake file into empty directory */
char path[FN_REFLEN]; char path[FN_REFLEN];
snprintf(path, sizeof(path), snprintf(path, sizeof(path),
"%s/db.opt", node.filepath); "%s/db.opt", node.filepath);
if (!(ret = backup_file_printf( if (!(ret = backup_file_printf(
trim_dotslash(path), "%s", ""))) { trim_dotslash(path), "%s", ""))) {
msg("Failed to create file %s\n", path); msg("Failed to create file %s", path);
goto out; goto out;
} }
} }
} }
if (opt_rsync) { if (opt_rsync) {
std::stringstream cmd; std::stringstream cmd;
int err; int err;
if (buffer_pool_filename && file_exists(buffer_pool_filename)) { if (buffer_pool_filename && file_exists(buffer_pool_filename)) {
skipping to change at line 1308 skipping to change at line 1298
fprintf(rsync_tmpfile, "%s\n", "ib_lru_dump"); fprintf(rsync_tmpfile, "%s\n", "ib_lru_dump");
rsync_list.insert("ib_lru_dump"); rsync_list.insert("ib_lru_dump");
} }
fclose(rsync_tmpfile); fclose(rsync_tmpfile);
rsync_tmpfile = NULL; rsync_tmpfile = NULL;
cmd << "rsync -t . --files-from=" << rsync_tmpfile_name cmd << "rsync -t . --files-from=" << rsync_tmpfile_name
<< " " << xtrabackup_target_dir; << " " << xtrabackup_target_dir;
msg_ts("Starting rsync as: %s\n", cmd.str().c_str()); msg("Starting rsync as: %s", cmd.str().c_str());
if ((err = system(cmd.str().c_str()) && !prep_mode) != 0) { if ((err = system(cmd.str().c_str()) && !prep_mode) != 0) {
msg_ts("Error: rsync failed with error code %d\n", err); msg("Error: rsync failed with error code %d", err);
ret = false; ret = false;
goto out; goto out;
} }
msg_ts("rsync finished successfully.\n"); msg("rsync finished successfully.");
if (!prep_mode && !opt_no_lock) { if (!prep_mode && !opt_no_lock) {
char path[FN_REFLEN]; char path[FN_REFLEN];
char dst_path[FN_REFLEN]; char dst_path[FN_REFLEN];
char *newline; char *newline;
/* Remove files that have been removed between first and /* Remove files that have been removed between first and
second passes. Cannot use "rsync --delete" because it second passes. Cannot use "rsync --delete" because it
does not work with --files-from. */ does not work with --files-from. */
snprintf(rsync_tmpfile_name, sizeof(rsync_tmpfile_name), snprintf(rsync_tmpfile_name, sizeof(rsync_tmpfile_name),
"%s/%s", opt_mysql_tmpdir, "%s/%s", opt_mysql_tmpdir,
"xtrabackup_rsyncfiles_pass1"); "xtrabackup_rsyncfiles_pass1");
rsync_tmpfile = fopen(rsync_tmpfile_name, "r"); rsync_tmpfile = fopen(rsync_tmpfile_name, "r");
if (rsync_tmpfile == NULL) { if (rsync_tmpfile == NULL) {
msg("Error: can't open file %s\n", msg("Error: can't open file %s",
rsync_tmpfile_name); rsync_tmpfile_name);
ret = false; ret = false;
goto out; goto out;
} }
while (fgets(path, sizeof(path), rsync_tmpfile)) { while (fgets(path, sizeof(path), rsync_tmpfile)) {
newline = strchr(path, '\n'); newline = strchr(path, '\n');
if (newline) { if (newline) {
*newline = 0; *newline = 0;
} }
if (rsync_list.count(path) < 1) { if (rsync_list.count(path) < 1) {
snprintf(dst_path, sizeof(dst_path), snprintf(dst_path, sizeof(dst_path),
"%s/%s", xtrabackup_target_dir, "%s/%s", xtrabackup_target_dir,
path); path);
msg_ts("Removing %s\n", dst_path); msg("Removing %s", dst_path);
unlink(dst_path); unlink(dst_path);
} }
} }
fclose(rsync_tmpfile); fclose(rsync_tmpfile);
rsync_tmpfile = NULL; rsync_tmpfile = NULL;
} }
} }
msg_ts("Finished %s non-InnoDB tables and files\n", msg("Finished %s non-InnoDB tables and files",
prep_mode ? "a prep copy of" : "backing up"); prep_mode ? "a prep copy of" : "backing up");
out: out:
datadir_iter_free(it); datadir_iter_free(it);
datadir_node_free(&node); datadir_node_free(&node);
if (rsync_tmpfile != NULL) { if (rsync_tmpfile != NULL) {
fclose(rsync_tmpfile); fclose(rsync_tmpfile);
} }
skipping to change at line 1428 skipping to change at line 1418
} }
if (!backup_files_from_datadir(fil_path_to_mysql_datadir)) { if (!backup_files_from_datadir(fil_path_to_mysql_datadir)) {
return false; return false;
} }
if (has_rocksdb_plugin()) { if (has_rocksdb_plugin()) {
rocksdb_create_checkpoint(); rocksdb_create_checkpoint();
} }
msg_ts("Waiting for log copy thread to read lsn %llu\n", (ulonglong)serve r_lsn_after_lock); msg("Waiting for log copy thread to read lsn %llu", (ulonglong)server_lsn _after_lock);
backup_wait_for_lsn(server_lsn_after_lock); backup_wait_for_lsn(server_lsn_after_lock);
backup_fix_ddl(); backup_fix_ddl();
// There is no need to stop slave thread before coping non-Innodb data wh en // There is no need to stop slave thread before coping non-Innodb data wh en
// --no-lock option is used because --no-lock option requires that no DDL or // --no-lock option is used because --no-lock option requires that no DDL or
// DML to non-transaction tables can occur. // DML to non-transaction tables can occur.
if (opt_no_lock) { if (opt_no_lock) {
if (opt_safe_slave_backup) { if (opt_safe_slave_backup) {
if (!wait_for_safe_slave(mysql_connection)) { if (!wait_for_safe_slave(mysql_connection)) {
return(false); return(false);
skipping to change at line 1471 skipping to change at line 1461
write_current_binlog_file(mysql_connection); write_current_binlog_file(mysql_connection);
} }
if (opt_binlog_info == BINLOG_INFO_ON) { if (opt_binlog_info == BINLOG_INFO_ON) {
lock_binlog_maybe(mysql_connection); lock_binlog_maybe(mysql_connection);
write_binlog_info(mysql_connection); write_binlog_info(mysql_connection);
} }
if (have_flush_engine_logs && !opt_no_lock) { if (have_flush_engine_logs && !opt_no_lock) {
msg_ts("Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...\n"); msg("Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...");
xb_mysql_query(mysql_connection, xb_mysql_query(mysql_connection,
"FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS", false); "FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS", false);
} }
return(true); return(true);
} }
/** Release resources after backup_start() */ /** Release resources after backup_start() */
void backup_release() void backup_release()
{ {
skipping to change at line 1495 skipping to change at line 1485
history_lock_time = 0; history_lock_time = 0;
} else { } else {
history_lock_time = time(NULL) - history_lock_time; history_lock_time = time(NULL) - history_lock_time;
} }
if (opt_lock_ddl_per_table) { if (opt_lock_ddl_per_table) {
mdl_unlock_all(); mdl_unlock_all();
} }
if (opt_safe_slave_backup && sql_thread_started) { if (opt_safe_slave_backup && sql_thread_started) {
msg("Starting slave SQL thread\n"); msg("Starting slave SQL thread");
xb_mysql_query(mysql_connection, xb_mysql_query(mysql_connection,
"START SLAVE SQL_THREAD", false); "START SLAVE SQL_THREAD", false);
} }
} }
/** Finish after backup_start() and backup_release() */ /** Finish after backup_start() and backup_release() */
bool backup_finish() bool backup_finish()
{ {
/* Copy buffer pool dump or LRU dump */ /* Copy buffer pool dump or LRU dump */
if (!opt_rsync) { if (!opt_rsync) {
skipping to change at line 1521 skipping to change at line 1511
} }
if (file_exists("ib_lru_dump")) { if (file_exists("ib_lru_dump")) {
copy_file(ds_data, "ib_lru_dump", "ib_lru_dump", 0); copy_file(ds_data, "ib_lru_dump", "ib_lru_dump", 0);
} }
} }
if (has_rocksdb_plugin()) { if (has_rocksdb_plugin()) {
rocksdb_backup_checkpoint(); rocksdb_backup_checkpoint();
} }
msg_ts("Backup created in directory '%s'\n", xtrabackup_target_dir); msg("Backup created in directory '%s'", xtrabackup_target_dir);
if (mysql_binlog_position != NULL) { if (mysql_binlog_position != NULL) {
msg("MySQL binlog position: %s\n", mysql_binlog_position); msg("MySQL binlog position: %s", mysql_binlog_position);
} }
if (mysql_slave_position && opt_slave_info) { if (mysql_slave_position && opt_slave_info) {
msg("MySQL slave binlog position: %s\n", msg("MySQL slave binlog position: %s",
mysql_slave_position); mysql_slave_position);
} }
if (!write_backup_config_file()) { if (!write_backup_config_file()) {
return(false); return(false);
} }
if (!write_xtrabackup_info(mysql_connection, XTRABACKUP_INFO, opt_history != 0)) { if (!write_xtrabackup_info(mysql_connection, XTRABACKUP_INFO, opt_history != 0)) {
return(false); return(false);
} }
skipping to change at line 1586 skipping to change at line 1576
|| !filename_matches(node.filepath, ext_list)) { || !filename_matches(node.filepath, ext_list)) {
continue; continue;
} }
if (file_exists(node.filepath_rel)) { if (file_exists(node.filepath_rel)) {
unlink(node.filepath_rel); unlink(node.filepath_rel);
} }
if (!(ret = copy_file(ds_data, node.filepath, if (!(ret = copy_file(ds_data, node.filepath,
node.filepath_rel, 1))) { node.filepath_rel, 1))) {
msg("Failed to copy file %s\n", msg("Failed to copy file %s",
node.filepath); node.filepath);
goto cleanup; goto cleanup;
} }
} }
/* copy buffer pool dump */ /* copy buffer pool dump */
if (innobase_buffer_pool_filename) { if (innobase_buffer_pool_filename) {
const char *src_name; const char *src_name;
src_name = trim_dotslash(innobase_buffer_pool_filename); src_name = trim_dotslash(innobase_buffer_pool_filename);
skipping to change at line 1726 skipping to change at line 1716
return(false); return(false);
} }
if (srv_log_group_home_dir && *srv_log_group_home_dir if (srv_log_group_home_dir && *srv_log_group_home_dir
&& !directory_exists(srv_log_group_home_dir, true)) { && !directory_exists(srv_log_group_home_dir, true)) {
return(false); return(false);
} }
/* cd to backup directory */ /* cd to backup directory */
if (my_setwd(xtrabackup_target_dir, MYF(MY_WME))) if (my_setwd(xtrabackup_target_dir, MYF(MY_WME)))
{ {
msg("cannot my_setwd %s\n", xtrabackup_target_dir); msg("Can't my_setwd %s", xtrabackup_target_dir);
return(false); return(false);
} }
/* parse data file path */ /* parse data file path */
if (!innobase_data_file_path) { if (!innobase_data_file_path) {
innobase_data_file_path = (char*) "ibdata1:10M:autoextend"; innobase_data_file_path = (char*) "ibdata1:10M:autoextend";
} }
srv_sys_space.set_path("."); srv_sys_space.set_path(".");
if (!srv_sys_space.parse_params(innobase_data_file_path, true)) { if (!srv_sys_space.parse_params(innobase_data_file_path, true)) {
msg("syntax error in innodb_data_file_path\n"); msg("syntax error in innodb_data_file_path");
return(false); return(false);
} }
srv_max_n_threads = 1000; srv_max_n_threads = 1000;
sync_check_init(); sync_check_init();
ut_crc32_init(); ut_crc32_init();
/* copy undo tablespaces */ /* copy undo tablespaces */
dst_dir = (srv_undo_dir && *srv_undo_dir) dst_dir = (srv_undo_dir && *srv_undo_dir)
skipping to change at line 1852 skipping to change at line 1842
continue; continue;
} }
/* create empty directories */ /* create empty directories */
if (node.is_empty_dir) { if (node.is_empty_dir) {
char path[FN_REFLEN]; char path[FN_REFLEN];
snprintf(path, sizeof(path), "%s/%s", snprintf(path, sizeof(path), "%s/%s",
mysql_data_home, node.filepath_rel); mysql_data_home, node.filepath_rel);
msg_ts("[%02u] Creating directory %s\n", 1, path); msg("Creating directory %s", path);
if (mkdirp(path, 0777, MYF(0)) < 0) { if (mkdirp(path, 0777, MYF(0)) < 0) {
char errbuf[MYSYS_STRERROR_SIZE]; char errbuf[MYSYS_STRERROR_SIZE];
my_strerror(errbuf, sizeof(errbuf), my_errno); my_strerror(errbuf, sizeof(errbuf), my_errno);
msg("Can not create directory %s: %s\n", msg("Can not create directory %s: %s",
path, errbuf); path, errbuf);
ret = false; ret = false;
goto cleanup; goto cleanup;
} }
msg_ts("[%02u] ...done.", 1); msg(" ...done.");
continue; continue;
} }
filename = base_name(node.filepath); filename = base_name(node.filepath);
/* skip .qp files */ /* skip .qp files */
if (filename_matches(filename, ext_list)) { if (filename_matches(filename, ext_list)) {
continue; continue;
} }
skipping to change at line 1975 skipping to change at line 1965
needs_action = true; needs_action = true;
} }
cmd << " > " << dest_filepath; cmd << " > " << dest_filepath;
message << " " << filepath; message << " " << filepath;
free(dest_filepath); free(dest_filepath);
if (needs_action) { if (needs_action) {
msg_ts("[%02u] %s\n", thread_n, message.str().c_str()); msg(thread_n,"%s\n", message.str().c_str());
if (system(cmd.str().c_str()) != 0) { if (system(cmd.str().c_str()) != 0) {
return(false); return(false);
} }
if (opt_remove_original) { if (opt_remove_original) {
msg_ts("[%02u] removing %s\n", thread_n, filepath); msg(thread_n, "Removing %s", filepath);
if (my_delete(filepath, MYF(MY_WME)) != 0) { if (my_delete(filepath, MYF(MY_WME)) != 0) {
return(false); return(false);
} }
} }
} }
return(true); return(true);
} }
static static
skipping to change at line 2045 skipping to change at line 2035
{ {
bool ret; bool ret;
datadir_iter_t *it = NULL; datadir_iter_t *it = NULL;
srv_max_n_threads = 1000; srv_max_n_threads = 1000;
sync_check_init(); sync_check_init();
/* cd to backup directory */ /* cd to backup directory */
if (my_setwd(xtrabackup_target_dir, MYF(MY_WME))) if (my_setwd(xtrabackup_target_dir, MYF(MY_WME)))
{ {
msg("cannot my_setwd %s\n", xtrabackup_target_dir); msg("Can't my_setwd %s", xtrabackup_target_dir);
return(false); return(false);
} }
/* copy the rest of tablespaces */ /* copy the rest of tablespaces */
ds_data = ds_create(".", DS_TYPE_LOCAL); ds_data = ds_create(".", DS_TYPE_LOCAL);
it = datadir_iter_new(".", false); it = datadir_iter_new(".", false);
ut_a(xtrabackup_parallel >= 0); ut_a(xtrabackup_parallel >= 0);
skipping to change at line 2194 skipping to change at line 2184
{ {
char to_path[FN_REFLEN]; char to_path[FN_REFLEN];
const char *from_path = node.filepath; const char *from_path = node.filepath;
snprintf(to_path, sizeof(to_path), "%s/%s", to, base_name(from_pa th)); snprintf(to_path, sizeof(to_path), "%s/%s", to, base_name(from_pa th));
bool rc = false; bool rc = false;
if (do_copy && allow_hardlinks) if (do_copy && allow_hardlinks)
{ {
rc = make_hardlink(from_path, to_path); rc = make_hardlink(from_path, to_path);
if (rc) if (rc)
{ {
msg_ts("[%02u] Creating hardlink from %s to %s\n" msg("Creating hardlink from %s to %s",from_path,
, to_path);
1, from_path, to_path);
} }
else else
{ {
allow_hardlinks = false; allow_hardlinks = false;
} }
} }
if (!rc) if (!rc)
{ {
rc = (do_copy ? rc = (do_copy ?
copy_file(ds_data, from_path, to_path, 1) : copy_file(ds_data, from_path, to_path, 1) :
move_file(ds_data, from_path, node.filepath_rel, move_file(ds_data, from_path, node.filepath_rel,
to, 1)); to, 1));
} }
if (!rc) if (!rc)
exit(EXIT_FAILURE); die("copy or move file failed");
} }
datadir_iter_free(it); datadir_iter_free(it);
datadir_node_free(&node); datadir_node_free(&node);
} }
/* /*
Obtain user level lock , to protect the checkpoint directory of the server Obtain user level lock , to protect the checkpoint directory of the server
from being user/overwritten by different backup processes, if backups are from being user/overwritten by different backup processes, if backups are
running in parallel. running in parallel.
This lock will be acquired before rocksdb checkpoint is created, held This lock will be acquired before rocksdb checkpoint is created, held
while all files from it are being copied to their final backup destination, while all files from it are being copied to their final backup destination,
and finally released after the checkpoint is removed. and finally released after the checkpoint is removed.
*/ */
static void rocksdb_lock_checkpoint() static void rocksdb_lock_checkpoint()
{ {
msg_ts("Obtaining rocksdb checkpoint lock.\n"); msg("Obtaining rocksdb checkpoint lock.");
MYSQL_RES *res = MYSQL_RES *res =
xb_mysql_query(mysql_connection, "SELECT GET_LOCK('mariabackup_ro cksdb_checkpoint',3600)", true, true); xb_mysql_query(mysql_connection, "SELECT GET_LOCK('mariabackup_ro cksdb_checkpoint',3600)", true, true);
MYSQL_ROW r = mysql_fetch_row(res); MYSQL_ROW r = mysql_fetch_row(res);
if (r && r[0] && strcmp(r[0], "1")) if (r && r[0] && strcmp(r[0], "1"))
{ {
msg_ts("Could not obtain rocksdb checkpont lock\n"); msg("Could not obtain rocksdb checkpont lock.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
mysql_free_result(res); mysql_free_result(res);
} }
static void rocksdb_unlock_checkpoint() static void rocksdb_unlock_checkpoint()
{ {
xb_mysql_query(mysql_connection, xb_mysql_query(mysql_connection,
"SELECT RELEASE_LOCK('mariabackup_rocksdb_checkpoint')", false, t rue); "SELECT RELEASE_LOCK('mariabackup_rocksdb_checkpoint')", false, t rue);
} }
skipping to change at line 2289 skipping to change at line 2278
#ifdef _WIN32 #ifdef _WIN32
for (char *p = rocksdb_checkpoint_dir; *p; p++) for (char *p = rocksdb_checkpoint_dir; *p; p++)
if (*p == '\\') *p = '/'; if (*p == '\\') *p = '/';
#endif #endif
rocksdb_lock_checkpoint(); rocksdb_lock_checkpoint();
if (!access(rocksdb_checkpoint_dir, 0)) if (!access(rocksdb_checkpoint_dir, 0))
{ {
msg_ts("Removing rocksdb checkpoint from previous backup attempt. \n"); msg("Removing rocksdb checkpoint from previous backup attempt.");
rocksdb_remove_checkpoint_directory(); rocksdb_remove_checkpoint_directory();
} }
char query[FN_REFLEN + 32]; char query[FN_REFLEN + 32];
snprintf(query, sizeof(query), "SET GLOBAL rocksdb_create_checkpoint='%s' ", rocksdb_checkpoint_dir); snprintf(query, sizeof(query), "SET GLOBAL rocksdb_create_checkpoint='%s' ", rocksdb_checkpoint_dir);
xb_mysql_query(mysql_connection, query, false, true); xb_mysql_query(mysql_connection, query, false, true);
} }
/* /*
Copy files from rocksdb temporary checkpoint to final destination. Copy files from rocksdb temporary checkpoint to final destination.
remove temp.checkpoint directory (in server's datadir) remove temp.checkpoint directory (in server's datadir)
and release user level lock acquired inside rocksdb_create_checkpoint(). and release user level lock acquired inside rocksdb_create_checkpoint().
*/ */
static void rocksdb_backup_checkpoint() static void rocksdb_backup_checkpoint()
{ {
msg_ts("Backing up rocksdb files.\n"); msg("Backing up rocksdb files.");
char rocksdb_backup_dir[FN_REFLEN]; char rocksdb_backup_dir[FN_REFLEN];
snprintf(rocksdb_backup_dir, sizeof(rocksdb_backup_dir), "%s/" ROCKSDB_BA CKUP_DIR , xtrabackup_target_dir); snprintf(rocksdb_backup_dir, sizeof(rocksdb_backup_dir), "%s/" ROCKSDB_BA CKUP_DIR , xtrabackup_target_dir);
bool backup_to_directory = xtrabackup_backup && xtrabackup_stream_fmt == XB_STREAM_FMT_NONE; bool backup_to_directory = xtrabackup_backup && xtrabackup_stream_fmt == XB_STREAM_FMT_NONE;
if (backup_to_directory) if (backup_to_directory)
{ {
if (my_mkdir(rocksdb_backup_dir, 0777, MYF(0))){ if (my_mkdir(rocksdb_backup_dir, 0777, MYF(0))){
msg_ts("Can't create rocksdb backup directory %s\n", rock die("Can't create rocksdb backup directory %s", rocksdb_b
sdb_backup_dir); ackup_dir);
exit(EXIT_FAILURE);
} }
} }
copy_or_move_dir(rocksdb_checkpoint_dir, ROCKSDB_BACKUP_DIR, true, backup _to_directory); copy_or_move_dir(rocksdb_checkpoint_dir, ROCKSDB_BACKUP_DIR, true, backup _to_directory);
rocksdb_remove_checkpoint_directory(); rocksdb_remove_checkpoint_directory();
rocksdb_unlock_checkpoint(); rocksdb_unlock_checkpoint();
} }
/* /*
Copies #rocksdb directory to the $rockdb_data_dir, on copy-back Copies #rocksdb directory to the $rockdb_data_dir, on copy-back
*/ */
 End of changes. 58 change blocks. 
73 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)