summaryrefslogtreecommitdiff
path: root/sql/set_var.h
diff options
context:
space:
mode:
authorunknown <sven@riska.(none)>2008-03-07 13:59:36 +0100
committerunknown <sven@riska.(none)>2008-03-07 13:59:36 +0100
commit875ad6d8b8f89eed171325a1e8b31816f7edef12 (patch)
tree60bc25fc3ff824c603da4b1857c28dd9b43f5f41 /sql/set_var.h
parentf613588c2bc6b1d1f735eb97eb58231a9c7d2f7f (diff)
downloadmariadb-git-875ad6d8b8f89eed171325a1e8b31816f7edef12.tar.gz
BUG#31168: @@hostname does not replicate
Problem: in mixed and statement mode, a query that refers to a system variable will use the slave's value when replayed on slave. So if the value of a system variable is inserted into a table, the slave will differ from the master. Fix: mark statements that refer to a system variable as "unsafe", meaning they will be replicated by row in mixed mode and produce a warning in statement mode. There are some exceptions: some variables are actually replicated. Those should *not* be marked as unsafe. BUG#34732: mysqlbinlog does not print default values for auto_increment variables Problem: mysqlbinlog does not print default values for some variables, including auto_increment_increment and others. So if a client executing the output of mysqlbinlog has different default values, replication will be wrong. Fix: Always print default values for all variables that are replicated. I need to fix the two bugs at the same time, because the test cases would fail if I only fixed one of them. include/m_ctype.h: Added definition of ILLEGAL_CHARSET_INFO_NUMBER. We just need a symbol for a number that will never be used by any charset. ~0U should be safe since charset numbers are sequential, starting from 0. mysql-test/include/commit.inc: Upated test to avoid making statements unsafe. mysql-test/r/commit_1innodb.result: Updated test needs updated result file. mysql-test/r/mysqlbinlog.result: Updated result file. mysql-test/r/mysqlbinlog2.result: Updated result file. mysql-test/r/user_var-binlog.result: Updated result file. mysql-test/suite/binlog/r/binlog_base64_flag.result: Updated result file. mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result: Updated result file. mysql-test/suite/binlog/r/binlog_unsafe.result: Modified test file needs modified result file. mysql-test/suite/binlog/t/binlog_base64_flag.test: Need to filter out pseudo_thread_id from result since it is nondeterministic. mysql-test/suite/binlog/t/binlog_unsafe.test: Add tests that using variables is unsafe. The 'CREATE VIEW' tests didn't make sense, so I removed them. SHOW WARNINGS is not necessary either, because we get warnings for each statement in the result file. mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result: Updated result file. mysql-test/suite/rpl/r/rpl_skip_error.result: Updated result file. mysql-test/suite/rpl/t/rpl_skip_error.test: The test used @@server_id, which is not safe to replicate, so it would have given a warning. The way it used @@server_id was hackish (issue a query on master that removes rows only on master), so I replaced it by a more robust way to do the same thing (connect to slave and insert the rows only there). Also clarified what the test case does. mysql-test/t/mysqlbinlog2.test: Use --short-form instead of manually filtering out nondeterministic stuff from mysqlbinlog (because we added the nondeterministic @@pseudo_thread_id to the output). sql/item_func.cc: Added method of Item_func_get_system_var that indicates whether the given system variable will be written to the binlog or not. sql/item_func.h: Added method of Item_func_get_system_var that indicates whether the given system variable will be written to the binlog or not. sql/log_event.cc: - auto_increment_offset was not written to the binlog if auto_increment_increment=1 - mysqlbinlog did not output default values for some variables (BUG#34732). In st_print_event_info, we remember for each variable whether it has been printed or not. This is achieved in different ways for different variables: - For auto_increment_*, lc_time_names, charset_database_number, we set the default values in st_print_event_info to something illegal, so that it will look like they have changed the first time they are seen. - For charset, sql_mode, pseudo_thread_id, we add a flag to st_print_event_info which indicates whether the variable has been printed. - Since pseudo_thread_id is now printed more often, and its value is not guaranteed to be constant across different runs of the same test script, I replaced it by a constant if --short-form is used. - Moved st_print_event_info constructor from log_event.h to log_event.cc, since it now depends on ILLEGAL_CHARSET_NUMBER, which is defined in m_ctype.h, which is better to include from a .cc file than from a header file. sql/log_event.h: Added fields to st_print_event_info that indicate whether some of the variables have been written or not. Since the initialization of charset_database_number now depends on ILLEGAL_CHARSET_INFO_NUMBER, which is defined in a header file, which we'd better not include from this header file -- I moved the constructor from here to log_event.cc. sql/set_var.cc: System variables now have a flag binlog_status, which indicates if they are written to the binlog. If nothing is specified, all variables are marked as not written to the binlog (NOT_IN_BINLOG) when created. In this file, the variables that are written to the binlog are marked with SESSION_VARIABLE_IN_BINLOG. sql/set_var.h: Added flag binlog_status to class sys_var. Added a getter and a constructor parameter that sets it. Since I had to change sys_var_thd_enum constructor anyways, I simplified it to use default values of arguments instead of three copies of the constructor. sql/sql_yacc.yy: Mark statements that refer to a system variable as "unsafe", meaning they will be replicated by row in mixed mode. Added comment to explain strange piece of code just above. mysql-test/include/diff_tables.inc: New auxiliary test file that tests whether two tables (possibly one on master and one on slave) differ. mysql-test/suite/rpl/r/rpl_variables.result: New test case needs new result file. mysql-test/suite/rpl/r/rpl_variables_stm.result: New test file needs new result file. mysql-test/suite/rpl/t/rpl_variables.test: Test that INSERT of @@variables is replicated correctly (by switching to row-based mode). mysql-test/suite/rpl/t/rpl_variables_stm.test: Test that replication of @@variables which are replicated explicitly works as expected in statement mode (without giving warnings).
Diffstat (limited to 'sql/set_var.h')
-rw-r--r--sql/set_var.h152
1 files changed, 91 insertions, 61 deletions
diff --git a/sql/set_var.h b/sql/set_var.h
index 171158fcf1e..46fe7755baf 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -48,6 +48,22 @@ struct sys_var_chain
class sys_var
{
public:
+
+ /**
+ Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
+ */
+ enum Binlog_status_enum
+ {
+ /* The variable value is not in the binlog. */
+ NOT_IN_BINLOG,
+ /* The value of the @@session variable is in the binlog. */
+ SESSION_VARIABLE_IN_BINLOG
+ /*
+ Currently, no @@global variable is ever in the binlog, so we
+ don't need an enumeration value for that.
+ */
+ };
+
sys_var *next;
struct my_option *option_limits; /* Updated by by set_var_init() */
uint name_length; /* Updated by by set_var_init() */
@@ -55,8 +71,9 @@ public:
sys_after_update_func after_update;
bool no_support_one_shot;
- sys_var(const char *name_arg,sys_after_update_func func= NULL)
- :name(name_arg), after_update(func)
+ sys_var(const char *name_arg, sys_after_update_func func= NULL,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :name(name_arg), after_update(func), binlog_status(binlog_status_arg)
, no_support_one_shot(1)
{}
virtual ~sys_var() {}
@@ -71,6 +88,11 @@ public:
virtual bool check(THD *thd, set_var *var);
bool check_enum(THD *thd, set_var *var, const TYPELIB *enum_names);
bool check_set(THD *thd, set_var *var, TYPELIB *enum_names);
+ bool is_written_to_binlog(enum_var_type type)
+ {
+ return (type == OPT_SESSION || type == OPT_DEFAULT) &&
+ (binlog_status == SESSION_VARIABLE_IN_BINLOG);
+ }
virtual bool update(THD *thd, set_var *var)=0;
virtual void set_default(THD *thd_arg, enum_var_type type) {}
virtual SHOW_TYPE show_type() { return SHOW_UNDEF; }
@@ -86,6 +108,9 @@ public:
virtual bool is_struct() { return 0; }
virtual bool is_readonly() const { return 0; }
virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
+
+private:
+ const Binlog_status_enum binlog_status;
};
@@ -232,8 +257,9 @@ class sys_var_const_str :public sys_var
{
public:
char *value; // Pointer to const value
- sys_var_const_str(sys_var_chain *chain, const char *name_arg, const char *value_arg)
- :sys_var(name_arg),value((char*) value_arg)
+ sys_var_const_str(sys_var_chain *chain, const char *name_arg,
+ const char *value_arg)
+ :sys_var(name_arg), value((char*) value_arg)
{ chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
@@ -328,8 +354,9 @@ class sys_var_thd :public sys_var
{
public:
sys_var_thd(const char *name_arg,
- sys_after_update_func func= NULL)
- :sys_var(name_arg,func)
+ sys_after_update_func func= NULL,
+ Binlog_status_enum binlog_status= NOT_IN_BINLOG)
+ :sys_var(name_arg, func, binlog_status)
{}
bool check_type(enum_var_type type) { return 0; }
bool check_default(enum_var_type type)
@@ -344,12 +371,13 @@ class sys_var_thd_ulong :public sys_var_thd
sys_check_func check_func;
public:
ulong SV::*offset;
- sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg)
- :sys_var_thd(name_arg), check_func(0), offset(offset_arg)
- { chain_sys_var(chain); }
- sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
- sys_check_func c_func, sys_after_update_func au_func)
- :sys_var_thd(name_arg,au_func), check_func(c_func), offset(offset_arg)
+ sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg,
+ ulong SV::*offset_arg,
+ sys_check_func c_func= NULL,
+ sys_after_update_func au_func= NULL,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_thd(name_arg, au_func, binlog_status_arg), check_func(c_func),
+ offset(offset_arg)
{ chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
@@ -440,22 +468,12 @@ protected:
TYPELIB *enum_names;
sys_check_func check_func;
public:
- sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
- TYPELIB *typelib)
- :sys_var_thd(name_arg), offset(offset_arg), enum_names(typelib),
- check_func(0)
- { chain_sys_var(chain); }
- sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
- TYPELIB *typelib,
- sys_after_update_func func)
- :sys_var_thd(name_arg,func), offset(offset_arg), enum_names(typelib),
- check_func(0)
- { chain_sys_var(chain); }
- sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
- TYPELIB *typelib, sys_after_update_func func,
- sys_check_func check)
- :sys_var_thd(name_arg,func), offset(offset_arg), enum_names(typelib),
- check_func(check)
+ sys_var_thd_enum(sys_var_chain *chain, const char *name_arg,
+ ulong SV::*offset_arg, TYPELIB *typelib,
+ sys_after_update_func func= NULL,
+ sys_check_func check= NULL)
+ :sys_var_thd(name_arg, func), offset(offset_arg),
+ enum_names(typelib), check_func(check)
{ chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
@@ -480,7 +498,7 @@ public:
sys_var_thd_sql_mode(sys_var_chain *chain, const char *name_arg,
ulong SV::*offset_arg)
:sys_var_thd_enum(chain, name_arg, offset_arg, &sql_mode_typelib,
- fix_sql_mode_var)
+ fix_sql_mode_var)
{}
bool check(THD *thd, set_var *var)
{
@@ -534,9 +552,10 @@ public:
bool reverse;
sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
sys_check_func c_func, sys_update_func u_func,
- ulonglong bit, bool reverse_arg=0)
- :sys_var_thd(name_arg), check_func(c_func), update_func(u_func),
- bit_flag(bit), reverse(reverse_arg)
+ ulonglong bit, bool reverse_arg=0,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_thd(name_arg, NULL, binlog_status_arg), check_func(c_func),
+ update_func(u_func), bit_flag(bit), reverse(reverse_arg)
{ chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
@@ -567,8 +586,9 @@ public:
class sys_var_timestamp :public sys_var
{
public:
- sys_var_timestamp(sys_var_chain *chain, const char *name_arg)
- :sys_var(name_arg)
+ sys_var_timestamp(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var(name_arg, NULL, binlog_status_arg)
{ chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
@@ -582,8 +602,9 @@ public:
class sys_var_last_insert_id :public sys_var
{
public:
- sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg)
- :sys_var(name_arg)
+ sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var(name_arg, NULL, binlog_status_arg)
{ chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
@@ -608,8 +629,9 @@ public:
class sys_var_rand_seed1 :public sys_var
{
public:
- sys_var_rand_seed1(sys_var_chain *chain, const char *name_arg)
- :sys_var(name_arg)
+ sys_var_rand_seed1(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var(name_arg, NULL, binlog_status_arg)
{ chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
@@ -618,8 +640,9 @@ public:
class sys_var_rand_seed2 :public sys_var
{
public:
- sys_var_rand_seed2(sys_var_chain *chain, const char *name_arg)
- :sys_var(name_arg)
+ sys_var_rand_seed2(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var(name_arg, NULL, binlog_status_arg)
{ chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
@@ -629,11 +652,12 @@ public:
class sys_var_collation :public sys_var_thd
{
public:
- sys_var_collation(const char *name_arg)
- :sys_var_thd(name_arg)
- {
+ sys_var_collation(const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_thd(name_arg, NULL, binlog_status_arg)
+ {
no_support_one_shot= 0;
- }
+ }
bool check(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_CHAR; }
bool check_update_type(Item_result type)
@@ -648,8 +672,9 @@ class sys_var_character_set :public sys_var_thd
{
public:
bool nullable;
- sys_var_character_set(const char *name_arg, bool is_nullable= 0) :
- sys_var_thd(name_arg), nullable(is_nullable)
+ sys_var_character_set(const char *name_arg, bool is_nullable= 0,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_thd(name_arg, NULL, binlog_status_arg), nullable(is_nullable)
{
/*
In fact only almost all variables derived from sys_var_character_set
@@ -678,8 +703,9 @@ public:
sys_var_character_set_sv(sys_var_chain *chain, const char *name_arg,
CHARSET_INFO *SV::*offset_arg,
CHARSET_INFO **global_default_arg,
- bool is_nullable= 0)
- : sys_var_character_set(name_arg, is_nullable),
+ bool is_nullable= 0,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ : sys_var_character_set(name_arg, is_nullable, binlog_status_arg),
offset(offset_arg), global_default(global_default_arg)
{ chain_sys_var(chain); }
void set_default(THD *thd, enum_var_type type);
@@ -693,9 +719,9 @@ public:
sys_var_character_set_client(sys_var_chain *chain, const char *name_arg,
CHARSET_INFO *SV::*offset_arg,
CHARSET_INFO **global_default_arg,
- bool is_nullable= 0)
+ Binlog_status_enum binlog_status_arg)
: sys_var_character_set_sv(chain, name_arg, offset_arg, global_default_arg,
- is_nullable)
+ 0, binlog_status_arg)
{ }
bool check(THD *thd, set_var *var);
};
@@ -704,8 +730,10 @@ public:
class sys_var_character_set_database :public sys_var_character_set
{
public:
- sys_var_character_set_database(sys_var_chain *chain, const char *name_arg) :
- sys_var_character_set(name_arg)
+ sys_var_character_set_database(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg=
+ NOT_IN_BINLOG)
+ : sys_var_character_set(name_arg, 0, binlog_status_arg)
{ chain_sys_var(chain); }
void set_default(THD *thd, enum_var_type type);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
@@ -718,8 +746,9 @@ class sys_var_collation_sv :public sys_var_collation
public:
sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
CHARSET_INFO *SV::*offset_arg,
- CHARSET_INFO **global_default_arg)
- :sys_var_collation(name_arg),
+ CHARSET_INFO **global_default_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_collation(name_arg, binlog_status_arg),
offset(offset_arg), global_default(global_default_arg)
{
chain_sys_var(chain);
@@ -946,8 +975,9 @@ public:
class sys_var_thd_time_zone :public sys_var_thd
{
public:
- sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg):
- sys_var_thd(name_arg)
+ sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ :sys_var_thd(name_arg, NULL, binlog_status_arg)
{
no_support_one_shot= 0;
chain_sys_var(chain);
@@ -1034,8 +1064,9 @@ public:
class sys_var_thd_lc_time_names :public sys_var_thd
{
public:
- sys_var_thd_lc_time_names(sys_var_chain *chain, const char *name_arg):
- sys_var_thd(name_arg)
+ sys_var_thd_lc_time_names(sys_var_chain *chain, const char *name_arg,
+ Binlog_status_enum binlog_status_arg= NOT_IN_BINLOG)
+ : sys_var_thd(name_arg, NULL, binlog_status_arg)
{
#if MYSQL_VERSION_ID < 50000
no_support_one_shot= 0;
@@ -1079,9 +1110,8 @@ public:
sys_var_thd_binlog_format(sys_var_chain *chain, const char *name_arg,
ulong SV::*offset_arg)
:sys_var_thd_enum(chain, name_arg, offset_arg,
- &binlog_format_typelib
- , fix_binlog_format_after_update
- )
+ &binlog_format_typelib,
+ fix_binlog_format_after_update)
{};
bool is_readonly() const;
};