From e016e0f70c46e8db1d871eca2f20056278c5b5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 23 Jun 2015 22:27:51 +0200 Subject: [PATCH] Add RESET MASTER TO x to allow specification of binlog file nr Bug #77438 Extend RESET MASTER to allow specifying next binary log. --- sql/binlog.cc | 42 +++++++++++++++++++++++++++--------------- sql/binlog.h | 11 +++++++---- sql/mysqld.cc | 3 ++- sql/rpl_rli.cc | 3 ++- sql/sql_lex.h | 1 + sql/sql_yacc.yy | 9 +++++++++ 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/sql/binlog.cc b/sql/binlog.cc index ddead6a..aabd5ed 100644 --- a/sql/binlog.cc +++ b/sql/binlog.cc @@ -3020,7 +3020,7 @@ static bool is_number(const char *str, nonzero if not possible to get unique filename. */ -static int find_uniq_filename(char *name) +static int find_uniq_filename(char *name, ulong new_number) { uint i; char buff[FN_REFLEN], ext_buf[FN_REFLEN]; @@ -3066,7 +3066,12 @@ updating the index files.", max_found); goto end; } - next= max_found + 1; + if (new_number > 0) + { + next= new_number; + } else { + next= max_found + 1; + } if (sprintf(ext_buf, "%06lu", next)<0) { error= 1; @@ -3105,12 +3110,13 @@ Please consider archiving some logs.", next, (MAX_LOG_UNIQUE_FN_EXT - next)); } -int MYSQL_BIN_LOG::generate_new_name(char *new_name, const char *log_name) +int MYSQL_BIN_LOG::generate_new_name(char *new_name, const char *log_name, + ulong new_number) { fn_format(new_name, log_name, mysql_data_home, "", 4); if (!fn_ext(log_name)[0]) { - if (find_uniq_filename(new_name)) + if (find_uniq_filename(new_name, new_number)) { my_printf_error(ER_NO_UNIQUE_LOGFILE, ER(ER_NO_UNIQUE_LOGFILE), MYF(ME_FATALERROR), log_name); @@ -3147,11 +3153,12 @@ const char *MYSQL_BIN_LOG::generate_name(const char *log_name, bool MYSQL_BIN_LOG::init_and_set_log_file_name(const char *log_name, - const char *new_name) + const char *new_name, + ulong new_number) { if (new_name && !my_stpcpy(log_file_name, new_name)) return TRUE; - else if (!new_name && generate_new_name(log_file_name, log_name)) + else if (!new_name && generate_new_name(log_file_name, log_name, new_number)) return TRUE; return FALSE; @@ -3173,7 +3180,8 @@ bool MYSQL_BIN_LOG::open( PSI_file_key log_file_key, #endif const char *log_name, - const char *new_name) + const char *new_name, + ulong new_number) { File file= -1; my_off_t pos= 0; @@ -3189,7 +3197,7 @@ bool MYSQL_BIN_LOG::open( goto err; } - if (init_and_set_log_file_name(name, new_name) || + if (init_and_set_log_file_name(name, new_name, new_number) || DBUG_EVALUATE_IF("fault_injection_init_name", 1, 0)) goto err; @@ -4306,7 +4314,8 @@ bool MYSQL_BIN_LOG::open_binlog(const char *log_name, bool null_created_arg, bool need_lock_index, bool need_sid_lock, - Format_description_log_event *extra_description_event) + Format_description_log_event *extra_description_event, + ulong new_number) { // lock_index must be acquired *before* sid_lock. DBUG_ASSERT(need_sid_lock || !need_lock_index); @@ -4315,7 +4324,7 @@ bool MYSQL_BIN_LOG::open_binlog(const char *log_name, mysql_mutex_assert_owner(get_log_lock()); - if (init_and_set_log_file_name(log_name, new_name)) + if (init_and_set_log_file_name(log_name, new_name, new_number)) { sql_print_error("MYSQL_BIN_LOG::open failed to generate new file name."); DBUG_RETURN(1); @@ -4361,7 +4370,7 @@ bool MYSQL_BIN_LOG::open_binlog(const char *log_name, #ifdef HAVE_PSI_INTERFACE m_key_file_log, #endif - log_name, new_name)) + log_name, new_name, new_number)) { #ifdef HAVE_REPLICATION close_purge_index_file(); @@ -5183,7 +5192,8 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool delete_only) max_size, false, false/*need_lock_index=false*/, false/*need_sid_lock=false*/, - NULL))) + NULL, + thd->lex->next_binlog_file_nr))) goto err; } my_free((void *) save_name); @@ -6217,7 +6227,7 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock_log, Format_description_log_even We have to do this here and not in open as we want to store the new file name in the current binary log file. */ - if ((error= generate_new_name(new_name, name))) + if ((error= generate_new_name(new_name, name, 0))) goto end; else { @@ -6297,7 +6307,8 @@ int MYSQL_BIN_LOG::new_file_impl(bool need_lock_log, Format_description_log_even max_size, true/*null_created_arg=true*/, false/*need_lock_index=false*/, true/*need_sid_lock=true*/, - extra_description_event); + extra_description_event, + 0); } /* handle reopening errors */ @@ -7434,7 +7445,8 @@ int MYSQL_BIN_LOG::open_binlog(const char *opt_name) open_binlog(opt_name, 0, max_binlog_size, false, true/*need_lock_index=true*/, true/*need_sid_lock=true*/, - NULL); + NULL, + 0); mysql_mutex_unlock(&LOCK_log); cleanup(); return 1; diff --git a/sql/binlog.h b/sql/binlog.h index 7eb1a88..2a46c9d 100644 --- a/sql/binlog.h +++ b/sql/binlog.h @@ -473,10 +473,12 @@ class MYSQL_BIN_LOG: public TC_LOG PSI_file_key log_file_key, #endif const char *log_name, - const char *new_name); + const char *new_name, + ulong number); bool init_and_set_log_file_name(const char *log_name, - const char *new_name); - int generate_new_name(char *new_name, const char *log_name); + const char *new_name, + ulong number); + int generate_new_name(char *new_name, const char *log_name, ulong new_number); public: const char *generate_name(const char *log_name, const char *suffix, @@ -777,7 +779,8 @@ class MYSQL_BIN_LOG: public TC_LOG ulong max_size, bool null_created, bool need_lock_index, bool need_sid_lock, - Format_description_log_event *extra_description_event); + Format_description_log_event *extra_description_event, + ulong new_number); bool open_index_file(const char *index_file_name_arg, const char *log_name, bool need_lock_index); /* Use this to start writing a new log file */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f657c96..016dbbf 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4262,7 +4262,8 @@ a file name for --log-bin-index option", opt_binlog_index_name); max_binlog_size, false, true/*need_lock_index=true*/, true/*need_sid_lock=true*/, - NULL)) + NULL, + 0)) { mysql_mutex_unlock(log_lock); unireg_abort(MYSQLD_ABORT_EXIT); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index bef351a..1975d39 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2086,7 +2086,8 @@ a file name for --relay-log-index option.", opt_relaylog_index_name); max_binlog_size), true, true/*need_lock_index=true*/, true/*need_sid_lock=true*/, - mi->get_mi_description_event())) + mi->get_mi_description_event(), + 0)) { mysql_mutex_unlock(log_lock); sql_print_error("Failed in open_log() called from Relay_log_info::rli_init_info()."); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index ac6c3ba..f3f6fb5 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -3137,6 +3137,7 @@ struct LEX: public Query_tables_list bool is_set_password_sql; bool contains_plaintext_password; enum_keep_diagnostics keep_diagnostics; + ulong next_binlog_file_nr; private: bool m_broken; ///< see mark_broken() diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e189075..2f7641b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -12298,6 +12298,7 @@ reset_option: SLAVE { Lex->type|= REFRESH_SLAVE; } slave_reset_options opt_channel | MASTER_SYM { Lex->type|= REFRESH_MASTER; } + master_reset_options | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;} ; @@ -12306,6 +12307,14 @@ slave_reset_options: | ALL { Lex->reset_slave_info.all= true; } ; +master_reset_options: + /* empty */ {} + | TO_SYM ulong_num + { + Lex->next_binlog_file_nr = $2; + } + ; + purge: PURGE {