summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorNirbhay Choubey <nirbhay@mariadb.com>2015-08-08 15:04:15 -0400
committerNirbhay Choubey <nirbhay@mariadb.com>2015-08-08 15:04:15 -0400
commitcd1a11ace3b4a4b034307590d58cc7a9d37004f6 (patch)
tree2c666d6c7af4a742e2b8f4ff429ab53a9da8ef3a /sql
parent46ad86f6a35aff59ecb68a23dba228e5796e935a (diff)
downloadmariadb-git-cd1a11ace3b4a4b034307590d58cc7a9d37004f6.tar.gz
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.
Diffstat (limited to 'sql')
-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
4 files changed, 53 insertions, 18 deletions
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)