Skip to content

Add RESET MASTER TO x to allow specification of binlog file nr #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions sql/binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions sql/binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion sql/rpl_rli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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().");
Expand Down
1 change: 1 addition & 0 deletions sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
;

Expand All @@ -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
{
Expand Down