Commit d5af51a7 authored by Brandon Nesterenko's avatar Brandon Nesterenko

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

 1. Binlog commit by rotate should not be used with
    Galera, so add an extra check during writing that
    the binlog is active (in case of WSREP binlog
    emulation).

 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.
parent d33b9d9b
connection node_2;
connection node_1;
connection node_2;
set statement sql_log_bin=0 for call mtr.add_suppression("Found binlog cache dir");
connection node_1;
CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 (id INT PRIMARY KEY) ENGINE=InnoDB;
connection node_2;
......
......@@ -2,6 +2,10 @@
--source include/have_innodb.inc
--source include/force_restart.inc
--connection node_2
set statement sql_log_bin=0 for call mtr.add_suppression("Found binlog cache dir");
--connection node_1
CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 (id INT PRIMARY KEY) ENGINE=InnoDB;
......
connection node_2;
connection node_1;
connection node_2;
set statement sql_log_bin=0 for call mtr.add_suppression("Found binlog cache dir");
connection node_1;
CREATE TABLE t1 (f1 INT PRIMARY KEY);
SET SESSION wsrep_trx_fragment_unit='ROWS';
SET SESSION wsrep_trx_fragment_size=1;
......
......@@ -4,6 +4,10 @@
#
--source include/galera_cluster.inc
--connection node_2
set statement sql_log_bin=0 for call mtr.add_suppression("Found binlog cache dir");
--connection node_1
CREATE TABLE t1 (f1 INT PRIMARY KEY);
#
......
......@@ -59,9 +59,14 @@ bool init_binlog_cache_dir()
uint max_tmp_file_name_len=
2 /* prefix */ + 10 /* max len of thread_id */ + 1 /* underline */;
ignore_db_dirs_append(BINLOG_CACHE_DIR);
dirname_part(binlog_cache_dir, log_bin_basename, &length);
/*
Even if the binary log is disabled (and thereby we wouldn't use the binlog
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
avoid overflowing the name buffer in write and commit.
......@@ -79,6 +84,25 @@ bool init_binlog_cache_dir()
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_warning("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));
}
return false;
}
ignore_db_dirs_append(BINLOG_CACHE_DIR);
if (!dir_info)
{
/* 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)
int Log_event_writer::write_internal(const uchar *pos, size_t len)
{
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;
if (my_b_safe_write(file, pos, len))
......
......@@ -5614,10 +5614,11 @@ static int init_server_components()
mysql_mutex_unlock(log_lock);
if (unlikely(error))
unireg_abort(1);
if (unlikely(init_binlog_cache_dir()))
unireg_abort(1);
}
if (unlikely(init_binlog_cache_dir()))
unireg_abort(1);
#ifdef HAVE_REPLICATION
binlog_space_limit= internal_binlog_space_limit;
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