summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/galera/galera_2nodes_as_master.cnf3
-rw-r--r--mysql-test/suite/galera/r/galera_as_master.result43
-rw-r--r--mysql-test/suite/galera/r/galera_sql_log_bin_zero.result8
-rw-r--r--mysql-test/suite/galera/r/sql_log_bin.result52
-rw-r--r--mysql-test/suite/galera/t/galera_as_master.test32
-rw-r--r--mysql-test/suite/galera/t/galera_sql_log_bin_zero.test9
-rw-r--r--mysql-test/suite/galera/t/sql_log_bin.test44
-rw-r--r--sql/handler.cc25
-rw-r--r--sql/log.cc30
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h14
11 files changed, 229 insertions, 33 deletions
diff --git a/mysql-test/suite/galera/galera_2nodes_as_master.cnf b/mysql-test/suite/galera/galera_2nodes_as_master.cnf
index 3543eff0544..68c0cca29a2 100644
--- a/mysql-test/suite/galera/galera_2nodes_as_master.cnf
+++ b/mysql-test/suite/galera/galera_2nodes_as_master.cnf
@@ -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
diff --git a/mysql-test/suite/galera/r/galera_as_master.result b/mysql-test/suite/galera/r/galera_as_master.result
index aba93573ecf..d87a744000c 100644
--- a/mysql-test/suite/galera/r/galera_as_master.result
+++ b/mysql-test/suite/galera/r/galera_as_master.result
@@ -1,7 +1,48 @@
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;
diff --git a/mysql-test/suite/galera/r/galera_sql_log_bin_zero.result b/mysql-test/suite/galera/r/galera_sql_log_bin_zero.result
index 89ab8d5e55b..c15a24e481f 100644
--- a/mysql-test/suite/galera/r/galera_sql_log_bin_zero.result
+++ b/mysql-test/suite/galera/r/galera_sql_log_bin_zero.result
@@ -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;
diff --git a/mysql-test/suite/galera/r/sql_log_bin.result b/mysql-test/suite/galera/r/sql_log_bin.result
new file mode 100644
index 00000000000..237725ec9a7
--- /dev/null
+++ b/mysql-test/suite/galera/r/sql_log_bin.result
@@ -0,0 +1,52 @@
+
+# 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
diff --git a/mysql-test/suite/galera/t/galera_as_master.test b/mysql-test/suite/galera/t/galera_as_master.test
index c42dbbf9683..c5d4db9f192 100644
--- a/mysql-test/suite/galera/t/galera_as_master.test
+++ b/mysql-test/suite/galera/t/galera_as_master.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;
diff --git a/mysql-test/suite/galera/t/galera_sql_log_bin_zero.test b/mysql-test/suite/galera/t/galera_sql_log_bin_zero.test
index b6965faa739..cd8d6ba6426 100644
--- a/mysql-test/suite/galera/t/galera_sql_log_bin_zero.test
+++ b/mysql-test/suite/galera/t/galera_sql_log_bin_zero.test
@@ -1,6 +1,7 @@
#
-# 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;
diff --git a/mysql-test/suite/galera/t/sql_log_bin.test b/mysql-test/suite/galera/t/sql_log_bin.test
new file mode 100644
index 00000000000..615bc4c30af
--- /dev/null
+++ b/mysql-test/suite/galera/t/sql_log_bin.test
@@ -0,0 +1,44 @@
+# 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
diff --git a/sql/handler.cc b/sql/handler.cc
index 1ddb2063faa..705b760732e 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -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())));
}
diff --git a/sql/log.cc b/sql/log.cc
index 42ba24d1acd..abc067b5075 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -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;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 781a4fd92d6..bf161b274df 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -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;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index ae9113933d7..ae1d6418ffb 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -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)