Commit cd1a11ac authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-7205 : Galera cluster & sql_log_bin = off don't work

While sql_bin_log=1(0) is meant to control binary logging for the
current session so that the updates to do(not) get logged into the
binary log to be replicated to the async MariaDB slave. The same
should not affect galera replication.

That is, the updates should always get replicated to other galera
nodes regardless of sql_bin_log's value.

Fixed by making sure that the updates are written to binlog cache
irrespective of sql_bin_log.

Added test cases.
parent 46ad86f6
......@@ -7,6 +7,7 @@
!include include/default_mysqld.cnf
[mysqld]
log-bin=mysqld-bin
binlog-format=row
innodb-autoinc-lock-mode=2
default-storage-engine=innodb
......@@ -17,7 +18,6 @@ default-storage-engine=innodb
#sst_port=@OPT.port
server-id=1
log-bin=mysqld-bin
log_slave_updates
wsrep-on=1
......@@ -37,7 +37,6 @@ wsrep-sync-wait=7
#sst_port=@OPT.port
server-id=2
log-bin=mysqld-bin
log_slave_updates
wsrep-on=1
......
START SLAVE;
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1);
# Disable binary logging for current session
SET SQL_LOG_BIN=OFF;
CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t2 VALUES(1);
INSERT INTO t1 VALUES(2);
DROP TABLE t1;
CREATE TABLE test.t3 AS SELECT * from t1;
SET SQL_LOG_BIN=ON;
INSERT INTO t1 VALUES(3);
CREATE TABLE test.t4 AS SELECT * from t1;
SELECT * FROM t1;
f1
1
2
3
SELECT * FROM t2;
f1
1
SELECT * FROM t3;
f1
1
2
SELECT * FROM t4;
f1
1
2
3
SHOW TABLES;
Tables_in_test
t1
t4
SELECT * FROM t1;
f1
1
3
SELECT * FROM t4;
f1
1
2
3
# Cleanup
DROP TABLE t1, t4;
SET SQL_LOG_BIN=OFF;
DROP TABLE t2, t3;
STOP SLAVE;
RESET SLAVE ALL;
......@@ -3,10 +3,10 @@ SET SESSION sql_log_bin = 0;
INSERT INTO t1 VALUES (1);
SET SESSION sql_log_bin = 1;
INSERT INTO t1 VALUES (2);
SELECT COUNT(*) = 1 FROM t1;
COUNT(*) = 1
SELECT COUNT(*) = 2 FROM t1;
COUNT(*) = 2
1
SELECT COUNT(*) = 0 FROM t1 WHERE f1 = 1;
COUNT(*) = 0
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 1;
COUNT(*) = 1
1
DROP TABLE t1;
# On node_1
USE test;
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t1 VALUES (1);
# Disable binary logging for current session
SET SQL_LOG_BIN=OFF;
INSERT INTO t1 VALUES (2);
CREATE TABLE t2(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t2 VALUES (1);
CREATE TABLE test.t3 AS SELECT * from t1;
# Enable binary logging for current session
SET SQL_LOG_BIN=ON;
INSERT INTO t2 VALUES (2);
CREATE TABLE t4 AS SELECT * from t2;
SELECT * FROM t1;
c1
1
2
SELECT * FROM t2;
c1
1
2
SELECT * FROM t3;
c1
1
2
SELECT * FROM t4;
c1
1
2
# On node_2
USE test;
SELECT * FROM t1;
c1
1
2
SELECT * FROM t2;
c1
1
2
SELECT * FROM t3;
c1
1
2
SELECT * FROM t4;
c1
1
2
DROP TABLE t1, t2, t3, t4;
# End of test
......@@ -17,22 +17,46 @@ START SLAVE;
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1);
--connection node_2
--echo # Disable binary logging for current session
SET SQL_LOG_BIN=OFF;
CREATE TABLE t2 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t2 VALUES(1);
INSERT INTO t1 VALUES(2);
CREATE TABLE test.t3 AS SELECT * from t1;
SET SQL_LOG_BIN=ON;
INSERT INTO t1 VALUES(3);
CREATE TABLE test.t4 AS SELECT * from t1;
--connection node_2
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
SELECT * FROM t4;
--connection node_3
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc
SHOW TABLES;
--let $wait_condition = SELECT COUNT(*) = 2 FROM t1;
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 3 FROM t4;
--source include/wait_condition.inc
SELECT * FROM t1;
SELECT * FROM t4;
--echo # Cleanup
--connection node_1
DROP TABLE t1;
DROP TABLE t1, t4;
SET SQL_LOG_BIN=OFF;
DROP TABLE t2, t3;
--connection node_3
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't4';
--source include/wait_condition.inc
STOP SLAVE;
RESET SLAVE ALL;
#
# Test SET SESSION sql_log_bin = 0 . We expect that unlogged updates will not be replicated
# to the slave and that there will be no assertions in the process.
# Test SET SESSION sql_log_bin = 0 . We expect that updates gets repliated to
# other nodes while they do not show up in the binary log files.
# (see galera.galera_as_master)
#
--source include/galera_cluster.inc
......@@ -18,8 +19,8 @@ INSERT INTO t1 VALUES (2);
--connection node_2
SELECT COUNT(*) = 1 FROM t1;
SELECT COUNT(*) = 0 FROM t1 WHERE f1 = 1;
SELECT COUNT(*) = 2 FROM t1;
SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 1;
--connection node_1
DROP TABLE t1;
# Test to check the behavior of galera cluster with sql_log_bin=ON|OFF & binary
# logging is disabled. sql_bin_log should not affect galera replication.
--source include/galera_cluster.inc
--source include/have_innodb.inc
--echo
--echo # On node_1
--connection node_1
USE test;
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t1 VALUES (1);
--echo # Disable binary logging for current session
SET SQL_LOG_BIN=OFF;
INSERT INTO t1 VALUES (2);
CREATE TABLE t2(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t2 VALUES (1);
CREATE TABLE test.t3 AS SELECT * from t1;
--echo # Enable binary logging for current session
SET SQL_LOG_BIN=ON;
INSERT INTO t2 VALUES (2);
CREATE TABLE t4 AS SELECT * from t2;
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
SELECT * FROM t4;
--echo
--echo # On node_2
--connection node_2
USE test;
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
SELECT * FROM t4;
# Cleanup
DROP TABLE t1, t2, t3, t4;
--source include/galera_end.inc
--echo # End of test
......@@ -5588,13 +5588,26 @@ static bool check_table_binlog_row_based(THD *thd, TABLE *table)
DBUG_ASSERT(table->s->cached_row_logging_check == 0 ||
table->s->cached_row_logging_check == 1);
return thd->is_current_stmt_binlog_format_row() &&
return (thd->is_current_stmt_binlog_format_row() &&
table->s->cached_row_logging_check &&
(thd->variables.option_bits & OPTION_BIN_LOG) &&
/* applier and replayer should not binlog */
((IF_WSREP(WSREP_EMULATE_BINLOG(thd) &&
thd->wsrep_exec_mode != REPL_RECV, 0)) ||
mysql_bin_log.is_open());
/*
Wsrep partially enables binary logging if it have not been
explicitly turned on. As a result we return 'true' if we are in
wsrep binlog emulation mode and the current thread is not a wsrep
applier or replayer thread. This decision is not affected by
@@sql_log_bin as we want the events to make into the binlog
cache only to filter them later before they make into binary log
file.
However, we do return 'false' if binary logging was temporarily
turned off (see tmp_disable_binlog(A)).
Otherwise, return 'true' if binary logging is on.
*/
(thd->variables.sql_log_bin_off != 1) &&
((WSREP_EMULATE_BINLOG(thd) && (thd->wsrep_exec_mode != REPL_RECV)) ||
((WSREP(thd) || (thd->variables.option_bits & OPTION_BIN_LOG)) &&
mysql_bin_log.is_open())));
}
......
......@@ -5953,19 +5953,19 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
binlog_cache_data *cache_data= 0;
bool is_trans_cache= FALSE;
bool using_trans= event_info->use_trans_cache();
bool direct;
bool direct= event_info->use_direct_logging();
ulong UNINIT_VAR(prev_binlog_id);
DBUG_ENTER("MYSQL_BIN_LOG::write(Log_event *)");
/*
When binary logging is not enabled (--log-bin=0), wsrep-patch partially
enables it without opening the binlog file (MSQL_BIN_LOG::open().
So, avoid writing directly to binlog file.
So, avoid writing to binlog file.
*/
if (wsrep_emulate_bin_log)
direct= false;
else
direct= event_info->use_direct_logging();
if (direct &&
(wsrep_emulate_bin_log ||
(WSREP(thd) && !(thd->variables.option_bits & OPTION_BIN_LOG))))
DBUG_RETURN(0);
if (thd->variables.option_bits & OPTION_GTID_BEGIN)
{
......@@ -6013,7 +6013,17 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info, my_bool *with_annotate)
binlog_[wild_]{do|ignore}_table?" (WL#1049)"
*/
const char *local_db= event_info->get_db();
if ((!(thd->variables.option_bits & OPTION_BIN_LOG)) ||
bool option_bin_log_flag= (thd->variables.option_bits & OPTION_BIN_LOG);
/*
Log all updates to binlog cache so that they can get replicated to other
nodes. A check has been added to stop them from getting logged into
binary log files.
*/
if (WSREP(thd)) option_bin_log_flag= true;
if ((!(option_bin_log_flag)) ||
(thd->lex->sql_command != SQLCOM_ROLLBACK_TO_SAVEPOINT &&
thd->lex->sql_command != SQLCOM_SAVEPOINT &&
!binlog_filter->db_ok(local_db)))
......@@ -6956,9 +6966,11 @@ MYSQL_BIN_LOG::write_transaction_to_binlog(THD *thd,
/*
Control should not be allowed beyond this point in wsrep_emulate_bin_log
mode.
mode. Also, do not write the cached updates to binlog if binary logging is
disabled (log-bin/sql_log_bin).
*/
if (wsrep_emulate_bin_log) DBUG_RETURN(0);
if (wsrep_emulate_bin_log || !(thd->variables.option_bits & OPTION_BIN_LOG))
DBUG_RETURN(0);
entry.thd= thd;
entry.cache_mngr= cache_mngr;
......
......@@ -1440,6 +1440,8 @@ void THD::init(void)
else
variables.option_bits&= ~OPTION_BIN_LOG;
variables.sql_log_bin_off= 0;
select_commands= update_commands= other_commands= 0;
/* Set to handle counting of aborted connections */
userstat_running= opt_userstat_running;
......
......@@ -633,6 +633,11 @@ typedef struct system_variables
my_bool query_cache_strip_comments;
my_bool sql_log_slow;
my_bool sql_log_bin;
/*
A flag to help detect whether binary logging was temporarily disabled
(see tmp_disable_binlog(A) macro).
*/
my_bool sql_log_bin_off;
my_bool binlog_annotate_row_events;
my_bool binlog_direct_non_trans_update;
......@@ -4036,11 +4041,14 @@ my_eof(THD *thd)
thd->get_stmt_da()->set_eof_status(thd);
}
#define tmp_disable_binlog(A) \
#define tmp_disable_binlog(A) \
{ulonglong tmp_disable_binlog__save_options= (A)->variables.option_bits; \
(A)->variables.option_bits&= ~OPTION_BIN_LOG
(A)->variables.option_bits&= ~OPTION_BIN_LOG; \
(A)->variables.sql_log_bin_off= 1;
#define reenable_binlog(A) (A)->variables.option_bits= tmp_disable_binlog__save_options;}
#define reenable_binlog(A) \
(A)->variables.option_bits= tmp_disable_binlog__save_options; \
(A)->variables.sql_log_bin_off= 0;}
inline sql_mode_t sql_mode_for_dates(THD *thd)
......
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