From: damien Date: May 24 2007 8:45pm Subject: bk commit into 5.0 tree (dkatz:1.2497) BUG#24733 List-Archive: http://lists.mysql.com/commits/27314 X-Bug: 24733 Message-Id: <20070524204500.24E6B3FDF3C@damien-katzs-computer.local> Below is the list of changes that have just been committed into a local 5.0 repository of dkatz. When dkatz does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-05-24 16:44:52-04:00, dkatz@stripped +1 -0 Bug #24733 RESET MASTER run before dump with --delete-master-logs fixed by using flush logs, dumping, then doing PURGE MASTER LOGS TO 'binfile', instead of deleting the log files at the beginning. NOTE: previously the delete-master-logs would reset the log names back to filename.00001. Now the trailing number doesn't get reset. This may need to be documented. client/mysqldump.c@stripped, 2007-05-24 16:44:49-04:00, dkatz@stripped +52 -4 changed the code the --delete-master-logs option is used from this: take locks dekete bin logs do dump (if this is a lock-based dump) release locks do dump (if this is a consistent-read-dump) to this: take locks flush logs remember the name of the new log do dump (if this is a lock-based dump) release locks do dump (if this is a consistent-read-dump) fflush output sql file if specified, to ensure the backup is commited to disk --- yes, dump succeeded --- do PURGE MASTER LOGS TO up to the new log # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: dkatz # Host: damien-katzs-computer.local # Root: /Users/dkatz/50_div_zero --- 1.263/client/mysqldump.c 2007-05-16 04:14:28 -04:00 +++ 1.264/client/mysqldump.c 2007-05-24 16:44:49 -04:00 @@ -3268,10 +3268,40 @@ static int do_unlock_tables(MYSQL *mysql return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES"); } +static int get_last_log_name(MYSQL *mysql_con, char* buff_last_logname, int buff_len) +{ + MYSQL_RES *res; + MYSQL_ROW row; + + if (mysql_query(mysql, "SHOW MASTER STATUS") || + !(res= mysql_store_result(mysql))) + return 1; + + if (!(row= mysql_fetch_row(res))) + { + mysql_free_result(res); + return 1; + } + + /* + Only one row is returned, and the first column is the name of the + active log. + */ + + strmake(buff_last_logname, row[0], buff_len); -static int do_reset_master(MYSQL *mysql_con) + mysql_free_result(res); + + return 0; +} + +static int purge_log_to(MYSQL *mysql_con, char* log_file_name) { - return mysql_query_with_error_report(mysql_con, 0, "RESET MASTER"); + DYNAMIC_STRING str; + init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024); + dynstr_append_checked(&str, log_file_name); + dynstr_append_checked(&str, "'"); + return mysql_query_with_error_report(mysql_con, 0, str.str); } @@ -3795,6 +3825,7 @@ static void dynstr_realloc_checked(DYNAM int main(int argc, char **argv) { + char last_log_name[FN_REFLEN]; int exit_code; MY_INIT("mysqldump"); @@ -3831,8 +3862,14 @@ int main(int argc, char **argv) goto err; if (opt_single_transaction && start_transaction(mysql)) goto err; - if (opt_delete_master_logs && do_reset_master(mysql)) - goto err; + + if (opt_delete_master_logs) + { + if (mysql_refresh(mysql, REFRESH_LOG) || + get_last_log_name(mysql, last_log_name, sizeof(last_log_name))) + goto err; + flush_logs= 0; + } if (opt_lock_all_tables || opt_master_data) { if (flush_logs && mysql_refresh(mysql, REFRESH_LOG)) @@ -3856,6 +3893,17 @@ int main(int argc, char **argv) /* One or more databases, all tables */ dump_databases(argv); } + + /* ensure dumped data flushed to disk */ + if (md_result_file && md_result_file != stdout && fflush(md_result_file)) + { + first_error = EX_MYSQLERR; + goto err; + } + /* everything successful, purge the old logs files */ + if (opt_delete_master_logs && purge_log_to(mysql, last_log_name)) + goto err; + #ifdef HAVE_SMEM my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); #endif