Skip to content
Permalink
Browse files
mariabackup : use die() macro for fatal exit with error message.
  • Loading branch information
vaintroub committed Jan 16, 2019
1 parent a8a27e6 commit 2153aaf
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 90 deletions.
@@ -2221,7 +2221,7 @@ static void copy_or_move_dir(const char *from, const char *to, bool do_copy, boo
to, 1));
}
if (!rc)
exit(EXIT_FAILURE);
die("copy or move file failed");
}
datadir_iter_free(it);
datadir_node_free(&node);
@@ -2323,8 +2323,7 @@ static void rocksdb_backup_checkpoint()
if (backup_to_directory)
{
if (my_mkdir(rocksdb_backup_dir, 0777, MYF(0))){
msg("Can't create rocksdb backup directory %s", rocksdb_backup_dir);
exit(EXIT_FAILURE);
die("Can't create rocksdb backup directory %s", rocksdb_backup_dir);
}
}
copy_or_move_dir(rocksdb_checkpoint_dir, ROCKSDB_BACKUP_DIR, true, backup_to_directory);
@@ -167,19 +167,19 @@ xb_mysql_query(MYSQL *connection, const char *query, bool use_result,
MYSQL_RES *mysql_result = NULL;

if (mysql_query(connection, query)) {
msg("Error: failed to execute query %s: %s", query, mysql_error(connection));
if (die_on_error) {
exit(EXIT_FAILURE);
die("failed to execute query %s: %s", query, mysql_error(connection));
} else {
msg("Error: failed to execute query %s: %s", query, mysql_error(connection));
}
return(NULL);
}

/* store result set on client if there is a result */
if (mysql_field_count(connection) > 0) {
if ((mysql_result = mysql_store_result(connection)) == NULL) {
msg("Error: failed to fetch query result %s: %s",
die("failed to fetch query result %s: %s",
query, mysql_error(connection));
exit(EXIT_FAILURE);
}

if (!use_result) {
@@ -910,8 +910,7 @@ DECLARE_THREAD(kill_mdl_waiters_thread(void *))
row[1], row[2], row[0]);
snprintf(query, sizeof(query), "KILL QUERY %s", row[0]);
if (mysql_query(mysql, query) && (mysql_errno(mysql) != ER_NO_SUCH_THREAD)) {
msg("Error: failed to execute query %s: %s", query,mysql_error(mysql));
exit(EXIT_FAILURE);
die("failed to execute query %s: %s", query,mysql_error(mysql));
}
}
mysql_free_result(result);
@@ -86,9 +86,7 @@ static inline int asprintf(char **strp, const char *fmt,...)

#define XB_DELTA_INFO_SUFFIX ".meta"


static inline int msg1(unsigned int thread_num, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 2, 3);
static inline int msg1(uint thread_num, const char *fmt, va_list args)
static inline int msg1(uint thread_num, const char *prefix, const char *fmt, va_list args)
{
int result;
time_t t = time(NULL);
@@ -98,35 +96,44 @@ static inline int msg1(uint thread_num, const char *fmt, va_list args)
result = vasprintf(&line, fmt, args);
if (result != -1) {
if (fmt && fmt[strlen(fmt)] != '\n')
result = fprintf(stderr, "[%02u] %s %s\n", thread_num, date, line);
result = fprintf(stderr, "[%02u] %s%s %s\n", thread_num, prefix, date, line);
else
result = fprintf(stderr, "[%02u] %s %s", thread_num, date, line);
result = fprintf(stderr, "[%02u] %s%s %s", thread_num, prefix, date, line);
free(line);
}
return result;
}
static inline int msg(unsigned int, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 2, 3);
static inline int msg(unsigned int thread_num, const char *fmt, ...)

static inline ATTRIBUTE_FORMAT(printf, 2, 3) int msg(unsigned int thread_num, const char *fmt, ...)
{
int result;
va_list args;
va_start(args, fmt);
result = msg1(thread_num, fmt, args);
result = msg1(thread_num,"", fmt, args);
va_end(args);
return result;
}

static inline int msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
static inline int msg(const char *fmt, ...)
static inline ATTRIBUTE_FORMAT(printf, 1, 2) int msg(const char *fmt, ...)
{
int result;
va_list args;
va_start(args, fmt);
result = msg1(0, fmt, args);
result = msg1(0, "", fmt, args);
va_end(args);
return result;
}

static inline ATTRIBUTE_FORMAT(printf, 1,2) ATTRIBUTE_NORETURN void die(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
msg1(0, "FATAL ERROR: ", fmt, args);
va_end(args);
fflush(stderr);
_exit(EXIT_FAILURE);
}


/* Use POSIX_FADV_NORMAL when available */

@@ -48,8 +48,7 @@ ds_create(const char *root, ds_type_t type)
#ifdef HAVE_LIBARCHIVE
ds = &datasink_archive;
#else
msg("Error : mariabackup was built without libarchive support");
exit(EXIT_FAILURE);
die("mariabackup was built without libarchive support");
#endif
break;
case DS_TYPE_XBSTREAM:
@@ -60,8 +59,7 @@ ds_create(const char *root, ds_type_t type)
break;
case DS_TYPE_ENCRYPT:
case DS_TYPE_DECRYPT:
msg("Error : mariabackup does not support encrypted backups.");
exit(EXIT_FAILURE);
die("mariabackup does not support encrypted backups.");
break;

case DS_TYPE_TMPFILE:
@@ -80,8 +78,7 @@ ds_create(const char *root, ds_type_t type)
if (ctxt != NULL) {
ctxt->datasink = ds;
} else {
msg("Error: failed to initialize datasink.");
exit(EXIT_FAILURE);
die("failed to initialize datasink.");
}

return ctxt;
@@ -96,7 +96,7 @@ buffer_open(ds_ctxt_t *ctxt, const char *path, MY_STAT *mystat)

dst_file = ds_open(pipe_ctxt, path, mystat);
if (dst_file == NULL) {
exit(EXIT_FAILURE);
die("ds_open(%s) failed", path);
}

buffer_ctxt = (ds_buffer_ctxt_t *) ctxt->ptr;
@@ -195,41 +195,37 @@ tmpfile_deinit(ds_ctxt_t *ctxt)
/* Stat the file to replace size and mtime on the original
* mystat struct */
if (my_fstat(tmp_file->fd, &mystat, MYF(0))) {
msg("error: my_fstat() failed.");
exit(EXIT_FAILURE);
die("my_fstat() failed.");
}
tmp_file->mystat.st_size = mystat.st_size;
tmp_file->mystat.st_mtime = mystat.st_mtime;

dst_file = ds_open(pipe_ctxt, tmp_file->orig_path,
&tmp_file->mystat);
if (dst_file == NULL) {
msg("error: could not stream a temporary file to "
die("could not stream a temporary file to "
"'%s'", tmp_file->orig_path);
exit(EXIT_FAILURE);
}

/* copy to the destination datasink */
posix_fadvise(tmp_file->fd, 0, 0, POSIX_FADV_SEQUENTIAL);
if (my_seek(tmp_file->fd, 0, SEEK_SET, MYF(0)) ==
MY_FILEPOS_ERROR) {
msg("error: my_seek() failed for '%s', errno = %d.",
die("my_seek() failed for '%s', errno = %d.",
tmp_file->file->path, my_errno);
exit(EXIT_FAILURE);
}
offset = 0;
while ((bytes = my_read(tmp_file->fd, (unsigned char *)buf, buf_size,
MYF(MY_WME))) > 0) {
posix_fadvise(tmp_file->fd, offset, buf_size, POSIX_FADV_DONTNEED);
offset += buf_size;
if (ds_write(dst_file, buf, bytes)) {
msg("error: cannot write to stream for '%s'.",
die("cannot write to stream for '%s'.",
tmp_file->orig_path);
exit(EXIT_FAILURE);
}
}
if (bytes == (size_t) -1) {
exit(EXIT_FAILURE);
die("my_read failed for %s", tmp_file->orig_path);
}

my_close(tmp_file->fd, MYF(MY_WME));
@@ -45,8 +45,7 @@ static std::string get_encryption_plugin_from_cnf()
FILE *f = fopen("backup-my.cnf", "r");
if (!f)
{
msg("Can't open backup-my.cnf for reading");
exit(EXIT_FAILURE);
die("Can't open backup-my.cnf for reading");
}
char line[512];
std::string plugin_load;
@@ -193,7 +193,7 @@ xb_write_galera_info(bool incremental_prepare)
fp = fopen(XB_GALERA_INFO_FILENAME, "w");
if (fp == NULL) {

msg("mariabackup: error: "
die(
"could not create " XB_GALERA_INFO_FILENAME
", errno = %d\n",
errno);
@@ -207,11 +207,10 @@ xb_write_galera_info(bool incremental_prepare)

if (fprintf(fp, "%s:%lld", uuid_str, (long long) seqno) < 0) {

msg("mariabackup: error: "
die(
"could not write to " XB_GALERA_INFO_FILENAME
", errno = %d\n",
errno);
exit(EXIT_FAILURE);
errno);;
}

fclose(fp);

0 comments on commit 2153aaf

Please sign in to comment.