Commit da913f16 authored by Brandon Nesterenko's avatar Brandon Nesterenko

MDEV-34930: MDEV-32014 Galera and SST/no binlog fixes

 1. Binlog commit by rotate (MDEV-32014) should not be
    used with Galera, yet while WSREP binlog emulation
    is active, the code path could lead into
    binlog_cache_data::write_prepare() in an invalid
    state, leading to errors in MTR. To fix, an extra
    check is added to ensure the binlog is actually
    active before calling write_prepare().

 2. If the #binlog_cache_files directory exists on a
    mariadbd run without opt_log_bin, the directory
    was treated as a table/database, leading to errors.
    To fix, on startup, if opt_log_bin is disabled and
    #binlog_cache_files exists (in the default log
    directory), the directory is deleted (and an
    informational message is provided in the error
    log)

Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
parent d33b9d9b
...@@ -59,9 +59,14 @@ bool init_binlog_cache_dir() ...@@ -59,9 +59,14 @@ bool init_binlog_cache_dir()
uint max_tmp_file_name_len= uint max_tmp_file_name_len=
2 /* prefix */ + 10 /* max len of thread_id */ + 1 /* underline */; 2 /* prefix */ + 10 /* max len of thread_id */ + 1 /* underline */;
ignore_db_dirs_append(BINLOG_CACHE_DIR); /*
Even if the binary log is disabled (and thereby we wouldn't use the binlog
dirname_part(binlog_cache_dir, log_bin_basename, &length); cache), we need to try to build the directory name, so if it exists while
the binlog is off (e.g. due to a previous run of mariadbd, or an SST), we
can delete it.
*/
dirname_part(binlog_cache_dir,
opt_bin_log ? log_bin_basename : opt_log_basename, &length);
/* /*
Must ensure the full name of the tmp file is shorter than FN_REFLEN, to Must ensure the full name of the tmp file is shorter than FN_REFLEN, to
avoid overflowing the name buffer in write and commit. avoid overflowing the name buffer in write and commit.
...@@ -79,6 +84,27 @@ bool init_binlog_cache_dir() ...@@ -79,6 +84,27 @@ bool init_binlog_cache_dir()
MY_DIR *dir_info= my_dir(binlog_cache_dir, MYF(0)); MY_DIR *dir_info= my_dir(binlog_cache_dir, MYF(0));
/*
If the binlog cache dir exists, yet binlogging is disabled, delete the
directory and skip the initialization logic.
*/
if (!opt_bin_log)
{
if (dir_info)
{
sql_print_information(
"Found binlog cache dir '%s', yet binary logging is "
"disabled. Deleting directory.",
binlog_cache_dir);
my_dirend(dir_info);
my_rmtree(binlog_cache_dir, MYF(0));
}
memset(binlog_cache_dir, 0, sizeof(binlog_cache_dir));
return false;
}
ignore_db_dirs_append(BINLOG_CACHE_DIR);
if (!dir_info) if (!dir_info)
{ {
/* Make a dir for binlog cache temp files if not exist. */ /* Make a dir for binlog cache temp files if not exist. */
......
...@@ -691,7 +691,11 @@ void Log_event::init_show_field_list(THD *thd, List<Item>* field_list) ...@@ -691,7 +691,11 @@ void Log_event::init_show_field_list(THD *thd, List<Item>* field_list)
int Log_event_writer::write_internal(const uchar *pos, size_t len) int Log_event_writer::write_internal(const uchar *pos, size_t len)
{ {
DBUG_ASSERT(!ctx || encrypt_or_write == &Log_event_writer::encrypt_and_write); DBUG_ASSERT(!ctx || encrypt_or_write == &Log_event_writer::encrypt_and_write);
if (cache_data && cache_data->write_prepare(len)) if (cache_data &&
#ifdef WITH_WSREP
mysql_bin_log.is_open() &&
#endif
cache_data->write_prepare(len))
return 1; return 1;
if (my_b_safe_write(file, pos, len)) if (my_b_safe_write(file, pos, len))
......
...@@ -5614,10 +5614,11 @@ static int init_server_components() ...@@ -5614,10 +5614,11 @@ static int init_server_components()
mysql_mutex_unlock(log_lock); mysql_mutex_unlock(log_lock);
if (unlikely(error)) if (unlikely(error))
unireg_abort(1); unireg_abort(1);
if (unlikely(init_binlog_cache_dir()))
unireg_abort(1);
} }
if (unlikely(init_binlog_cache_dir()))
unireg_abort(1);
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
binlog_space_limit= internal_binlog_space_limit; binlog_space_limit= internal_binlog_space_limit;
slave_connections_needed_for_purge= slave_connections_needed_for_purge=
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment